Merge branch 'master' into master
This commit is contained in:
commit
ddf7c3e02e
|
@ -274,6 +274,7 @@ These include:
|
|||
* gitMergedByUser
|
||||
* gitMergeRequestAssignee
|
||||
* gitlabMergeRequestLastCommit
|
||||
* gitlabMergeRequestTargetProjectId
|
||||
* gitlabTargetBranch
|
||||
* gitlabTargetRepoName
|
||||
* gitlabTargetNamespace
|
||||
|
|
|
@ -433,5 +433,9 @@ public class GitLabPushTrigger extends Trigger<Job<?, ?>> {
|
|||
String secretToken = Util.toHexString(random);
|
||||
response.setHeader("script", "document.getElementById('secretToken').value='" + secretToken + "'");
|
||||
}
|
||||
|
||||
public void doClearSecretToken(@AncestorInPath final Job<?, ?> project, StaplerResponse response) {;
|
||||
response.setHeader("script", "document.getElementById('secretToken').value=''");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ public final class CauseData {
|
|||
private final String mergeRequestState;
|
||||
private final String mergedByUser;
|
||||
private final String mergeRequestAssignee;
|
||||
private final Integer mergeRequestTargetProjectId;
|
||||
private final String targetBranch;
|
||||
private final String targetRepoName;
|
||||
private final String targetNamespace;
|
||||
|
@ -61,10 +62,10 @@ public final class CauseData {
|
|||
CauseData(ActionType actionType, Integer sourceProjectId, Integer targetProjectId, String branch, String sourceBranch, String userName,
|
||||
String userEmail, String sourceRepoHomepage, String sourceRepoName, String sourceNamespace, String sourceRepoUrl,
|
||||
String sourceRepoSshUrl, String sourceRepoHttpUrl, String mergeRequestTitle, String mergeRequestDescription, Integer mergeRequestId,
|
||||
Integer mergeRequestIid, String targetBranch, String targetRepoName, String targetNamespace, String targetRepoSshUrl,
|
||||
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) {
|
||||
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.");
|
||||
|
@ -85,6 +86,7 @@ public final class CauseData {
|
|||
this.mergeRequestState = mergeRequestState == null ? "" : mergeRequestState;
|
||||
this.mergedByUser = mergedByUser == null ? "" : mergedByUser;
|
||||
this.mergeRequestAssignee = mergeRequestAssignee == null ? "" : mergeRequestAssignee;
|
||||
this.mergeRequestTargetProjectId = mergeRequestTargetProjectId;
|
||||
this.targetBranch = checkNotNull(targetBranch, "targetBranch must not be null.");
|
||||
this.targetRepoName = checkNotNull(targetRepoName, "targetRepoName must not be null.");
|
||||
this.targetNamespace = checkNotNull(targetNamespace, "targetNamespace must not be null.");
|
||||
|
@ -124,6 +126,7 @@ public final class CauseData {
|
|||
variables.put("gitlabMergeRequestDescription", mergeRequestDescription);
|
||||
variables.put("gitlabMergeRequestId", mergeRequestId == null ? "" : mergeRequestId.toString());
|
||||
variables.put("gitlabMergeRequestIid", mergeRequestIid == null ? "" : mergeRequestIid.toString());
|
||||
variables.put("gitlabMergeRequestTargetProjectId", mergeRequestTargetProjectId == null ? "" : mergeRequestTargetProjectId.toString());
|
||||
variables.put("gitlabMergeRequestLastCommit", lastCommit);
|
||||
variables.pufIfNotNull("gitlabMergeRequestState", mergeRequestState);
|
||||
variables.pufIfNotNull("gitlabMergedByUser", mergedByUser);
|
||||
|
@ -216,6 +219,10 @@ public final class CauseData {
|
|||
return mergeRequestIid;
|
||||
}
|
||||
|
||||
public Integer getMergeRequestTargetProjectId() {
|
||||
return mergeRequestTargetProjectId;
|
||||
}
|
||||
|
||||
public String getTargetBranch() {
|
||||
return targetBranch;
|
||||
}
|
||||
|
@ -321,6 +328,7 @@ public final class CauseData {
|
|||
.append(mergeRequestState, causeData.mergeRequestState)
|
||||
.append(mergedByUser, causeData.mergedByUser)
|
||||
.append(mergeRequestAssignee, causeData.mergeRequestAssignee)
|
||||
.append(mergeRequestTargetProjectId, causeData.mergeRequestTargetProjectId)
|
||||
.append(targetBranch, causeData.targetBranch)
|
||||
.append(targetRepoName, causeData.targetRepoName)
|
||||
.append(targetNamespace, causeData.targetNamespace)
|
||||
|
@ -366,6 +374,7 @@ public final class CauseData {
|
|||
.append(mergeRequestState)
|
||||
.append(mergedByUser)
|
||||
.append(mergeRequestAssignee)
|
||||
.append(mergeRequestTargetProjectId)
|
||||
.append(targetBranch)
|
||||
.append(targetRepoName)
|
||||
.append(targetNamespace)
|
||||
|
@ -411,6 +420,7 @@ public final class CauseData {
|
|||
.append("mergeRequestState", mergeRequestState)
|
||||
.append("mergedByUser", mergedByUser)
|
||||
.append("mergeRequestAssignee", mergeRequestAssignee)
|
||||
.append("mergeRequestTargetProjectId", mergeRequestTargetProjectId)
|
||||
.append("targetBranch", targetBranch)
|
||||
.append("targetRepoName", targetRepoName)
|
||||
.append("targetNamespace", targetNamespace)
|
||||
|
|
|
@ -29,20 +29,24 @@ public class GitLabMessagePublisher extends MergeRequestNotifier {
|
|||
private boolean replaceSuccessNote = false;
|
||||
private boolean replaceFailureNote = false;
|
||||
private boolean replaceAbortNote = false;
|
||||
private boolean replaceUnstableNote = false;
|
||||
private String successNoteText;
|
||||
private String failureNoteText;
|
||||
private String abortNoteText;
|
||||
private String unstableNoteText;
|
||||
|
||||
@DataBoundConstructor
|
||||
public GitLabMessagePublisher(boolean onlyForFailure, boolean replaceSuccessNote, boolean replaceFailureNote, boolean replaceAbortNote,
|
||||
String successNoteText, String failureNoteText, String abortNoteText) {
|
||||
public GitLabMessagePublisher(boolean onlyForFailure, boolean replaceSuccessNote, boolean replaceFailureNote, boolean replaceAbortNote, boolean replaceUnstableNote,
|
||||
String successNoteText, String failureNoteText, String abortNoteText, String unstableNoteText) {
|
||||
this.onlyForFailure = onlyForFailure;
|
||||
this.replaceSuccessNote = replaceSuccessNote;
|
||||
this.replaceFailureNote = replaceFailureNote;
|
||||
this.replaceAbortNote = replaceAbortNote;
|
||||
this.replaceUnstableNote = replaceUnstableNote;
|
||||
this.successNoteText = successNoteText;
|
||||
this.failureNoteText = failureNoteText;
|
||||
this.abortNoteText = abortNoteText;
|
||||
this.unstableNoteText = unstableNoteText;
|
||||
}
|
||||
|
||||
public GitLabMessagePublisher() { }
|
||||
|
@ -63,6 +67,10 @@ public class GitLabMessagePublisher extends MergeRequestNotifier {
|
|||
return replaceAbortNote;
|
||||
}
|
||||
|
||||
public boolean isReplaceUnstableNote() {
|
||||
return replaceUnstableNote;
|
||||
}
|
||||
|
||||
public String getSuccessNoteText() {
|
||||
return this.successNoteText == null ? "" : this.successNoteText;
|
||||
}
|
||||
|
@ -75,6 +83,10 @@ public class GitLabMessagePublisher extends MergeRequestNotifier {
|
|||
return this.abortNoteText == null ? "" : this.abortNoteText;
|
||||
}
|
||||
|
||||
public String getUnstableNoteText() {
|
||||
return this.unstableNoteText == null ? "" : this.unstableNoteText;
|
||||
}
|
||||
|
||||
@Extension
|
||||
public static class DescriptorImpl extends BuildStepDescriptor<Publisher> {
|
||||
|
||||
|
@ -111,6 +123,8 @@ public class GitLabMessagePublisher extends MergeRequestNotifier {
|
|||
return ":white_check_mark:";
|
||||
} else if (result == Result.ABORTED) {
|
||||
return ":point_up:";
|
||||
} else if (result == Result.UNSTABLE) {
|
||||
return ":warning:";
|
||||
} else {
|
||||
return ":negative_squared_cross_mark:";
|
||||
}
|
||||
|
@ -151,6 +165,8 @@ public class GitLabMessagePublisher extends MergeRequestNotifier {
|
|||
message = replaceMacros(build, listener, this.getSuccessNoteText());
|
||||
} else if (this.replaceAbortNote && build.getResult() == Result.ABORTED) {
|
||||
message = replaceMacros(build, listener, this.getAbortNoteText());
|
||||
} else if (this.replaceUnstableNote && build.getResult() == Result.UNSTABLE) {
|
||||
message = replaceMacros(build, listener, this.getUnstableNoteText());
|
||||
} else if (this.replaceFailureNote && build.getResult() == Result.FAILURE) {
|
||||
message = replaceMacros(build, listener, this.getFailureNoteText());
|
||||
} else {
|
||||
|
|
|
@ -90,6 +90,7 @@ class MergeRequestHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<M
|
|||
.withMergeRequestState(hook.getObjectAttributes().getState().toString())
|
||||
.withMergedByUser(hook.getUser() == null ? null : hook.getUser().getUsername())
|
||||
.withMergeRequestAssignee(hook.getAssignee() == null ? null : hook.getAssignee().getUsername())
|
||||
.withMergeRequestTargetProjectId(hook.getObjectAttributes().getTargetProjectId())
|
||||
.withTargetBranch(hook.getObjectAttributes().getTargetBranch())
|
||||
.withTargetRepoName(hook.getObjectAttributes().getTarget().getName())
|
||||
.withTargetNamespace(hook.getObjectAttributes().getTarget().getNamespace())
|
||||
|
|
|
@ -75,6 +75,7 @@ class NoteHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<NoteHook>
|
|||
.withMergeRequestDescription(hook.getMergeRequest().getDescription())
|
||||
.withMergeRequestId(hook.getMergeRequest().getId())
|
||||
.withMergeRequestIid(hook.getMergeRequest().getIid())
|
||||
.withMergeRequestTargetProjectId(hook.getMergeRequest().getTargetProjectId())
|
||||
.withTargetBranch(hook.getMergeRequest().getTargetBranch())
|
||||
.withTargetRepoName(hook.getMergeRequest().getTarget().getName())
|
||||
.withTargetNamespace(hook.getMergeRequest().getTarget().getNamespace())
|
||||
|
|
|
@ -130,6 +130,7 @@ class OpenMergeRequestPushHookTriggerHandler implements PushHookTriggerHandler {
|
|||
.withMergeRequestDescription(mergeRequest.getDescription())
|
||||
.withMergeRequestId(mergeRequest.getId())
|
||||
.withMergeRequestIid(mergeRequest.getIid())
|
||||
.withMergeRequestTargetProjectId(mergeRequest.getTargetProjectId())
|
||||
.withTargetBranch(mergeRequest.getTargetBranch())
|
||||
.withTargetRepoName(hook.getRepository().getName())
|
||||
.withTargetNamespace(hook.getProject().getNamespace())
|
||||
|
|
|
@ -63,6 +63,7 @@ class PushHookTriggerHandlerImpl extends AbstractWebHookTriggerHandler<PushHook>
|
|||
.withMergeRequestState(null)
|
||||
.withMergedByUser("")
|
||||
.withMergeRequestAssignee("")
|
||||
.withMergeRequestTargetProjectId(null)
|
||||
.withTargetBranch(getTargetBranch(hook))
|
||||
.withTargetRepoName("")
|
||||
.withTargetNamespace("")
|
||||
|
|
|
@ -82,6 +82,7 @@
|
|||
<table>
|
||||
<f:readOnlyTextbox field="secretToken" id="secretToken"/>
|
||||
<f:validateButton title="${%Generate}" method="generateSecretToken"/>
|
||||
<f:validateButton title="${%Clear}" method="clearSecretToken"/>
|
||||
</table>
|
||||
</f:entry>
|
||||
</f:advanced>
|
||||
|
|
|
@ -20,5 +20,10 @@
|
|||
<f:textarea name="abortNoteText" field="abortNoteText"/>
|
||||
</f:entry>
|
||||
</f:optionalBlock>
|
||||
<f:optionalBlock name="replaceUnstableNote" checked="${instance.replaceUnstableNote}" title="Custom message on unstable" inline="true">
|
||||
<f:entry>
|
||||
<f:textarea name="unstableNoteText" field="unstableNoteText"/>
|
||||
</f:entry>
|
||||
</f:optionalBlock>
|
||||
</f:advanced>
|
||||
</j:jelly>
|
||||
|
|
|
@ -105,7 +105,7 @@ public class GitLabMessagePublisherTest {
|
|||
prepareSendMessageWithSuccessResponse(projectId, mergeRequestId, defaultNote)
|
||||
};
|
||||
|
||||
GitLabMessagePublisher publisher = spy(new GitLabMessagePublisher(false, false, false, false, null, null, null));
|
||||
GitLabMessagePublisher publisher = spy(new GitLabMessagePublisher(false, false, false, false, false, null, null, null, null));
|
||||
doReturn(projectId).when(publisher).getProjectId(build);
|
||||
doReturn(mergeRequestId).when(publisher).getMergeRequestId(build);
|
||||
publisher.perform(build, null, listener);
|
||||
|
@ -127,7 +127,7 @@ public class GitLabMessagePublisherTest {
|
|||
prepareSendMessageWithSuccessResponse(projectId, mergeRequestId, defaultNote)
|
||||
};
|
||||
|
||||
GitLabMessagePublisher publisher = spy(new GitLabMessagePublisher(false, false, false, false, null, null, null));
|
||||
GitLabMessagePublisher publisher = spy(new GitLabMessagePublisher(false, false, false, false, false, null, null, null, null));
|
||||
doReturn(projectId).when(publisher).getProjectId(build);
|
||||
doReturn(mergeRequestId).when(publisher).getMergeRequestId(build);
|
||||
publisher.perform(build, null, listener);
|
||||
|
@ -142,7 +142,7 @@ public class GitLabMessagePublisherTest {
|
|||
Integer mergeRequestId = 1;
|
||||
AbstractBuild build = mockBuild("/build/123", GIT_LAB_CONNECTION, Result.SUCCESS, buildNumber);
|
||||
|
||||
GitLabMessagePublisher publisher = spy(new GitLabMessagePublisher(true, false, false, false, null, null, null));
|
||||
GitLabMessagePublisher publisher = spy(new GitLabMessagePublisher(true, false, false, false, false, null, null, null, null));
|
||||
doReturn(projectId).when(publisher).getProjectId(build);
|
||||
doReturn(mergeRequestId).when(publisher).getMergeRequestId(build);
|
||||
publisher.perform(build, null, listener);
|
||||
|
@ -164,7 +164,7 @@ public class GitLabMessagePublisherTest {
|
|||
prepareSendMessageWithSuccessResponse(projectId, mergeRequestId, defaultNote)
|
||||
};
|
||||
|
||||
GitLabMessagePublisher publisher = spy(new GitLabMessagePublisher(false, false, false, false, null, null, null));
|
||||
GitLabMessagePublisher publisher = spy(new GitLabMessagePublisher(false, false, false, false, false, null, null, null, null));
|
||||
doReturn(projectId).when(publisher).getProjectId(build);
|
||||
doReturn(mergeRequestId).when(publisher).getMergeRequestId(build);
|
||||
publisher.perform(build, null, listener);
|
||||
|
@ -186,7 +186,7 @@ public class GitLabMessagePublisherTest {
|
|||
prepareSendMessageWithSuccessResponse(projectId, mergeRequestId, defaultNote)
|
||||
};
|
||||
|
||||
GitLabMessagePublisher publisher = spy(new GitLabMessagePublisher(true, false, false, false, null, null, null));
|
||||
GitLabMessagePublisher publisher = spy(new GitLabMessagePublisher(true, false, false, false, false, null, null, null, null));
|
||||
doReturn(projectId).when(publisher).getProjectId(build);
|
||||
doReturn(mergeRequestId).when(publisher).getMergeRequestId(build);
|
||||
publisher.perform(build, null, listener);
|
||||
|
@ -206,7 +206,7 @@ public class GitLabMessagePublisherTest {
|
|||
prepareSendMessageWithSuccessResponse(projectId, mergeRequestId, defaultNote)
|
||||
};
|
||||
|
||||
GitLabMessagePublisher publisher = spy(new GitLabMessagePublisher(false, false, false, true, null, null, defaultNote));
|
||||
GitLabMessagePublisher publisher = spy(new GitLabMessagePublisher(false, false, false, true, false, null, null, defaultNote, null));
|
||||
doReturn(projectId).when(publisher).getProjectId(build);
|
||||
doReturn(mergeRequestId).when(publisher).getMergeRequestId(build);
|
||||
publisher.perform(build, null, listener);
|
||||
|
@ -226,7 +226,7 @@ public class GitLabMessagePublisherTest {
|
|||
prepareSendMessageWithSuccessResponse(projectId, mergeRequestId, defaultNote)
|
||||
};
|
||||
|
||||
GitLabMessagePublisher publisher = spy(new GitLabMessagePublisher(false, true, false, false, defaultNote, null, null));
|
||||
GitLabMessagePublisher publisher = spy(new GitLabMessagePublisher(false, true, false, false, false, defaultNote, null, null, null));
|
||||
doReturn(projectId).when(publisher).getProjectId(build);
|
||||
doReturn(mergeRequestId).when(publisher).getMergeRequestId(build);
|
||||
publisher.perform(build, null, listener);
|
||||
|
@ -246,7 +246,27 @@ public class GitLabMessagePublisherTest {
|
|||
prepareSendMessageWithSuccessResponse(projectId, mergeRequestId, defaultNote)
|
||||
};
|
||||
|
||||
GitLabMessagePublisher publisher = spy(new GitLabMessagePublisher(false, false, true, false, null, defaultNote, null));
|
||||
GitLabMessagePublisher publisher = spy(new GitLabMessagePublisher(false, false, true, false, false, null, defaultNote, null, null));
|
||||
doReturn(projectId).when(publisher).getProjectId(build);
|
||||
doReturn(mergeRequestId).when(publisher).getMergeRequestId(build);
|
||||
publisher.perform(build, null, listener);
|
||||
|
||||
mockServerClient.verify(requests);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unstableWithCustomNote() throws IOException, InterruptedException {
|
||||
Integer buildNumber = 1;
|
||||
Integer projectId = 3;
|
||||
Integer mergeRequestId = 1;
|
||||
AbstractBuild build = mockBuild("/build/123", GIT_LAB_CONNECTION, Result.UNSTABLE, buildNumber);
|
||||
String defaultNote = "unstable";
|
||||
|
||||
HttpRequest[] requests = new HttpRequest[] {
|
||||
prepareSendMessageWithSuccessResponse(projectId, mergeRequestId, defaultNote)
|
||||
};
|
||||
|
||||
GitLabMessagePublisher publisher = spy(new GitLabMessagePublisher(false, false, false, false, true, null, null, null, defaultNote));
|
||||
doReturn(projectId).when(publisher).getProjectId(build);
|
||||
doReturn(mergeRequestId).when(publisher).getMergeRequestId(build);
|
||||
publisher.perform(build, null, listener);
|
||||
|
|
Loading…
Reference in New Issue