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

Support gitlab trigger comments contains gitlabNote to the build env. #223

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -31,6 +31,7 @@ public void buildEnvironmentFor(@Nonnull Run r, @Nonnull EnvVars envs,
variables.put("gitlabSourceProjectId", cause.getSourceProjectId()+"");
variables.put("gitlabTargetProjectId", cause.getTargetProjectId()+"");
variables.put("gitlabLastCommitId", cause.getLastCommitId());
variables.put("gitlabNote", cause.getNote());
envs.overrideAll(variables);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public QueueTaskFuture<?> startJob(GitlabCause cause) {
values.put("gitlabTargetBranch", new StringParameterValue("gitlabTargetBranch", cause.getTargetBranch()));
values.put("gitlabTitle", new StringParameterValue("gitlabTitle", cause.getTitle()));
values.put("gitlabDescription", new StringParameterValue("gitlabDescription", cause.getDescription()));
values.put("gitlabNote", new StringParameterValue("gitlabNote", cause.getNote()));
for (Map.Entry<String, String> entry : cause.getCustomParameters().entrySet()) {
values.put(entry.getKey(), new StringParameterValue(entry.getKey(), entry.getValue()));
}
Expand Down Expand Up @@ -240,7 +241,7 @@ public boolean isApplicable(Item item) {

@Override
public String getDisplayName() {
return "Gitlab Merge Requests Builder";
return "JD Gitlab Merge Requests Builder(V1.0)";
}

@Override
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/jenkinsci/plugins/gitlab/GitlabBuilds.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public GitlabBuilds(GitlabBuildTrigger trigger, GitlabRepository repository) {
public String build(GitlabCause cause, Map<String, String> customParameters, GitlabProject project, GitlabMergeRequest mergeRequest) throws IOException {

boolean shouldRun = true;
boolean shouldRunCauseByNote = false;
GitlabAPI api = trigger.getBuilder().getGitlab().get();
String triggerComment = trigger.getTriggerComment();
GitlabNote lastNote = getLastNote(mergeRequest, api);
Expand All @@ -55,9 +56,11 @@ public String build(GitlabCause cause, Map<String, String> customParameters, Git
shouldRun = false;
}

if (lastNote != null && lastNote.getBody().equals(triggerComment)) {
if (lastNote != null && lastNote.getBody().startsWith(triggerComment)) {
LOGGER.info("Trigger comment found");
shouldRun = true;
shouldRunCauseByNote = true;
cause.setNote(lastNote.getBody().replace(triggerComment, "").trim());
}

if (shouldRun) {
Expand All @@ -78,7 +81,7 @@ public String build(GitlabCause cause, Map<String, String> customParameters, Git
}

if (shouldRun) {
if (isWorkInProgress(mergeRequest.getTitle())) {
if (!shouldRunCauseByNote && isWorkInProgress(mergeRequest.getTitle())) {
shouldRun = false;
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/jenkinsci/plugins/gitlab/GitlabCause.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class GitlabCause extends Cause {
private final Integer sourceProjectId;
private final Integer targetProjectId;
private final String lastCommitId;
private String note;

public GitlabCause(Integer mergeRequestId,
Integer mergeRequestIid,
Expand Down Expand Up @@ -94,7 +95,15 @@ public Integer getTargetProjectId() {
return targetProjectId;
}

public String getLastCommitId() {
public String getLastCommitId() {
return lastCommitId;
}

public void setNote(String note) {
this.note = note;
}

public String getNote() {
return note;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,16 @@ public void check(GitlabMergeRequest gitlabMergeRequest) {
sourceBranch = gitlabMergeRequest.getSourceBranch();
}

// force to get new title.
title = gitlabMergeRequest.getTitle();
if (title == null || title.trim().isEmpty()) {
title = gitlabMergeRequest.getTitle();

// title = gitlabMergeRequest.getTitle();
if (title == null) { title = ""; }
}

description = gitlabMergeRequest.getDescription();
if (description == null || description.trim().isEmpty()) {
description = gitlabMergeRequest.getDescription();

// description = gitlabMergeRequest.getDescription();
if (description == null) { description = ""; }
}

Expand Down