Skip to content

Commit

Permalink
chore: Improve JIRA cloud importer to match user by email address
Browse files Browse the repository at this point in the history
  • Loading branch information
robinshine committed Jan 17, 2025
1 parent 5a57d22 commit 5ddce2c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ImportOption implements Serializable {

private static final long serialVersionUID = 1L;

private String assigneeIssueField;
private String assigneesIssueField;

private String dueDateIssueField;

Expand All @@ -37,16 +37,16 @@ private static GlobalIssueSetting getIssueSetting() {
return OneDev.getInstance(SettingManager.class).getIssueSetting();
}

@Editable(order=350, description="Specify a user field to hold assignee information.<br>"
@Editable(order=350, description="Specify a multi-value user field to hold assignees information.<br>"
+ "<b>NOTE: </b> You may customize OneDev issue fields in case there is no appropriate option here")
@ChoiceProvider("getAssigneesIssueFieldChoices")
@NotEmpty
public String getAssigneeIssueField() {
return assigneeIssueField;
public String getAssigneesIssueField() {
return assigneesIssueField;
}

public void setAssigneeIssueField(String assigneeIssueField) {
this.assigneeIssueField = assigneeIssueField;
public void setAssigneesIssueField(String assigneesIssueField) {
this.assigneesIssueField = assigneesIssueField;
}

@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,20 @@ private Long getUserId(Map<String, Optional<Long>> userIds, JsonNode userNode, T
String accountId = userNode.get("accountId").asText();
Optional<Long> userIdOpt = userIds.get(accountId);
if (userIdOpt == null) {
String displayName = null;
if (userNode.hasNonNull("displayName"))
displayName = userNode.get("displayName").asText(null);
if (displayName != null)
userIdOpt = Optional.ofNullable(User.idOf(OneDev.getInstance(UserManager.class).findByFullName(displayName)));
else
userIdOpt = Optional.empty();
String emailAddress = null;
if (userNode.hasNonNull("emailAddress"))
emailAddress = userNode.get("emailAddress").asText(null);
if (emailAddress != null) {
userIdOpt = Optional.ofNullable(User.idOf(OneDev.getInstance(UserManager.class).findByVerifiedEmailAddress(emailAddress)));
} else {
String displayName = null;
if (userNode.hasNonNull("displayName"))
displayName = userNode.get("displayName").asText(null);
if (displayName != null)
userIdOpt = Optional.ofNullable(User.idOf(OneDev.getInstance(UserManager.class).findByFullName(displayName)));
else
userIdOpt = Optional.empty();
}
userIds.put(accountId, userIdOpt);
}
return userIdOpt.orElse(null);
Expand Down Expand Up @@ -608,7 +615,7 @@ public void consume(List<JsonNode> pageData) throws InterruptedException {
JsonNode assigneeNode = fieldsNode.get("assignee");
IssueField assigneeField = new IssueField();
assigneeField.setIssue(issue);
assigneeField.setName(option.getAssigneeIssueField());
assigneeField.setName(option.getAssigneesIssueField());
assigneeField.setType(InputSpec.USER);

Long userId = getUserId(userIds, assigneeNode, logger);
Expand Down

0 comments on commit 5ddce2c

Please sign in to comment.