Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 24832b1

Browse filesBrowse files
authored
Merge pull request hub4j#1610 from michael-s-grant/feature/issue-1597-add-listCodeownersErrors
Issue 1597: Tested and implemented GHRepository.listCodeownersErrors()
2 parents 44b184a + 7e1e5b4 commit 24832b1
Copy full SHA for 24832b1

File tree

Expand file treeCollapse file tree

9 files changed

+689
-0
lines changed
Filter options
Expand file treeCollapse file tree

9 files changed

+689
-0
lines changed
+77Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package org.kohsuke.github;
2+
3+
/**
4+
* Represents an error in a {@code CODEOWNERS} file. See <a href=
5+
* "https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners">the
6+
* relevant documentation</a>.
7+
*
8+
* @author Michael Grant
9+
*/
10+
public class GHCodeownersError {
11+
private int line, column;
12+
13+
private String kind, source, suggestion, message, path;
14+
15+
/**
16+
* Gets line.
17+
*
18+
* @return the line
19+
*/
20+
public int getLine() {
21+
return line;
22+
}
23+
24+
/**
25+
* Gets column.
26+
*
27+
* @return the column
28+
*/
29+
public int getColumn() {
30+
return column;
31+
}
32+
33+
/**
34+
* Gets kind.
35+
*
36+
* @return the kind
37+
*/
38+
public String getKind() {
39+
return kind;
40+
}
41+
42+
/**
43+
* Gets source.
44+
*
45+
* @return the source
46+
*/
47+
public String getSource() {
48+
return source;
49+
}
50+
51+
/**
52+
* Gets suggestion.
53+
*
54+
* @return the suggestion
55+
*/
56+
public String getSuggestion() {
57+
return suggestion;
58+
}
59+
60+
/**
61+
* Gets message.
62+
*
63+
* @return the message
64+
*/
65+
public String getMessage() {
66+
return message;
67+
}
68+
69+
/**
70+
* Gets path.
71+
*
72+
* @return the path
73+
*/
74+
public String getPath() {
75+
return path;
76+
}
77+
}

‎src/main/java/org/kohsuke/github/GHRepository.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHRepository.java
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2956,6 +2956,25 @@ public GHSubscription getSubscription() throws IOException {
29562956
}
29572957
}
29582958

2959+
// Only used within listCodeownersErrors().
2960+
private static class GHCodeownersErrors {
2961+
public List<GHCodeownersError> errors;
2962+
}
2963+
2964+
/**
2965+
* List errors in the {@code CODEOWNERS} file. Note that GitHub skips lines with incorrect syntax; these are
2966+
* reported in the web interface, but not in the API call which this library uses.
2967+
*
2968+
* @return the list of errors
2969+
* @throws IOException
2970+
* the io exception
2971+
*/
2972+
public List<GHCodeownersError> listCodeownersErrors() throws IOException {
2973+
return root().createRequest()
2974+
.withUrlPath(getApiTailUrl("codeowners/errors"))
2975+
.fetch(GHCodeownersErrors.class).errors;
2976+
}
2977+
29592978
/**
29602979
* List contributors paged iterable.
29612980
*
+55Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.kohsuke.github;
2+
3+
import org.junit.Test;
4+
5+
import java.io.IOException;
6+
import java.util.List;
7+
8+
import static org.hamcrest.Matchers.*;
9+
10+
/**
11+
* Test class for listing errors in CODEOWNERS files.
12+
*
13+
* @author Michael Grant
14+
*/
15+
public class GHCodeownersErrorTest extends AbstractGitHubWireMockTest {
16+
17+
/**
18+
* Gets the {@code CODEOWNERS} errors.
19+
*
20+
* @throws IOException
21+
* the exception
22+
*/
23+
@Test
24+
public void testGetCodeownersErrors() throws IOException {
25+
final GHRepository repo = getRepository(gitHub);
26+
final List<GHCodeownersError> codeownersErrors = repo.listCodeownersErrors();
27+
assertThat(codeownersErrors.size(), is(1));
28+
final GHCodeownersError firstError = codeownersErrors.get(0);
29+
assertThat(firstError.getLine(), is(1));
30+
assertThat(firstError.getColumn(), is(3));
31+
assertThat(firstError.getKind(), is("Unknown owner"));
32+
assertThat(firstError.getSource(),
33+
is("* @nonexistent-user # Deliberate error to test response to repo.listCodeownersErrors()\n"));
34+
assertThat(firstError.getSuggestion(),
35+
is("make sure @nonexistent-user exists and has write access to the repository"));
36+
assertThat(firstError.getMessage(),
37+
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 ^"));
38+
assertThat(firstError.getPath(), is(".github/CODEOWNERS"));
39+
}
40+
41+
/**
42+
* Gets the repository.
43+
*
44+
* @return the repository
45+
* @throws IOException
46+
* Signals that an I/O exception has occurred.
47+
*/
48+
protected GHRepository getRepository() throws IOException {
49+
return getRepository(gitHub);
50+
}
51+
52+
private GHRepository getRepository(GitHub gitHub) throws IOException {
53+
return gitHub.getOrganization(GITHUB_API_TEST_ORG).getRepository("github-api");
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"login": "hub4j-test-org",
3+
"id": 7544739,
4+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
5+
"url": "https://api.github.com/orgs/hub4j-test-org",
6+
"repos_url": "https://api.github.com/orgs/hub4j-test-org/repos",
7+
"events_url": "https://api.github.com/orgs/hub4j-test-org/events",
8+
"hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks",
9+
"issues_url": "https://api.github.com/orgs/hub4j-test-org/issues",
10+
"members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}",
11+
"public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}",
12+
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
13+
"description": "Hub4j Test Org Description (this could be null or blank too)",
14+
"name": "Hub4j Test Org Name (this could be null or blank too)",
15+
"company": null,
16+
"blog": "https://hub4j.url.io/could/be/null",
17+
"location": "Hub4j Test Org Location (this could be null or blank too)",
18+
"email": "hub4jtestorgemail@could.be.null.com",
19+
"twitter_username": null,
20+
"is_verified": false,
21+
"has_organization_projects": true,
22+
"has_repository_projects": true,
23+
"public_repos": 54,
24+
"public_gists": 0,
25+
"followers": 1,
26+
"following": 0,
27+
"html_url": "https://github.com/hub4j-test-org",
28+
"created_at": "2014-05-10T19:39:11Z",
29+
"updated_at": "2020-06-04T05:56:10Z",
30+
"type": "Organization"
31+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.