Skip to content

Commit

Permalink
Add functionality to get active rules for a branch (#1897)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
ihrigb and bitwiseman authored Aug 1, 2024
1 parent cab9bbb commit 3c4d80c
Show file tree
Hide file tree
Showing 10 changed files with 1,136 additions and 6 deletions.
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

0 comments on commit 3c4d80c

Please sign in to comment.