Skip to content

Commit 953e5c4

Browse files
akashRindhewwong
authored andcommitted
(feat) Add data models for code scanning alert and related structures
[#1133]
1 parent be00e51 commit 953e5c4

File tree

3 files changed

+348
-0
lines changed

3 files changed

+348
-0
lines changed
Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
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.Date;
9+
10+
/**
11+
* Code scanning alert for a repository
12+
*
13+
* <a href="https://docs.github.com/en/rest/reference/code-scanning"></a>
14+
*/
15+
@SuppressFBWarnings(value = { "UUF_UNUSED_FIELD" }, justification = "JSON API")
16+
public class GHCodeScanningAlert extends GHObject {
17+
@JsonIgnore
18+
private GHRepository owner;
19+
private long number;
20+
private String html_url;
21+
private GHCodeScanningAlertState state;
22+
private GHUser dismissed_by;
23+
private String dismissed_at;
24+
private String dismissed_reason;
25+
private Tool tool;
26+
private Rule rule;
27+
private GHCodeScanningAlertInstance most_recent_instance;
28+
private String instances_url;
29+
30+
GHCodeScanningAlert wrap(GHRepository owner) {
31+
this.owner = owner;
32+
return wrap(owner.root);
33+
}
34+
35+
GHCodeScanningAlert wrap(GitHub root) {
36+
this.root = root;
37+
if (owner != null) {
38+
owner.wrap(root);
39+
}
40+
return this;
41+
}
42+
43+
/**
44+
* Id/number of the alert.
45+
*
46+
* @return the id/number
47+
* @see #getId()
48+
*/
49+
public long getNumber() {
50+
return number;
51+
}
52+
53+
/**
54+
* Id/number of the alert.
55+
*
56+
* @return the id/number
57+
* @see #getNumber()
58+
*/
59+
@Override
60+
public long getId() {
61+
return getNumber();
62+
}
63+
64+
/**
65+
* State of alert
66+
*
67+
* @return the state
68+
*/
69+
public GHCodeScanningAlertState getState() {
70+
return state;
71+
}
72+
73+
/**
74+
* User that has dismissed the alert. Non-null when {@link #getState()} is <i>Dismissed</i>
75+
*
76+
* <p>
77+
* Note: User object returned by code scanning GitHub API does not contain all fields. Use with caution
78+
* </p>
79+
*
80+
* @return the user
81+
*/
82+
public GHUser getDismissedBy() {
83+
return dismissed_by;
84+
}
85+
86+
/**
87+
* Time when alert was dismissed. Non-null when {@link #getState()} is <i>Dismissed</i>
88+
*
89+
* @return the time
90+
*/
91+
public Date getDismissedAt() {
92+
return GitHubClient.parseDate(dismissed_at);
93+
}
94+
95+
/**
96+
* Reason provided for dismissing the alert.
97+
*
98+
* @return the reason
99+
*/
100+
public String getDismissedReason() {
101+
return dismissed_reason;
102+
}
103+
104+
/**
105+
* Code scanning tool that created this alert
106+
*
107+
* @return the tool
108+
*/
109+
public Tool getTool() {
110+
return tool;
111+
}
112+
113+
/**
114+
* Code scanning rule that was violated, causing the alert
115+
*
116+
* @return the rule
117+
*/
118+
public Rule getRule() {
119+
return rule;
120+
}
121+
122+
/**
123+
* Most recent instance of the alert
124+
*
125+
* @return most recent instance
126+
*/
127+
public GHCodeScanningAlertInstance getMostRecentInstance() {
128+
return most_recent_instance;
129+
}
130+
131+
@Override
132+
public URL getHtmlUrl() throws IOException {
133+
return GitHubClient.parseURL(html_url);
134+
}
135+
136+
/**
137+
* Code scanning rule
138+
*/
139+
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API")
140+
static class Rule {
141+
private String id;
142+
private String severity;
143+
private String description;
144+
private String name;
145+
private String full_description;
146+
private String[] tags;
147+
private String help;
148+
149+
/**
150+
* Id of rule
151+
*
152+
* @return the id
153+
*/
154+
public String getId() {
155+
return id;
156+
}
157+
158+
/**
159+
* Severity of rule
160+
*
161+
* @return the severity
162+
*/
163+
public String getSeverity() {
164+
return severity;
165+
}
166+
167+
/**
168+
* Description of rule
169+
*
170+
* @return the description
171+
*/
172+
public String getDescription() {
173+
return description;
174+
}
175+
176+
/**
177+
* Name of rule
178+
*
179+
* @return the name
180+
*/
181+
public String getName() {
182+
return name;
183+
}
184+
185+
/**
186+
* Full description of rule
187+
*
188+
* @return the full description
189+
*/
190+
public String getFullDescription() {
191+
return full_description;
192+
}
193+
194+
/**
195+
* Tags associated with the rule
196+
*
197+
* @return the tags
198+
*/
199+
public String[] getTags() {
200+
return tags;
201+
}
202+
203+
/**
204+
* Help text for the rule
205+
*
206+
* @return the help text
207+
*/
208+
public String getHelp() {
209+
return help;
210+
}
211+
}
212+
213+
/**
214+
* Code scanning tool
215+
*/
216+
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API")
217+
static class Tool {
218+
private String name;
219+
private String guid;
220+
private String version;
221+
222+
/**
223+
* Name of code scanning tool
224+
*
225+
* @return the name
226+
*/
227+
public String getName() {
228+
return name;
229+
}
230+
231+
/**
232+
* GUID of code scanning tool
233+
*
234+
* @return the GUID
235+
*/
236+
public String getGuid() {
237+
return guid;
238+
}
239+
240+
/**
241+
* Version of code scanning tool
242+
*
243+
* @return the version
244+
*/
245+
public String getVersion() {
246+
return version;
247+
}
248+
}
249+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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.util.Arrays;
7+
import java.util.Collections;
8+
import java.util.List;
9+
10+
public class GHCodeScanningAlertInstance {
11+
12+
@JsonIgnore
13+
private GHCodeScanningAlert owner;
14+
15+
private String ref;
16+
private String analysis_key;
17+
private String environment;
18+
private GHCodeScanningAlertState state;
19+
private String commit_sha;
20+
private String[] classifications;
21+
private Message message;
22+
private Location location;
23+
24+
public String getRef() {
25+
return ref;
26+
}
27+
28+
public String getAnalysisKey() {
29+
return analysis_key;
30+
}
31+
32+
public String getEnvironment() {
33+
return environment;
34+
}
35+
36+
public GHCodeScanningAlertState getState() {
37+
return state;
38+
}
39+
40+
public String getCommitSha() {
41+
return commit_sha;
42+
}
43+
44+
public List<String> getClassifications() {
45+
return Collections.unmodifiableList(Arrays.asList(classifications));
46+
}
47+
48+
public Message getMessage() {
49+
return message;
50+
}
51+
52+
public Location getLocation() {
53+
return location;
54+
}
55+
56+
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API")
57+
static class Message {
58+
59+
private String text;
60+
61+
public String getText() {
62+
return text;
63+
}
64+
}
65+
66+
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API")
67+
static class Location {
68+
private String path;
69+
private long start_line;
70+
private long end_line;
71+
private long start_column;
72+
private long end_column;
73+
74+
public String getPath() {
75+
return path;
76+
}
77+
78+
public long getStartLine() {
79+
return start_line;
80+
}
81+
82+
public long getEndLine() {
83+
return end_line;
84+
}
85+
86+
public long getStartColumn() {
87+
return start_column;
88+
}
89+
90+
public long getEndColumn() {
91+
return end_column;
92+
}
93+
}
94+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.kohsuke.github;
2+
3+
public enum GHCodeScanningAlertState {
4+
OPEN, FIXED, DISMISSED
5+
}

0 commit comments

Comments
 (0)