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

WIP: Export MR labels as build variable #646

Closed
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 @@ -58,6 +58,7 @@ public final class CauseData {
private final String createdAt;
private final String finishedAt;
private final String buildDuration;
private final List<String> labels;

@GeneratePojoBuilder(withFactoryMethod = "*")
CauseData(ActionType actionType, Integer sourceProjectId, Integer targetProjectId, String branch, String sourceBranch, String userName,
Expand All @@ -66,7 +67,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, List<String> labels) {
this.actionType = checkNotNull(actionType, "actionType must not be null.");
this.sourceProjectId = checkNotNull(sourceProjectId, "sourceProjectId must not be null.");
this.targetProjectId = checkNotNull(targetProjectId, "targetProjectId must not be null.");
Expand Down Expand Up @@ -108,6 +109,7 @@ public final class CauseData {
this.createdAt = createdAt;
this.finishedAt = finishedAt;
this.buildDuration = buildDuration;
this.labels = labels;
}

public Map<String, String> getBuildVariables() {
Expand Down Expand Up @@ -149,6 +151,7 @@ public Map<String, String> getBuildVariables() {
variables.put("finishedAt", finishedAt);
variables.put("duration", buildDuration);
variables.putIfNotNull("gitlabTriggerPhrase", triggerPhrase);
if (labels != null) variables.put("gitlabLabels", StringUtils.join(labels,' '));
return variables;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ protected CauseData retrieveCauseData(MergeRequestHook hook) {
.withTriggeredByUser(hook.getObjectAttributes().getLastCommit().getAuthor().getName())
.withLastCommit(hook.getObjectAttributes().getLastCommit().getId())
.withTargetProjectUrl(hook.getObjectAttributes().getTarget().getWebUrl())
.withLabels(hook.getObjectAttributes().getLabels())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ protected CauseData retrieveCauseData(NoteHook hook) {
.withLastCommit(hook.getMergeRequest().getLastCommit().getId())
.withTargetProjectUrl(hook.getMergeRequest().getTarget().getWebUrl())
.withTriggerPhrase(hook.getObjectAttributes().getNote())
.withLabels(hook.getMergeRequest().getLabels())
.build();
}

Expand Down