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 b6bb66d

Browse filesBrowse files
author
Xavier CARON
committed
Rule sets implementation
1 parent 2936a1d commit b6bb66d
Copy full SHA for b6bb66d

File tree

Expand file treeCollapse file tree

3 files changed

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

3 files changed

+167
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHRepository.java
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,10 @@ public GHRepository() {
125125
private GHRepository source, parent;
126126

127127
private Boolean isTemplate;
128+
128129
private boolean compareUsePaginatedCommits;
129130

131+
130132
/**
131133
* Read.
132134
*
@@ -3337,6 +3339,34 @@ public PagedIterable<GHRepositoryRule> listRulesForBranch(String branch) throws
33373339
.toIterable(GHRepositoryRule[].class, null);
33383340
}
33393341

3342+
/**
3343+
* Get all rulesets that apply to current repository
3344+
* (https://docs.github.com/en/rest/repos/rules?apiVersion=2022-11-28#get-all-repository-rulesets).
3345+
*
3346+
* @return the rulesets for repository
3347+
*/
3348+
public PagedIterable<GHRuleSet> listRuleSetsForRepository(){
3349+
return root().createRequest()//
3350+
.method("GET")//
3351+
.withUrlPath(getApiTailUrl("/rulesets"))//
3352+
.toIterable(GHRuleSet[].class, null);
3353+
}
3354+
3355+
/**
3356+
* Get a ruleset that apply to current repository by its ID
3357+
* (https://docs.github.com/en/rest/repos/rules?apiVersion=2022-11-28#get-a-repository-ruleset).
3358+
*
3359+
* @param id the ID of this ruleset
3360+
* @return the ruleset
3361+
* @throws IOException
3362+
*/
3363+
public GHRuleSet getARepositoryRuleSet(int id) throws IOException{
3364+
return root().createRequest()//
3365+
.method("GET")//
3366+
.withUrlPath(getApiTailUrl("/rulesets/"+id))//
3367+
.fetch(GHRuleSet.class);
3368+
}
3369+
33403370
/**
33413371
* Check, if vulnerability alerts are enabled for this repository
33423372
* (https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#check-if-vulnerability-alerts-are-enabled-for-a-repository).
+90Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package org.kohsuke.github;
2+
3+
public class GHRuleSet extends GitHubInteractiveObject {
4+
5+
6+
public enum RuleSetEnforcement {
7+
8+
DISABLED("disabled"), ACTIVE("active"), EVALUATE("evaluate");
9+
10+
private String value;
11+
12+
RuleSetEnforcement(String value) {
13+
this.value = value;
14+
}
15+
16+
public String getValue() {
17+
return value;
18+
}
19+
20+
public void setValue(String value) {
21+
this.value = value;
22+
}
23+
24+
}
25+
26+
private Long id;
27+
28+
private String name;
29+
30+
private String sourceType;
31+
32+
private String source;
33+
34+
private RuleSetEnforcement enforcement;
35+
36+
private String nodeId;
37+
38+
public Long getId() {
39+
return id;
40+
}
41+
42+
public void setId(Long id) {
43+
this.id = id;
44+
}
45+
46+
public String getName() {
47+
return name;
48+
}
49+
50+
public void setName(String name) {
51+
this.name = name;
52+
}
53+
54+
public String getSourceType() {
55+
return sourceType;
56+
}
57+
58+
public void setSourceType(String sourceType) {
59+
this.sourceType = sourceType;
60+
}
61+
62+
public String getSource() {
63+
return source;
64+
}
65+
66+
public void setSource(String source) {
67+
this.source = source;
68+
}
69+
70+
public RuleSetEnforcement getEnforcement() {
71+
return enforcement;
72+
}
73+
74+
public void setEnforcement(RuleSetEnforcement enforcement) {
75+
this.enforcement = enforcement;
76+
}
77+
78+
public String getNodeId() {
79+
return nodeId;
80+
}
81+
82+
public void setNodeId(String nodeId) {
83+
this.nodeId = nodeId;
84+
}
85+
86+
public GHRuleSetBuilder updateRuleSet() {
87+
return new GHRuleSetBuilder(this);
88+
}
89+
90+
}
+47Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.kohsuke.github;
2+
3+
import org.kohsuke.github.GHRuleSet.RuleSetEnforcement;
4+
5+
public class GHRuleSetBuilder {
6+
7+
private GHRuleSet ruleSet;
8+
9+
private Requester builder;
10+
11+
public GHRuleSetBuilder(GHRuleSet ghRuleSet) {
12+
this.ruleSet = ghRuleSet;
13+
this.builder = ruleSet.root().createRequest();
14+
}
15+
16+
17+
public GHRuleSetBuilder id(Long id) {
18+
builder.with("id", id);
19+
return this;
20+
}
21+
22+
public GHRuleSetBuilder name(String name) {
23+
builder.with("name", name);
24+
return this;
25+
}
26+
27+
public GHRuleSetBuilder sourceType(String sourceType) {
28+
builder.with("source_type", sourceType);
29+
return this;
30+
}
31+
32+
public GHRuleSetBuilder source(String source) {
33+
builder.with("source", source);
34+
return this;
35+
}
36+
37+
public GHRuleSetBuilder enforcement(RuleSetEnforcement enforcement) {
38+
builder.with("enforcement", enforcement.getValue());
39+
return this;
40+
}
41+
42+
public GHRuleSetBuilder nodeId(String nodeId) {
43+
builder.with("node_id", nodeId);
44+
return this;
45+
}
46+
47+
}

0 commit comments

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