forked from hub4j/github-api
-
Notifications
You must be signed in to change notification settings - Fork 2
Cet 19215 be pull secret scanning alerts #33
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
205 changes: 205 additions & 0 deletions
205
src/main/java/org/kohsuke/github/GHSecretScanningAlert.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
package org.kohsuke.github; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.Arrays; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
/** | ||
* Secret scanning alert for a repository | ||
* | ||
* <a href="https://docs.github.com/en/rest/secret-scanning/secret-scanning"></a> | ||
*/ | ||
@SuppressFBWarnings(value = { "UUF_UNUSED_FIELD" }, justification = "JSON API") | ||
public class GHSecretScanningAlert extends GHObject { | ||
@JsonIgnore | ||
private GHRepository owner; | ||
private long number; | ||
private String html_url; | ||
private String locations_url; | ||
private GHSecretScanningAlertState state; | ||
private String resolution; | ||
private String resolved_at; | ||
private GHUser resolved_by; | ||
private String secret_type; | ||
private String secret_type_display_name; | ||
private String secret; | ||
|
||
private Boolean push_protection_bypassed; | ||
private GHUser push_protection_bypassed_by; | ||
private String push_protection_bypassed_at; | ||
|
||
private String created_at; | ||
private String updated_at; | ||
|
||
GHSecretScanningAlert wrap(GHRepository owner) { | ||
this.owner = owner; | ||
return this; | ||
} | ||
|
||
/** | ||
* Id/number of the alert. | ||
* | ||
* @return the id/number | ||
* @see #getId() | ||
*/ | ||
public long getNumber() { | ||
return number; | ||
} | ||
|
||
/** | ||
* Id/number of the alert. | ||
* | ||
* @return the id/number | ||
* @see #getNumber() | ||
*/ | ||
@Override | ||
public long getId() { | ||
return getNumber(); | ||
} | ||
|
||
@Override | ||
public URL getHtmlUrl() throws IOException { | ||
return GitHubClient.parseURL(html_url); | ||
} | ||
|
||
/** | ||
* State of alert | ||
* | ||
* @return the state | ||
*/ | ||
public GHSecretScanningAlertState getState() { | ||
return state; | ||
} | ||
|
||
/** | ||
* Resolution of the alert. Can be 'false_positive', 'wont_fix', 'revoked', 'used_in_tests', or null. | ||
* | ||
* @return the resolution | ||
*/ | ||
public String getResolution() { | ||
return resolution; | ||
} | ||
|
||
/** | ||
* Time when alert was resolved. Non-null when {@link #getState()} is <i>Resolved</i> | ||
* | ||
* @return the time | ||
*/ | ||
public Date getResolvedAt() { | ||
return GitHubClient.parseDate(resolved_at); | ||
} | ||
|
||
/** | ||
* User that has resolved the alert. Non-null when {@link #getState()} is <i>Resolved</i> | ||
* | ||
* <p> | ||
* Note: User object returned by secret scanning GitHub API does not contain all fields. Use with caution | ||
* </p> | ||
* | ||
* @return the user | ||
*/ | ||
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior") | ||
public GHUser getResolvedBy() { | ||
return resolved_by; | ||
} | ||
|
||
/** | ||
* Type of secret that was detected | ||
* | ||
* @return the secret type | ||
*/ | ||
public String getSecretType() { | ||
return secret_type; | ||
} | ||
|
||
/** | ||
* Display name for tyype of secret that was detected | ||
* | ||
* @return the secret type display name | ||
*/ | ||
public String getSecretTypeDisplayName() { | ||
return secret_type_display_name; | ||
} | ||
|
||
/** | ||
* Secret value that was detected | ||
* | ||
* @return the secret value | ||
*/ | ||
public String getSecret() { | ||
return secret; | ||
} | ||
|
||
/** | ||
* Whether push protection was bypassed for this alert | ||
* | ||
* @return true if push protection was bypassed, false otherwise | ||
*/ | ||
public Boolean isPushProtectionBypassed() { | ||
return push_protection_bypassed; | ||
} | ||
|
||
/** | ||
* User that bypassed push protection. Non-null when {@link #isPushProtectionBypassed()} is true | ||
* | ||
* @return the user | ||
*/ | ||
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior") | ||
public GHUser getPushProtectionBypassedBy() { | ||
return push_protection_bypassed_by; | ||
} | ||
|
||
/** | ||
* Time when push protection was bypassed. Non-null when {@link #isPushProtectionBypassed()} is true | ||
* | ||
* @return the time | ||
*/ | ||
public Date getPushProtectionBypassedAt() { | ||
return GitHubClient.parseDate(push_protection_bypassed_at); | ||
} | ||
|
||
/** | ||
* Gets created at. | ||
* | ||
* @return the created at | ||
*/ | ||
public Date getCreatedAt() { | ||
return GitHubClient.parseDate(created_at); | ||
} | ||
|
||
/** | ||
* Gets updated at. | ||
* | ||
* @return the updated at | ||
*/ | ||
public Date getUpdatedAt() { | ||
return GitHubClient.parseDate(updated_at); | ||
} | ||
|
||
/** | ||
* Gets locations url. | ||
* | ||
* @return the locations url | ||
*/ | ||
public String getLocationsUrl() { | ||
return locations_url; | ||
} | ||
|
||
/** | ||
* Gets locations. | ||
* | ||
* @return the locations array | ||
* @throws IOException | ||
* the io exception | ||
*/ | ||
public List<GHSecretScanningAlertLocation> getLocations() throws IOException { | ||
return Arrays.asList( | ||
root().createRequest().withUrlPath(getLocationsUrl()).fetch(GHSecretScanningAlertLocation[].class)); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/org/kohsuke/github/GHSecretScanningAlertLocation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.kohsuke.github; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
|
||
/** | ||
* Code scanning alert for a repository | ||
* | ||
* <a href="https://docs.github.com/en/rest/reference/code-scanning"></a> | ||
*/ | ||
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API") | ||
public class GHSecretScanningAlertLocation { | ||
private String type; | ||
private GHSecretScanningAlertLocationDetails details; | ||
|
||
/** | ||
* Instantiates a new GH secret scanning alert location. | ||
*/ | ||
public GHSecretScanningAlertLocation() { | ||
} | ||
|
||
/** | ||
* The type of location. | ||
* | ||
* @return the type | ||
*/ | ||
public String getType() { | ||
return type; | ||
} | ||
|
||
/** | ||
* The details of the location. | ||
* | ||
* @return the details | ||
*/ | ||
public GHSecretScanningAlertLocationDetails getDetails() { | ||
return details; | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/org/kohsuke/github/GHSecretScanningAlertLocationDetails.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.kohsuke.github; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
|
||
/** | ||
* Code sc for a repository | ||
* | ||
* <a href="https://docs.github.com/en/rest/reference/code-scanning"></a> | ||
*/ | ||
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API") | ||
public class GHSecretScanningAlertLocationDetails { | ||
private String path; | ||
|
||
/** | ||
* Instantiates a new GH secret scanning alert location details. | ||
*/ | ||
public GHSecretScanningAlertLocationDetails() { | ||
} | ||
|
||
/** | ||
* The path to the file containing the secret. | ||
* | ||
* @return the path | ||
*/ | ||
public String getPath() { | ||
return path; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/org/kohsuke/github/GHSecretScanningAlertState.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.kohsuke.github; | ||
|
||
/** | ||
* What is the current state of the Secret Scanning Alert | ||
*/ | ||
public enum GHSecretScanningAlertState { | ||
/** | ||
* Alert is open and still an active issue. | ||
*/ | ||
OPEN, | ||
/** | ||
* Issue that has caused the alert has been addressed. | ||
*/ | ||
RESOLVED, | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/org/kohsuke/github/GHSecretScanningAlertsIterable.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.kohsuke.github; | ||
|
||
import java.util.Iterator; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
class GHSecretScanningAlertsIterable extends PagedIterable<GHSecretScanningAlert> { | ||
private final GHRepository owner; | ||
private final GitHubRequest request; | ||
private GHSecretScanningAlert[] result; | ||
|
||
GHSecretScanningAlertsIterable(GHRepository owner, GitHubRequest request) { | ||
this.owner = owner; | ||
this.request = request; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public PagedIterator<GHSecretScanningAlert> _iterator(int pageSize) { | ||
return new PagedIterator<>( | ||
adapt(GitHubPageIterator | ||
.create(owner.root().getClient(), GHSecretScanningAlert[].class, request, pageSize)), | ||
null); | ||
} | ||
|
||
protected Iterator<GHSecretScanningAlert[]> adapt(final Iterator<GHSecretScanningAlert[]> base) { | ||
return new Iterator<GHSecretScanningAlert[]>() { | ||
public boolean hasNext() { | ||
return base.hasNext(); | ||
} | ||
|
||
public GHSecretScanningAlert[] next() { | ||
GHSecretScanningAlert[] v = base.next(); | ||
if (result == null) { | ||
result = v; | ||
} | ||
|
||
for (GHSecretScanningAlert alert : result) { | ||
alert.wrap(owner); | ||
} | ||
return result; | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we pull this in? or is this written by you?