|
| 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 | + * Secret scanning alert for a repository |
| 12 | + * |
| 13 | + * <a href="https://docs.github.com/en/rest/secret-scanning/secret-scanning"></a> |
| 14 | + */ |
| 15 | +@SuppressFBWarnings(value = { "UUF_UNUSED_FIELD" }, justification = "JSON API") |
| 16 | +public class GHSecretScanningAlert extends GHObject { |
| 17 | + @JsonIgnore |
| 18 | + private GHRepository owner; |
| 19 | + private long number; |
| 20 | + private String html_url; |
| 21 | + private GHSecretScanningAlertState state; |
| 22 | + private String resolution; |
| 23 | + private String resolved_at; |
| 24 | + private GHUser resolved_by; |
| 25 | + private String secret_type; |
| 26 | + private Secret secret; |
| 27 | + private String push_protection_bypassed; |
| 28 | + private GHUser push_protection_bypassed_by; |
| 29 | + private String push_protection_bypassed_at; |
| 30 | + |
| 31 | + GHSecretScanningAlert wrap(GHRepository owner) { |
| 32 | + this.owner = owner; |
| 33 | + return this; |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * Id/number of the alert. |
| 38 | + * |
| 39 | + * @return the id/number |
| 40 | + * @see #getId() |
| 41 | + */ |
| 42 | + public long getNumber() { |
| 43 | + return number; |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Id/number of the alert. |
| 48 | + * |
| 49 | + * @return the id/number |
| 50 | + * @see #getNumber() |
| 51 | + */ |
| 52 | + @Override |
| 53 | + public long getId() { |
| 54 | + return getNumber(); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * State of alert |
| 59 | + * |
| 60 | + * @return the state |
| 61 | + */ |
| 62 | + public GHSecretScanningAlertState getState() { |
| 63 | + return state; |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Resolution of the alert. Can be 'false_positive', 'wont_fix', 'revoked', 'used_in_tests', or null. |
| 68 | + * |
| 69 | + * @return the resolution |
| 70 | + */ |
| 71 | + public String getResolution() { |
| 72 | + return resolution; |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Time when alert was resolved. Non-null when {@link #getState()} is <i>Resolved</i> |
| 77 | + * |
| 78 | + * @return the time |
| 79 | + */ |
| 80 | + public Date getResolvedAt() { |
| 81 | + return GitHubClient.parseDate(resolved_at); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * User that has resolved the alert. Non-null when {@link #getState()} is <i>Resolved</i> |
| 86 | + * |
| 87 | + * <p> |
| 88 | + * Note: User object returned by secret scanning GitHub API does not contain all fields. Use with caution |
| 89 | + * </p> |
| 90 | + * |
| 91 | + * @return the user |
| 92 | + */ |
| 93 | + @SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior") |
| 94 | + public GHUser getResolvedBy() { |
| 95 | + return resolved_by; |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * Type of secret that was detected |
| 100 | + * |
| 101 | + * @return the secret type |
| 102 | + */ |
| 103 | + public String getSecretType() { |
| 104 | + return secret_type; |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Secret that was detected |
| 109 | + * |
| 110 | + * @return the secret |
| 111 | + */ |
| 112 | + public Secret getSecret() { |
| 113 | + return secret; |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * Whether push protection was bypassed for this alert |
| 118 | + * |
| 119 | + * @return true if push protection was bypassed, false otherwise |
| 120 | + */ |
| 121 | + public boolean isPushProtectionBypassed() { |
| 122 | + return push_protection_bypassed != null && !push_protection_bypassed.isEmpty(); |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * User that bypassed push protection. Non-null when {@link #isPushProtectionBypassed()} is true |
| 127 | + * |
| 128 | + * @return the user |
| 129 | + */ |
| 130 | + @SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior") |
| 131 | + public GHUser getPushProtectionBypassedBy() { |
| 132 | + return push_protection_bypassed_by; |
| 133 | + } |
| 134 | + |
| 135 | + /** |
| 136 | + * Time when push protection was bypassed. Non-null when {@link #isPushProtectionBypassed()} is true |
| 137 | + * |
| 138 | + * @return the time |
| 139 | + */ |
| 140 | + public Date getPushProtectionBypassedAt() { |
| 141 | + return GitHubClient.parseDate(push_protection_bypassed_at); |
| 142 | + } |
| 143 | + |
| 144 | + @Override |
| 145 | + public URL getHtmlUrl() throws IOException { |
| 146 | + return GitHubClient.parseURL(html_url); |
| 147 | + } |
| 148 | + |
| 149 | + /** |
| 150 | + * Secret details |
| 151 | + */ |
| 152 | + @SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API") |
| 153 | + public static class Secret { |
| 154 | + private String name; |
| 155 | + private String type; |
| 156 | + private String value; |
| 157 | + |
| 158 | + /** |
| 159 | + * Name of the secret |
| 160 | + * |
| 161 | + * @return the name |
| 162 | + */ |
| 163 | + public String getName() { |
| 164 | + return name; |
| 165 | + } |
| 166 | + |
| 167 | + /** |
| 168 | + * Type of the secret |
| 169 | + * |
| 170 | + * @return the type |
| 171 | + */ |
| 172 | + public String getType() { |
| 173 | + return type; |
| 174 | + } |
| 175 | + |
| 176 | + /** |
| 177 | + * Value of the secret |
| 178 | + * |
| 179 | + * @return the value |
| 180 | + */ |
| 181 | + public String getValue() { |
| 182 | + return value; |
| 183 | + } |
| 184 | + } |
| 185 | +} |
0 commit comments