Skip to content

Commit 3c4d80c

Browse files
ihrigbbitwiseman
andauthored
Add functionality to get active rules for a branch (#1897)
* Add functionality to get active rules for a branch * Add javadoc to enums * Add javadoc to constants * Fix javadoc warnings * Add tests to cover model classes * Add class javadoc * Cover missing parts * Update src/main/java/org/kohsuke/github/GHRepositoryRule.java Co-authored-by: Liam Newman <bitwiseman@gmail.com> * Apply suggestions * Add unknown to enums * Apply requested changes * Fix javadoc * Fix javadoc * Configure type for objectreader * Ignore spotbugs warnings * Cover enums --------- Co-authored-by: Liam Newman <bitwiseman@gmail.com>
1 parent cab9bbb commit 3c4d80c

File tree

10 files changed

+1136
-6
lines changed

10 files changed

+1136
-6
lines changed

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ public PagedIterable<GHUser> listCollaborators(CollaboratorAffiliation affiliati
10071007

10081008
/**
10091009
* Lists all
1010-
* <a href="https://help.github.com/articles/assigning-issues-and-pull-requests-to-other-github-users/">the
1010+
* <a href= "https://help.github.com/articles/assigning-issues-and-pull-requests-to-other-github-users/">the
10111011
* available assignees</a> to which issues may be assigned.
10121012
*
10131013
* @return the paged iterable
@@ -2222,7 +2222,7 @@ public GHCommitStatus getLastCommitStatus(String sha1) throws IOException {
22222222
* @return check runs for given ref
22232223
* @throws IOException
22242224
* the io exception
2225-
* @see <a href="https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-specific-ref">List check runs
2225+
* @see <a href= "https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-specific-ref">List check runs
22262226
* for a specific ref</a>
22272227
*/
22282228
public PagedIterable<GHCheckRun> getCheckRuns(String ref) throws IOException {
@@ -2242,7 +2242,7 @@ public PagedIterable<GHCheckRun> getCheckRuns(String ref) throws IOException {
22422242
* @return check runs for the given ref
22432243
* @throws IOException
22442244
* the io exception
2245-
* @see <a href="https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-specific-ref">List check runs
2245+
* @see <a href= "https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-specific-ref">List check runs
22462246
* for a specific ref</a>
22472247
*/
22482248
public PagedIterable<GHCheckRun> getCheckRuns(String ref, Map<String, Object> params) throws IOException {
@@ -3568,7 +3568,8 @@ void populate() throws IOException {
35683568

35693569
// We don't use the URL provided in the JSON because it is not reliable:
35703570
// 1. There is bug in Push event payloads that returns the wrong url.
3571-
// For Push event repository records, they take the form "https://github.com/{fullName}".
3571+
// For Push event repository records, they take the form
3572+
// "https://github.com/{fullName}".
35723573
// All other occurrences of "url" take the form "https://api.github.com/...".
35733574
// 2. For Installation event payloads, the URL is not provided at all.
35743575

@@ -3649,6 +3650,23 @@ public List<GHRepositoryTrafficTopReferralSources> getTopReferralSources() throw
36493650
.fetch(GHRepositoryTrafficTopReferralSources[].class));
36503651
}
36513652

3653+
/**
3654+
* Get all active rules that apply to the specified branch
3655+
* (https://docs.github.com/en/rest/repos/rules?apiVersion=2022-11-28#get-rules-for-a-branch).
3656+
*
3657+
* @param branch
3658+
* the branch
3659+
* @return the rules for branch
3660+
* @throws IOException
3661+
* the io exception
3662+
*/
3663+
public PagedIterable<GHRepositoryRule> listRulesForBranch(String branch) throws IOException {
3664+
return root().createRequest()
3665+
.method("GET")
3666+
.withUrlPath(getApiTailUrl("/rules/branches/" + branch))
3667+
.toIterable(GHRepositoryRule[].class, null);
3668+
}
3669+
36523670
/**
36533671
* A {@link GHRepositoryBuilder} that allows multiple properties to be updated per request.
36543672
*

0 commit comments

Comments
 (0)