-
Notifications
You must be signed in to change notification settings - Fork 735
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1610 from michael-s-grant/feature/issue-1597-add-…
…listCodeownersErrors Issue 1597: Tested and implemented GHRepository.listCodeownersErrors()
- Loading branch information
Showing
9 changed files
with
689 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package org.kohsuke.github; | ||
|
||
/** | ||
* Represents an error in a {@code CODEOWNERS} file. See <a href= | ||
* "https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners">the | ||
* relevant documentation</a>. | ||
* | ||
* @author Michael Grant | ||
*/ | ||
public class GHCodeownersError { | ||
private int line, column; | ||
|
||
private String kind, source, suggestion, message, path; | ||
|
||
/** | ||
* Gets line. | ||
* | ||
* @return the line | ||
*/ | ||
public int getLine() { | ||
return line; | ||
} | ||
|
||
/** | ||
* Gets column. | ||
* | ||
* @return the column | ||
*/ | ||
public int getColumn() { | ||
return column; | ||
} | ||
|
||
/** | ||
* Gets kind. | ||
* | ||
* @return the kind | ||
*/ | ||
public String getKind() { | ||
return kind; | ||
} | ||
|
||
/** | ||
* Gets source. | ||
* | ||
* @return the source | ||
*/ | ||
public String getSource() { | ||
return source; | ||
} | ||
|
||
/** | ||
* Gets suggestion. | ||
* | ||
* @return the suggestion | ||
*/ | ||
public String getSuggestion() { | ||
return suggestion; | ||
} | ||
|
||
/** | ||
* Gets message. | ||
* | ||
* @return the message | ||
*/ | ||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
/** | ||
* Gets path. | ||
* | ||
* @return the path | ||
*/ | ||
public String getPath() { | ||
return path; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/test/java/org/kohsuke/github/GHCodeownersErrorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.kohsuke.github; | ||
|
||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.Matchers.*; | ||
|
||
/** | ||
* Test class for listing errors in CODEOWNERS files. | ||
* | ||
* @author Michael Grant | ||
*/ | ||
public class GHCodeownersErrorTest extends AbstractGitHubWireMockTest { | ||
|
||
/** | ||
* Gets the {@code CODEOWNERS} errors. | ||
* | ||
* @throws IOException | ||
* the exception | ||
*/ | ||
@Test | ||
public void testGetCodeownersErrors() throws IOException { | ||
final GHRepository repo = getRepository(gitHub); | ||
final List<GHCodeownersError> codeownersErrors = repo.listCodeownersErrors(); | ||
assertThat(codeownersErrors.size(), is(1)); | ||
final GHCodeownersError firstError = codeownersErrors.get(0); | ||
assertThat(firstError.getLine(), is(1)); | ||
assertThat(firstError.getColumn(), is(3)); | ||
assertThat(firstError.getKind(), is("Unknown owner")); | ||
assertThat(firstError.getSource(), | ||
is("* @nonexistent-user # Deliberate error to test response to repo.listCodeownersErrors()\n")); | ||
assertThat(firstError.getSuggestion(), | ||
is("make sure @nonexistent-user exists and has write access to the repository")); | ||
assertThat(firstError.getMessage(), | ||
is("Unknown owner on line 1: make sure @nonexistent-user exists and has write access to the repository\n\n * @nonexistent-user # Deliberate error to test response to repo.listCodeownersErrors()\n ^")); | ||
assertThat(firstError.getPath(), is(".github/CODEOWNERS")); | ||
} | ||
|
||
/** | ||
* Gets the repository. | ||
* | ||
* @return the repository | ||
* @throws IOException | ||
* Signals that an I/O exception has occurred. | ||
*/ | ||
protected GHRepository getRepository() throws IOException { | ||
return getRepository(gitHub); | ||
} | ||
|
||
private GHRepository getRepository(GitHub gitHub) throws IOException { | ||
return gitHub.getOrganization(GITHUB_API_TEST_ORG).getRepository("github-api"); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...GHCodeownersErrorTest/wiremock/testGetCodeownersErrors/__files/orgs_hub4j-test-org-1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"login": "hub4j-test-org", | ||
"id": 7544739, | ||
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", | ||
"url": "https://api.github.com/orgs/hub4j-test-org", | ||
"repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", | ||
"events_url": "https://api.github.com/orgs/hub4j-test-org/events", | ||
"hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", | ||
"issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", | ||
"members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", | ||
"public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", | ||
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4", | ||
"description": "Hub4j Test Org Description (this could be null or blank too)", | ||
"name": "Hub4j Test Org Name (this could be null or blank too)", | ||
"company": null, | ||
"blog": "https://hub4j.url.io/could/be/null", | ||
"location": "Hub4j Test Org Location (this could be null or blank too)", | ||
"email": "[email protected]", | ||
"twitter_username": null, | ||
"is_verified": false, | ||
"has_organization_projects": true, | ||
"has_repository_projects": true, | ||
"public_repos": 54, | ||
"public_gists": 0, | ||
"followers": 1, | ||
"following": 0, | ||
"html_url": "https://github.com/hub4j-test-org", | ||
"created_at": "2014-05-10T19:39:11Z", | ||
"updated_at": "2020-06-04T05:56:10Z", | ||
"type": "Organization" | ||
} |
Oops, something went wrong.