Skip to content

Commit

Permalink
Add support for setting all labels in a single request
Browse files Browse the repository at this point in the history
Reviewed-by: ehelin
  • Loading branch information
rwestberg committed Jan 28, 2021
1 parent 81faf24 commit 53337ec
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public Issue createBackport(Issue primary, String fixVersion, String assignee) {

// The backport should not have any labels set - if it does, clear them
var labels = issue.labels();
for (var label : labels) {
issue.removeLabel(label);
if (!labels.isEmpty()) {
issue.setLabels(List.of());
}
return issue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ public void removeLabel(String label) {
labels.remove(label);
}

@Override
public void setLabels(List<String> labels) {
this.labels = new HashSet<>(labels);
}

@Override
public List<String> labels() {
return new ArrayList<String>(labels);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,19 @@ public void removeLabel(String label) {
.execute();
}

@Override
public void setLabels(List<String> labels) {
var labelArray = JSON.array();
for (var label : labels) {
labelArray.add(label);
}
var query = JSON.object().put("labels", labelArray);
request.put("issues/" + json.get("number").toString() + "/labels")
.body(query)
.execute();
this.labels = labels;
}

@Override
public List<String> labels() {
if (labels == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,14 @@ public void removeLabel(String label) {
.execute();
}

@Override
public void setLabels(List<String> labels) {
request.put("")
.body("labels", String.join(",", labels))
.execute();
this.labels = labels;
}

@Override
public List<String> labels() {
if (labels == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ default boolean isResolved() {
*/
void removeLabel(String label);

/**
* Set the given labels and remove any others.
*/
void setLabels(List<String> labels);

/**
* Retrieves all the currently set labels.
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,19 @@ public void removeLabel(String label) {
request.put("").body(query).execute();
}

@Override
public void setLabels(List<String> labels) {
var labelsArray = JSON.array();
for (var label : labels) {
labelsArray.add(label);
}
var query = JSON.object()
.put("update", JSON.object()
.put("labels", JSON.array().add(JSON.object()
.put("set", labelsArray))));
request.put("").body(query).execute();
}

@Override
public List<String> labels() {
return json.get("fields").get("labels").stream()
Expand Down
10 changes: 10 additions & 0 deletions test/src/main/java/org/openjdk/skara/test/TestIssue.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ public void removeLabel(String label) {
data.lastUpdate = ZonedDateTime.now();
}

@Override
public void setLabels(List<String> labels) {
data.labels.clear();
var now = ZonedDateTime.now();
for (var label : labels) {
data.labels.put(label, now);
}
data.lastUpdate = now;
}

@Override
public List<String> labels() {
return new ArrayList<>(data.labels.keySet());
Expand Down

1 comment on commit 53337ec

@openjdk-notifier
Copy link

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.