-
Notifications
You must be signed in to change notification settings - Fork 776
(feat) Support code-scanning API (Pt#1) #1142
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
Closed
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
311575f
(feat) Add data models for code scanning alert and related structures
akashRindhe b2437b8
(feat) Add methods to list code scanning alerts on a repository
akashRindhe 1efcbf1
(feat) Add function to search code scanning alert by id
akashRindhe 6ab47cf
(feat) Add method to list instances of code scanning alert
akashRindhe 3ff6ac0
Merge branch 'main' into feat/1133
bitwiseman 8f0ba6e
Merge branch 'main' into feat/1133
bitwiseman a86959e
Merge branch 'main' into feat/1133
bitwiseman 336189e
Merge branch 'main' into feat/1133
bitwiseman d61bc81
Merge branch 'main' into feat/1133
bitwiseman fe129ca
Merge branch 'main' into feat/1133
bitwiseman 8fc2de2
Bring PR up to current main
bitwiseman c25f5b4
Merge branch 'main' into feat/1133
bitwiseman 8912703
Merge branch 'main' into feat/1133
bitwiseman 8745486
Merge branch 'main' into feat/1133
bitwiseman 90f93fe
Merge branch 'main' into feat/1133
bitwiseman b81ee25
Merge branch 'main' into feat/1133
bitwiseman fc45aeb
Merge branch 'main' into feat/1133
bitwiseman 3f8f079
Merge branch 'main' into feat/1133
bitwiseman 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
252 changes: 252 additions & 0 deletions
252
src/main/java/org/kohsuke/github/GHCodeScanningAlert.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,252 @@ | ||
| 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.Date; | ||
|
|
||
| /** | ||
| * Code scanning alert for a repository | ||
| * | ||
| * <a href="https://docs.github.com/en/rest/reference/code-scanning"></a> | ||
| */ | ||
| @SuppressFBWarnings(value = { "UUF_UNUSED_FIELD" }, justification = "JSON API") | ||
| public class GHCodeScanningAlert extends GHObject { | ||
| @JsonIgnore | ||
| private GHRepository owner; | ||
| private long number; | ||
| private String html_url; | ||
| private GHCodeScanningAlertState state; | ||
| private GHUser dismissed_by; | ||
| private String dismissed_at; | ||
| private String dismissed_reason; | ||
| private Tool tool; | ||
| private Rule rule; | ||
| private GHCodeScanningAlertInstance most_recent_instance; | ||
| private String instances_url; | ||
|
|
||
| GHCodeScanningAlert 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(); | ||
| } | ||
|
|
||
| /** | ||
| * State of alert | ||
| * | ||
| * @return the state | ||
| */ | ||
| public GHCodeScanningAlertState getState() { | ||
| return state; | ||
| } | ||
|
|
||
| /** | ||
| * User that has dismissed the alert. Non-null when {@link #getState()} is <i>Dismissed</i> | ||
| * | ||
| * <p> | ||
| * Note: User object returned by code 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 getDismissedBy() { | ||
| return dismissed_by; | ||
| } | ||
|
|
||
| /** | ||
| * Time when alert was dismissed. Non-null when {@link #getState()} is <i>Dismissed</i> | ||
| * | ||
| * @return the time | ||
| */ | ||
| public Date getDismissedAt() { | ||
| return GitHubClient.parseDate(dismissed_at); | ||
| } | ||
|
|
||
| /** | ||
| * Reason provided for dismissing the alert. | ||
| * | ||
| * @return the reason | ||
| */ | ||
| public String getDismissedReason() { | ||
| return dismissed_reason; | ||
| } | ||
|
|
||
| /** | ||
| * Code scanning tool that created this alert | ||
| * | ||
| * @return the tool | ||
| */ | ||
| public Tool getTool() { | ||
| return tool; | ||
| } | ||
|
|
||
| /** | ||
| * Code scanning rule that was violated, causing the alert | ||
| * | ||
| * @return the rule | ||
| */ | ||
| public Rule getRule() { | ||
| return rule; | ||
| } | ||
|
|
||
| /** | ||
| * Most recent instance of the alert | ||
| * | ||
| * @return most recent instance | ||
| */ | ||
| public GHCodeScanningAlertInstance getMostRecentInstance() { | ||
| return most_recent_instance; | ||
| } | ||
|
|
||
| /** | ||
| * List all instances of the alert | ||
| * | ||
| * @return the paged iterable | ||
| */ | ||
| public PagedIterable<GHCodeScanningAlertInstance> listAlertInstances() { | ||
| return new GHCodeScanningAlertInstancesIterable(this, | ||
| root().createRequest().withUrlPath(instances_url).build()); | ||
| } | ||
|
|
||
| @Override | ||
| public URL getHtmlUrl() throws IOException { | ||
| return GitHubClient.parseURL(html_url); | ||
| } | ||
|
|
||
| /** | ||
| * Code scanning rule | ||
| */ | ||
| @SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API") | ||
| static class Rule { | ||
| private String id; | ||
| private String severity; | ||
| private String description; | ||
| private String name; | ||
| private String full_description; | ||
| private String[] tags; | ||
| private String help; | ||
|
|
||
| /** | ||
| * Id of rule | ||
| * | ||
| * @return the id | ||
| */ | ||
| public String getId() { | ||
| return id; | ||
| } | ||
|
|
||
| /** | ||
| * Severity of rule | ||
| * | ||
| * @return the severity | ||
| */ | ||
| public String getSeverity() { | ||
| return severity; | ||
| } | ||
|
|
||
| /** | ||
| * Description of rule | ||
| * | ||
| * @return the description | ||
| */ | ||
| public String getDescription() { | ||
| return description; | ||
| } | ||
|
|
||
| /** | ||
| * Name of rule | ||
| * | ||
| * @return the name | ||
| */ | ||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| /** | ||
| * Full description of rule | ||
| * | ||
| * @return the full description | ||
| */ | ||
| public String getFullDescription() { | ||
| return full_description; | ||
| } | ||
|
|
||
| /** | ||
| * Tags associated with the rule | ||
| * | ||
| * @return the tags | ||
| */ | ||
| public String[] getTags() { | ||
| return tags; | ||
| } | ||
|
|
||
| /** | ||
| * Help text for the rule | ||
| * | ||
| * @return the help text | ||
| */ | ||
| public String getHelp() { | ||
| return help; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Code scanning tool | ||
| */ | ||
| @SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API") | ||
| static class Tool { | ||
| private String name; | ||
| private String guid; | ||
| private String version; | ||
|
|
||
| /** | ||
| * Name of code scanning tool | ||
| * | ||
| * @return the name | ||
| */ | ||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| /** | ||
| * GUID of code scanning tool | ||
| * | ||
| * @return the GUID | ||
| */ | ||
| public String getGuid() { | ||
| return guid; | ||
| } | ||
|
|
||
| /** | ||
| * Version of code scanning tool | ||
| * | ||
| * @return the version | ||
| */ | ||
| public String getVersion() { | ||
| return version; | ||
| } | ||
| } | ||
| } | ||
88 changes: 88 additions & 0 deletions
88
src/main/java/org/kohsuke/github/GHCodeScanningAlertInstance.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,88 @@ | ||
| package org.kohsuke.github; | ||
|
|
||
| import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| public class GHCodeScanningAlertInstance { | ||
| private String ref; | ||
| private String analysis_key; | ||
| private String environment; | ||
| private GHCodeScanningAlertState state; | ||
| private String commit_sha; | ||
| private String[] classifications; | ||
| private Message message; | ||
| private Location location; | ||
|
|
||
| public String getRef() { | ||
| return ref; | ||
| } | ||
|
|
||
| public String getAnalysisKey() { | ||
| return analysis_key; | ||
| } | ||
|
|
||
| public String getEnvironment() { | ||
| return environment; | ||
| } | ||
|
|
||
| public GHCodeScanningAlertState getState() { | ||
| return state; | ||
| } | ||
|
|
||
| public String getCommitSha() { | ||
| return commit_sha; | ||
| } | ||
|
|
||
| public List<String> getClassifications() { | ||
| return Collections.unmodifiableList(Arrays.asList(classifications)); | ||
| } | ||
|
|
||
| public Message getMessage() { | ||
| return message; | ||
| } | ||
|
|
||
| public Location getLocation() { | ||
| return location; | ||
| } | ||
|
|
||
| @SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API") | ||
| static class Message { | ||
| private String text; | ||
|
|
||
| public String getText() { | ||
| return text; | ||
| } | ||
| } | ||
|
|
||
| @SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API") | ||
| static class Location { | ||
| private String path; | ||
| private long start_line; | ||
| private long end_line; | ||
| private long start_column; | ||
| private long end_column; | ||
|
|
||
| public String getPath() { | ||
| return path; | ||
| } | ||
|
|
||
| public long getStartLine() { | ||
| return start_line; | ||
| } | ||
|
|
||
| public long getEndLine() { | ||
| return end_line; | ||
| } | ||
|
|
||
| public long getStartColumn() { | ||
| return start_column; | ||
| } | ||
|
|
||
| public long getEndColumn() { | ||
| return end_column; | ||
| } | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
src/main/java/org/kohsuke/github/GHCodeScanningAlertInstancesIterable.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,41 @@ | ||
| package org.kohsuke.github; | ||
|
|
||
| import java.util.Iterator; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
|
|
||
| public class GHCodeScanningAlertInstancesIterable extends PagedIterable<GHCodeScanningAlertInstance> { | ||
| private final GHCodeScanningAlert owner; | ||
| private final GitHubRequest request; | ||
| private GHCodeScanningAlertInstance[] result; | ||
|
|
||
| GHCodeScanningAlertInstancesIterable(GHCodeScanningAlert owner, GitHubRequest request) { | ||
| this.owner = owner; | ||
| this.request = request; | ||
| } | ||
|
|
||
| @Nonnull | ||
| @Override | ||
| public PagedIterator<GHCodeScanningAlertInstance> _iterator(int pageSize) { | ||
| return new PagedIterator<>( | ||
| adapt(GitHubPageIterator | ||
| .create(owner.root().getClient(), GHCodeScanningAlertInstance[].class, request, pageSize)), | ||
| null); | ||
| } | ||
|
|
||
| protected Iterator<GHCodeScanningAlertInstance[]> adapt(final Iterator<GHCodeScanningAlertInstance[]> base) { | ||
| return new Iterator<GHCodeScanningAlertInstance[]>() { | ||
| public boolean hasNext() { | ||
| return base.hasNext(); | ||
| } | ||
|
|
||
| public GHCodeScanningAlertInstance[] next() { | ||
| GHCodeScanningAlertInstance[] v = base.next(); | ||
| if (result == null) { | ||
| result = v; | ||
| } | ||
| return result; | ||
| } | ||
| }; | ||
| } | ||
| } |
5 changes: 5 additions & 0 deletions
5
src/main/java/org/kohsuke/github/GHCodeScanningAlertState.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,5 @@ | ||
| package org.kohsuke.github; | ||
|
|
||
| public enum GHCodeScanningAlertState { | ||
| OPEN, FIXED, DISMISSED | ||
| } |
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.
@akashRindhe
This is marked as not covered. Please see if there's anything you can do to cover this method and any other methods that are not covered by tests. Don't wear yourself out on it, but just take another look and see if any of them are easy cover.