Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to get active rules for a branch #1897

Merged
merged 16 commits into from
Aug 1, 2024
26 changes: 22 additions & 4 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ public PagedIterable<GHUser> listCollaborators(CollaboratorAffiliation affiliati

/**
* Lists all
* <a href="https://help.github.com/articles/assigning-issues-and-pull-requests-to-other-github-users/">the
* <a href= "https://help.github.com/articles/assigning-issues-and-pull-requests-to-other-github-users/">the
* available assignees</a> to which issues may be assigned.
*
* @return the paged iterable
Expand Down Expand Up @@ -2222,7 +2222,7 @@ public GHCommitStatus getLastCommitStatus(String sha1) throws IOException {
* @return check runs for given ref
* @throws IOException
* the io exception
* @see <a href="https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-specific-ref">List check runs
* @see <a href= "https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-specific-ref">List check runs
* for a specific ref</a>
*/
public PagedIterable<GHCheckRun> getCheckRuns(String ref) throws IOException {
Expand All @@ -2242,7 +2242,7 @@ public PagedIterable<GHCheckRun> getCheckRuns(String ref) throws IOException {
* @return check runs for the given ref
* @throws IOException
* the io exception
* @see <a href="https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-specific-ref">List check runs
* @see <a href= "https://developer.github.com/v3/checks/runs/#list-check-runs-for-a-specific-ref">List check runs
* for a specific ref</a>
*/
public PagedIterable<GHCheckRun> getCheckRuns(String ref, Map<String, Object> params) throws IOException {
Expand Down Expand Up @@ -3568,7 +3568,8 @@ void populate() throws IOException {

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

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

/**
* Get all active rules that apply to the specified branch
* (https://docs.github.com/en/rest/repos/rules?apiVersion=2022-11-28#get-rules-for-a-branch).
*
* @param branch
* the branch
* @return the rules for branch
* @throws IOException
* the io exception
*/
public PagedIterable<GHRepositoryRule> listRulesForBranch(String branch) throws IOException {
return root().createRequest()
.method("GET")
.withUrlPath(getApiTailUrl("/rules/branches/" + branch))
.toIterable(GHRepositoryRule[].class, null);
}

/**
* A {@link GHRepositoryBuilder} that allows multiple properties to be updated per request.
*
Expand Down
Loading