Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-55342] Parse hashtags in change #114

Merged
merged 1 commit into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

Expand All @@ -45,6 +46,7 @@
import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.COMMENTS;
import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.COMMIT_MESSAGE;
import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.TOPIC;
import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.HASHTAGS;
import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.ID;
import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.NUMBER;
import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.OWNER;
Expand Down Expand Up @@ -81,6 +83,10 @@ public class Change implements GerritJsonDTO {
* Topic name.
*/
private transient String topic;
/**
* Hashtags.
*/
private List<String> hashtags;
/**
* Change identifier.
*/
Expand Down Expand Up @@ -202,6 +208,16 @@ public void fromJson(JSONObject json) {
}
}

if (json.containsKey(HASHTAGS)) {
JSONArray tags = json.getJSONArray(HASHTAGS);
hashtags = new ArrayList<String>(tags.size());
for (int i = 0; i < tags.size(); i++) {
hashtags.add(tags.getString(i));
}
} else {
hashtags = Collections.emptyList();
}

url = getString(json, URL);
status = GerritChangeStatus.fromString(getString(json, STATUS));
wip = getBoolean(json, WIP, false);
Expand Down Expand Up @@ -283,6 +299,22 @@ public void setTopicObject(Topic topicObject) {
this.topicObject = topicObject;
}

/**
* Change hashtags.
* @return the hashtags.
*/
public List<String> getHashtags() {
return hashtags;
}

/**
* Sets the hashtags to this change.
* @param hashtags the hashtags.
*/
public void setHashtags(List<String> hashtags) {
this.hashtags = hashtags;
}

/**
* Change identifier.
* @return the identifier.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.junit.Before;
import org.junit.Test;

import java.util.Arrays;
import java.util.Date;
import java.util.concurrent.TimeUnit;

Expand All @@ -48,6 +49,7 @@
import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.CREATED_ON;
import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.LAST_UPDATED;
import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.STATUS;
import static com.sonymobile.tools.gerrit.gerritevents.dto.GerritEventKeys.HASHTAGS;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
Expand Down Expand Up @@ -208,6 +210,10 @@ public void testInitJson() throws Exception {
json.put(OWNER, jsonAccount);
json.put(STATUS, "NEW");
json.put(URL, "http://localhost:8080");
JSONArray hashtags = new JSONArray();
hashtags.add("first");
hashtags.add("second");
json.put(HASHTAGS, hashtags);
Change change = new Change(json);

assertEquals(change.getProject(), "project");
Expand All @@ -219,6 +225,7 @@ public void testInitJson() throws Exception {
assertEquals(change.getUrl(), "http://localhost:8080");
assertNull(change.getComments());
assertEquals(change.getStatus(), GerritChangeStatus.NEW);
assertEquals(change.getHashtags(), Arrays.asList("first", "second"));
}

/**
Expand Down