Skip to content
Permalink
Browse files
Backport security level should be inherited from main issue
Reviewed-by: kcr, darcy
  • Loading branch information
erikj79 committed Apr 8, 2021
1 parent f12ee73 commit 35dd1da1ec3103a17d118ecf028eff698dea6868
@@ -36,7 +36,6 @@ class IssueNotifierBuilder {
private boolean setFixVersion = false;
private Map<String, String> fixVersions = null;
private JbsVault vault = null;
private String securityLevel = null;
private boolean prOnly = true;
private String buildName = null;

@@ -81,11 +80,6 @@ public IssueNotifierBuilder vault(JbsVault vault) {
return this;
}

public IssueNotifierBuilder securityLevel(String securityLevel) {
this.securityLevel = securityLevel;
return this;
}

public IssueNotifierBuilder prOnly(boolean prOnly) {
this.prOnly = prOnly;
return this;
@@ -97,7 +91,7 @@ public IssueNotifierBuilder buildName(String buildName) {
}

IssueNotifier build() {
var jbsBackport = new JbsBackport(issueProject.webUrl(), vault, securityLevel);
var jbsBackport = new JbsBackport(issueProject.webUrl(), vault);
return new IssueNotifier(issueProject, reviewLink, reviewIcon, commitLink, commitIcon,
setFixVersion, fixVersions, jbsBackport, prOnly, buildName);
}
@@ -84,10 +84,6 @@ public Notifier create(BotConfiguration botConfiguration, JSONObject notifierCon
}
}

if (notifierConfiguration.contains("security")) {
builder.securityLevel(notifierConfiguration.get("security").asString());
}

if (notifierConfiguration.contains("pronly")) {
builder.prOnly(notifierConfiguration.get("pronly").asBoolean());
}
@@ -31,7 +31,6 @@
import java.util.stream.Collectors;

public class JbsBackport {
private final String securityLevel;
private final RestRequest backportRequest;

private static URI backportRequest(URI uri) {
@@ -40,8 +39,7 @@ private static URI backportRequest(URI uri) {
.build();
}

JbsBackport(URI uri, JbsVault vault, String securityLevel) {
this.securityLevel = securityLevel;
JbsBackport(URI uri, JbsVault vault) {
if (vault != null) {
backportRequest = new RestRequest(backportRequest(uri), vault.authId(), () -> Arrays.asList("Cookie", vault.getCookie()));
} else {
@@ -75,8 +73,8 @@ public Issue createBackport(Issue primary, String fixVersion, String assignee) {
if (assignee != null) {
request.body("assignee", assignee);
}
if (securityLevel != null) {
request.body("level", securityLevel);
if (primary.properties().containsKey("security")) {
request.body("level", primary.properties().get("security").asString());
}
var response = request.execute();
var issue = primary.project().issue(response.get("key").asString()).orElseThrow();
@@ -1028,6 +1028,7 @@ void testIssueBackport(TestInfo testInfo) throws IOException {
Map.of("issuetype", JSON.of("Enhancement"),
"customfield_10008", JSON.of("java.io")
));
var level = issue.properties().get("security");
issue.setProperty("fixVersions", JSON.array().add("13.0.1"));
issue.setProperty("priority", JSON.of("1"));
issue.addLabel("test");
@@ -1061,6 +1062,11 @@ void testIssueBackport(TestInfo testInfo) throws IOException {

// Labels should not
assertEquals(0, backport.labelNames().size());

// If the parent issue has a security level (can be configured when running a test manually) it should be propagated
if (level != null) {
assertEquals(level.asString(), backport.properties().get("security").asString());
}
}
}
}
@@ -212,7 +212,7 @@ JiraHost jiraHost() {
}

private static final Set<String> knownProperties = Set.of("issuetype", "fixVersions", "versions", "priority", "components");
private static final Set<String> readOnlyProperties = Set.of("resolution");
private static final Set<String> readOnlyProperties = Set.of("resolution", "security");

boolean isAllowedProperty(String name, boolean forWrite) {
if (knownProperties.contains(name)) {
@@ -248,7 +248,8 @@ Optional<JSONValue> decodeProperty(String name, JSONValue value) {
} // fall-through
case "issuetype":
return Optional.of(JSON.of(value.get("name").asString()));
case "priority":
case "priority": // fall-through
case "security":
return Optional.of(JSON.of(value.get("id").asString()));
default:
return Optional.of(value);

1 comment on commit 35dd1da

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 35dd1da Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.