Skip to content

Commit

Permalink
Add comment author to CauseData for Note events (#1372)
Browse files Browse the repository at this point in the history
Co-authored-by: Bruno Verachten <gounthar@gmail.com>
Co-authored-by: Kris Stern <krisstern@outlook.com>
  • Loading branch information
3 people authored Jan 31, 2023
1 parent b26083a commit ef3356d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/java/com/dabsquared/gitlabjenkins/cause/CauseData.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public final class CauseData {
private final String createdAt;
private final String finishedAt;
private final String buildDuration;
private final String commentAuthor;

@GeneratePojoBuilder(withFactoryMethod = "*")
CauseData(ActionType actionType, Integer sourceProjectId, Integer targetProjectId, String branch, String sourceBranch, String userName,
Expand All @@ -68,7 +69,7 @@ public final class CauseData {
Integer mergeRequestIid, Integer mergeRequestTargetProjectId, String targetBranch, String targetRepoName, String targetNamespace, String targetRepoSshUrl,
String targetRepoHttpUrl, String triggeredByUser, String before, String after, String lastCommit, String targetProjectUrl,
String triggerPhrase, String mergeRequestState, String mergedByUser, String mergeRequestAssignee, String ref, String isTag,
String sha, String beforeSha, String status, String stages, String createdAt, String finishedAt, String buildDuration) {
String sha, String beforeSha, String status, String stages, String createdAt, String finishedAt, String buildDuration, String commentAuthor) {
this.actionType = Objects.requireNonNull(actionType, "actionType must not be null.");
this.sourceProjectId = Objects.requireNonNull(sourceProjectId, "sourceProjectId must not be null.");
this.targetProjectId = Objects.requireNonNull(targetProjectId, "targetProjectId must not be null.");
Expand Down Expand Up @@ -111,6 +112,7 @@ public final class CauseData {
this.createdAt = createdAt;
this.finishedAt = finishedAt;
this.buildDuration = buildDuration;
this.commentAuthor = commentAuthor;
}

@Exported
Expand Down Expand Up @@ -144,6 +146,7 @@ public Map<String, String> getBuildVariables() {
variables.put("gitlabTargetRepoHttpUrl", targetRepoHttpUrl);
variables.put("gitlabBefore", before);
variables.put("gitlabAfter", after);
variables.putIfNotNull("gitlabCommentAuthor", commentAuthor);
variables.put("ref", ref);
variables.put("beforeSha", beforeSha);
variables.put("isTag", isTag);
Expand Down Expand Up @@ -329,6 +332,9 @@ public String getTargetProjectUrl() {
@Exported
public String getBuildDuration() { return buildDuration; }

@Exported
public String getCommentAuthor() { return commentAuthor; }


String getShortDescription() {
return actionType.getShortDescription(this);
Expand Down Expand Up @@ -410,6 +416,7 @@ public boolean equals(Object o) {
.append(createdAt, causeData.getCreatedAt())
.append(finishedAt, causeData.getFinishedAt())
.append(buildDuration, causeData.getBuildDuration())
.append(commentAuthor, causeData.getCommentAuthor())
.isEquals();
}

Expand Down Expand Up @@ -457,6 +464,7 @@ public int hashCode() {
.append(createdAt)
.append(finishedAt)
.append(buildDuration)
.append(commentAuthor)
.toHashCode();
}

Expand Down Expand Up @@ -504,6 +512,7 @@ public String toString() {
.append("createdAt", createdAt)
.append("finishedAt", finishedAt)
.append("duration", buildDuration)
.append("commentAuthor", commentAuthor)
.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ protected CauseData retrieveCauseData(NoteHook hook) {
.withLastCommit(hook.getMergeRequest().getLastCommit().getId())
.withTargetProjectUrl(hook.getMergeRequest().getTarget().getWebUrl())
.withTriggerPhrase(hook.getObjectAttributes().getNote())
.withCommentAuthor(hook.getUser() == null ? null : hook.getUser().getUsername())
.build();
}

Expand Down

0 comments on commit ef3356d

Please sign in to comment.