|
| 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 | +} |
0 commit comments