Skip to content

Commit 1d290fb

Browse files
authored
Merge pull request #33 from cortexapps/CET-19215-BE-Pull-secret-scanning-alerts
Cet 19215 be pull secret scanning alerts
2 parents f2941fe + f74b427 commit 1d290fb

16 files changed

+899
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>org.kohsuke</groupId>
44
<artifactId>cortexapps-github-api</artifactId>
5-
<version>1.326</version>
5+
<version>1.327</version>
66
<name>GitHub API for Java</name>
77
<url>https://github-api.kohsuke.org/</url>
88
<description>GitHub API for Java</description>

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3496,6 +3496,47 @@ public <T> void dispatch(String eventType, @Nullable T clientPayload) throws IOE
34963496
.send();
34973497
}
34983498

3499+
/**
3500+
* Lists the secret scanning alerts for this repository
3501+
*
3502+
* @return the paged iterable
3503+
*/
3504+
public PagedIterable<GHSecretScanningAlert> listSecretScanningAlerts() {
3505+
return listSecretScanningAlerts(Collections.emptyMap());
3506+
}
3507+
3508+
/**
3509+
* Lists the secret scanning alerts for this repository filtered on the alert state
3510+
*
3511+
* @param state
3512+
* state of the alert
3513+
* @return the paged iterable
3514+
*/
3515+
public PagedIterable<GHSecretScanningAlert> listSecretScanningAlerts(GHSecretScanningAlertState state) {
3516+
return listSecretScanningAlerts(Collections.singletonMap("state", state.name().toLowerCase()));
3517+
}
3518+
3519+
private PagedIterable<GHSecretScanningAlert> listSecretScanningAlerts(Map<String, Object> filters) {
3520+
return new GHSecretScanningAlertsIterable(this,
3521+
root().createRequest().withUrlPath(getApiTailUrl("secret-scanning/alerts")).with(filters).build());
3522+
}
3523+
3524+
/**
3525+
* Get secret scanning alert by number
3526+
*
3527+
* @param number
3528+
* number of the secret scanning alert
3529+
* @return the secret scanning alert
3530+
* @throws IOException
3531+
* the io exception
3532+
*/
3533+
public GHSecretScanningAlert getSecretScanningAlert(long number) throws IOException {
3534+
return root().createRequest()
3535+
.withUrlPath(getApiTailUrl("secret-scanning/alerts"), String.valueOf(number))
3536+
.fetch(GHSecretScanningAlert.class)
3537+
.wrap(this);
3538+
}
3539+
34993540
private <T> T downloadArchive(@Nonnull String type,
35003541
@CheckForNull String ref,
35013542
@Nonnull InputStreamFunction<T> streamFunction) throws IOException {
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
package org.kohsuke.github;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnore;
4+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
5+
6+
import java.io.IOException;
7+
import java.net.URL;
8+
import java.util.Arrays;
9+
import java.util.Date;
10+
import java.util.List;
11+
12+
/**
13+
* Secret scanning alert for a repository
14+
*
15+
* <a href="https://docs.github.com/en/rest/secret-scanning/secret-scanning"></a>
16+
*/
17+
@SuppressFBWarnings(value = { "UUF_UNUSED_FIELD" }, justification = "JSON API")
18+
public class GHSecretScanningAlert extends GHObject {
19+
@JsonIgnore
20+
private GHRepository owner;
21+
private long number;
22+
private String html_url;
23+
private String locations_url;
24+
private GHSecretScanningAlertState state;
25+
private String resolution;
26+
private String resolved_at;
27+
private GHUser resolved_by;
28+
private String secret_type;
29+
private String secret_type_display_name;
30+
private String secret;
31+
32+
private Boolean push_protection_bypassed;
33+
private GHUser push_protection_bypassed_by;
34+
private String push_protection_bypassed_at;
35+
36+
private String created_at;
37+
private String updated_at;
38+
39+
GHSecretScanningAlert wrap(GHRepository owner) {
40+
this.owner = owner;
41+
return this;
42+
}
43+
44+
/**
45+
* Id/number of the alert.
46+
*
47+
* @return the id/number
48+
* @see #getId()
49+
*/
50+
public long getNumber() {
51+
return number;
52+
}
53+
54+
/**
55+
* Id/number of the alert.
56+
*
57+
* @return the id/number
58+
* @see #getNumber()
59+
*/
60+
@Override
61+
public long getId() {
62+
return getNumber();
63+
}
64+
65+
@Override
66+
public URL getHtmlUrl() throws IOException {
67+
return GitHubClient.parseURL(html_url);
68+
}
69+
70+
/**
71+
* State of alert
72+
*
73+
* @return the state
74+
*/
75+
public GHSecretScanningAlertState getState() {
76+
return state;
77+
}
78+
79+
/**
80+
* Resolution of the alert. Can be 'false_positive', 'wont_fix', 'revoked', 'used_in_tests', or null.
81+
*
82+
* @return the resolution
83+
*/
84+
public String getResolution() {
85+
return resolution;
86+
}
87+
88+
/**
89+
* Time when alert was resolved. Non-null when {@link #getState()} is <i>Resolved</i>
90+
*
91+
* @return the time
92+
*/
93+
public Date getResolvedAt() {
94+
return GitHubClient.parseDate(resolved_at);
95+
}
96+
97+
/**
98+
* User that has resolved the alert. Non-null when {@link #getState()} is <i>Resolved</i>
99+
*
100+
* <p>
101+
* Note: User object returned by secret scanning GitHub API does not contain all fields. Use with caution
102+
* </p>
103+
*
104+
* @return the user
105+
*/
106+
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior")
107+
public GHUser getResolvedBy() {
108+
return resolved_by;
109+
}
110+
111+
/**
112+
* Type of secret that was detected
113+
*
114+
* @return the secret type
115+
*/
116+
public String getSecretType() {
117+
return secret_type;
118+
}
119+
120+
/**
121+
* Display name for tyype of secret that was detected
122+
*
123+
* @return the secret type display name
124+
*/
125+
public String getSecretTypeDisplayName() {
126+
return secret_type_display_name;
127+
}
128+
129+
/**
130+
* Secret value that was detected
131+
*
132+
* @return the secret value
133+
*/
134+
public String getSecret() {
135+
return secret;
136+
}
137+
138+
/**
139+
* Whether push protection was bypassed for this alert
140+
*
141+
* @return true if push protection was bypassed, false otherwise
142+
*/
143+
public Boolean isPushProtectionBypassed() {
144+
return push_protection_bypassed;
145+
}
146+
147+
/**
148+
* User that bypassed push protection. Non-null when {@link #isPushProtectionBypassed()} is true
149+
*
150+
* @return the user
151+
*/
152+
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior")
153+
public GHUser getPushProtectionBypassedBy() {
154+
return push_protection_bypassed_by;
155+
}
156+
157+
/**
158+
* Time when push protection was bypassed. Non-null when {@link #isPushProtectionBypassed()} is true
159+
*
160+
* @return the time
161+
*/
162+
public Date getPushProtectionBypassedAt() {
163+
return GitHubClient.parseDate(push_protection_bypassed_at);
164+
}
165+
166+
/**
167+
* Gets created at.
168+
*
169+
* @return the created at
170+
*/
171+
public Date getCreatedAt() {
172+
return GitHubClient.parseDate(created_at);
173+
}
174+
175+
/**
176+
* Gets updated at.
177+
*
178+
* @return the updated at
179+
*/
180+
public Date getUpdatedAt() {
181+
return GitHubClient.parseDate(updated_at);
182+
}
183+
184+
/**
185+
* Gets locations url.
186+
*
187+
* @return the locations url
188+
*/
189+
public String getLocationsUrl() {
190+
return locations_url;
191+
}
192+
193+
/**
194+
* Gets locations.
195+
*
196+
* @return the locations array
197+
* @throws IOException
198+
* the io exception
199+
*/
200+
public List<GHSecretScanningAlertLocation> getLocations() throws IOException {
201+
return Arrays.asList(
202+
root().createRequest().withUrlPath(getLocationsUrl()).fetch(GHSecretScanningAlertLocation[].class));
203+
}
204+
205+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.kohsuke.github;
2+
3+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
4+
5+
/**
6+
* Code scanning alert for a repository
7+
*
8+
* <a href="https://docs.github.com/en/rest/reference/code-scanning"></a>
9+
*/
10+
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API")
11+
public class GHSecretScanningAlertLocation {
12+
private String type;
13+
private GHSecretScanningAlertLocationDetails details;
14+
15+
/**
16+
* Instantiates a new GH secret scanning alert location.
17+
*/
18+
public GHSecretScanningAlertLocation() {
19+
}
20+
21+
/**
22+
* The type of location.
23+
*
24+
* @return the type
25+
*/
26+
public String getType() {
27+
return type;
28+
}
29+
30+
/**
31+
* The details of the location.
32+
*
33+
* @return the details
34+
*/
35+
public GHSecretScanningAlertLocationDetails getDetails() {
36+
return details;
37+
}
38+
39+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.kohsuke.github;
2+
3+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
4+
5+
/**
6+
* Code sc for a repository
7+
*
8+
* <a href="https://docs.github.com/en/rest/reference/code-scanning"></a>
9+
*/
10+
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API")
11+
public class GHSecretScanningAlertLocationDetails {
12+
private String path;
13+
14+
/**
15+
* Instantiates a new GH secret scanning alert location details.
16+
*/
17+
public GHSecretScanningAlertLocationDetails() {
18+
}
19+
20+
/**
21+
* The path to the file containing the secret.
22+
*
23+
* @return the path
24+
*/
25+
public String getPath() {
26+
return path;
27+
}
28+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.kohsuke.github;
2+
3+
/**
4+
* What is the current state of the Secret Scanning Alert
5+
*/
6+
public enum GHSecretScanningAlertState {
7+
/**
8+
* Alert is open and still an active issue.
9+
*/
10+
OPEN,
11+
/**
12+
* Issue that has caused the alert has been addressed.
13+
*/
14+
RESOLVED,
15+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.kohsuke.github;
2+
3+
import java.util.Iterator;
4+
5+
import javax.annotation.Nonnull;
6+
7+
class GHSecretScanningAlertsIterable extends PagedIterable<GHSecretScanningAlert> {
8+
private final GHRepository owner;
9+
private final GitHubRequest request;
10+
private GHSecretScanningAlert[] result;
11+
12+
GHSecretScanningAlertsIterable(GHRepository owner, GitHubRequest request) {
13+
this.owner = owner;
14+
this.request = request;
15+
}
16+
17+
@Nonnull
18+
@Override
19+
public PagedIterator<GHSecretScanningAlert> _iterator(int pageSize) {
20+
return new PagedIterator<>(
21+
adapt(GitHubPageIterator
22+
.create(owner.root().getClient(), GHSecretScanningAlert[].class, request, pageSize)),
23+
null);
24+
}
25+
26+
protected Iterator<GHSecretScanningAlert[]> adapt(final Iterator<GHSecretScanningAlert[]> base) {
27+
return new Iterator<GHSecretScanningAlert[]>() {
28+
public boolean hasNext() {
29+
return base.hasNext();
30+
}
31+
32+
public GHSecretScanningAlert[] next() {
33+
GHSecretScanningAlert[] v = base.next();
34+
if (result == null) {
35+
result = v;
36+
}
37+
38+
for (GHSecretScanningAlert alert : result) {
39+
alert.wrap(owner);
40+
}
41+
return result;
42+
}
43+
};
44+
}
45+
}

0 commit comments

Comments
 (0)