Skip to content
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 @@ -81,6 +81,7 @@ public class GitLabPushTrigger extends Trigger<Job<?, ?>> implements MergeReques
private boolean triggerOnMergeRequest = true;
private boolean triggerOnlyIfNewCommitsPushed = false;
private boolean triggerOnPipelineEvent = false;
private boolean triggerOnFailedPipelineEvent = false;
private boolean triggerOnAcceptedMergeRequest = false;
private boolean triggerOnClosedMergeRequest = false;
private boolean triggerOnApprovedMergeRequest = false;
Expand Down Expand Up @@ -512,6 +513,15 @@ public void setTriggerOnPipelineEvent(boolean triggerOnPipelineEvent) {
this.triggerOnPipelineEvent = triggerOnPipelineEvent;
}

public boolean getTriggerOnFailedPipelineEvent() {
return triggerOnFailedPipelineEvent;
}

@DataBoundSetter
public void setTriggerOnFailedPipelineEvent(boolean triggerOnFailedPipelineEvent) {
this.triggerOnFailedPipelineEvent = triggerOnFailedPipelineEvent;
}

@DataBoundSetter
public void setPendingBuildName(String pendingBuildName) {
this.pendingBuildName = pendingBuildName;
Expand Down Expand Up @@ -588,7 +598,7 @@ private void initializeTriggerHandler() {
triggerToBranchDeleteRequest,
triggerOpenMergeRequestOnPush,
skipWorkInProgressMergeRequest);
pipelineTriggerHandler = newPipelineHookTriggerHandler(triggerOnPipelineEvent);
pipelineTriggerHandler = newPipelineHookTriggerHandler(triggerOnPipelineEvent, triggerOnFailedPipelineEvent);
}

private void initializeBranchFilter() {
Expand Down
134 changes: 133 additions & 1 deletion src/main/java/com/dabsquared/gitlabjenkins/cause/CauseData.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ public final class CauseData {
private final String finishedAt;
private final String buildDuration;
private final String commentAuthor;
private final Integer pipelineId;
private final Integer pipelineIid;
private final String pipelineSource;
private final String pipelineUrl;
private final String commitMessage;
private final String commitTitle;
private final String commitAuthorName;
private final String commitAuthorEmail;
private final String commitUrl;
private final String projectWebUrl;
private final String projectPathWithNamespace;

@GeneratePojoBuilder(withFactoryMethod = "*")
CauseData(
Expand Down Expand Up @@ -109,7 +120,18 @@ public final class CauseData {
String createdAt,
String finishedAt,
String buildDuration,
String commentAuthor) {
String commentAuthor,
Integer pipelineId,
Integer pipelineIid,
String pipelineSource,
String pipelineUrl,
String commitMessage,
String commitTitle,
String commitAuthorName,
String commitAuthorEmail,
String commitUrl,
String projectWebUrl,
String projectPathWithNamespace) {
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 @@ -155,6 +177,17 @@ public final class CauseData {
this.finishedAt = finishedAt;
this.buildDuration = buildDuration;
this.commentAuthor = commentAuthor;
this.pipelineId = pipelineId;
this.pipelineIid = pipelineIid;
this.pipelineSource = pipelineSource;
this.pipelineUrl = pipelineUrl;
this.commitMessage = commitMessage;
this.commitTitle = commitTitle;
this.commitAuthorName = commitAuthorName;
this.commitAuthorEmail = commitAuthorEmail;
this.commitUrl = commitUrl;
this.projectWebUrl = projectWebUrl;
this.projectPathWithNamespace = projectPathWithNamespace;
}

@Exported
Expand Down Expand Up @@ -205,6 +238,17 @@ public Map<String, String> getBuildVariables() {
variables.put("finishedAt", finishedAt);
variables.put("duration", buildDuration);
variables.putIfNotNull("gitlabTriggerPhrase", triggerPhrase);
variables.putIfNotNull("gitlabPipelineId", pipelineId == null ? null : pipelineId.toString());
variables.putIfNotNull("gitlabPipelineIid", pipelineIid == null ? null : pipelineIid.toString());
variables.putIfNotNull("gitlabPipelineSource", pipelineSource);
variables.putIfNotNull("gitlabPipelineUrl", pipelineUrl);
variables.putIfNotNull("gitlabCommitMessage", commitMessage);
variables.putIfNotNull("gitlabCommitTitle", commitTitle);
variables.putIfNotNull("gitlabCommitAuthorName", commitAuthorName);
variables.putIfNotNull("gitlabCommitAuthorEmail", commitAuthorEmail);
variables.putIfNotNull("gitlabCommitUrl", commitUrl);
variables.putIfNotNull("gitlabProjectWebUrl", projectWebUrl);
variables.putIfNotNull("gitlabProjectPathWithNamespace", projectPathWithNamespace);
return variables;
}

Expand Down Expand Up @@ -413,6 +457,61 @@ public String getCommentAuthor() {
return commentAuthor;
}

@Exported
public Integer getPipelineId() {
return pipelineId;
}

@Exported
public Integer getPipelineIid() {
return pipelineIid;
}

@Exported
public String getPipelineSource() {
return pipelineSource;
}

@Exported
public String getPipelineUrl() {
return pipelineUrl;
}

@Exported
public String getCommitMessage() {
return commitMessage;
}

@Exported
public String getCommitTitle() {
return commitTitle;
}

@Exported
public String getCommitAuthorName() {
return commitAuthorName;
}

@Exported
public String getCommitAuthorEmail() {
return commitAuthorEmail;
}

@Exported
public String getCommitUrl() {
return commitUrl;
}

@Exported
public String getProjectWebUrl() {
return projectWebUrl;
}

@Exported
public String getProjectPathWithNamespace() {
return projectPathWithNamespace;
}

String getShortDescription() {
return actionType.getShortDescription(this);
}
Expand Down Expand Up @@ -505,6 +604,17 @@ public boolean equals(Object o) {
.append(finishedAt, causeData.getFinishedAt())
.append(buildDuration, causeData.getBuildDuration())
.append(commentAuthor, causeData.getCommentAuthor())
.append(pipelineId, causeData.getPipelineId())
.append(pipelineIid, causeData.getPipelineIid())
.append(pipelineSource, causeData.getPipelineSource())
.append(pipelineUrl, causeData.getPipelineUrl())
.append(commitMessage, causeData.getCommitMessage())
.append(commitTitle, causeData.getCommitTitle())
.append(commitAuthorName, causeData.getCommitAuthorName())
.append(commitAuthorEmail, causeData.getCommitAuthorEmail())
.append(commitUrl, causeData.getCommitUrl())
.append(projectWebUrl, causeData.getProjectWebUrl())
.append(projectPathWithNamespace, causeData.getProjectPathWithNamespace())
.isEquals();
}

Expand Down Expand Up @@ -555,6 +665,17 @@ public int hashCode() {
.append(finishedAt)
.append(buildDuration)
.append(commentAuthor)
.append(pipelineId)
.append(pipelineIid)
.append(pipelineSource)
.append(pipelineUrl)
.append(commitMessage)
.append(commitTitle)
.append(commitAuthorName)
.append(commitAuthorEmail)
.append(commitUrl)
.append(projectWebUrl)
.append(projectPathWithNamespace)
.toHashCode();
}

Expand Down Expand Up @@ -605,6 +726,17 @@ public String toString() {
.append("finishedAt", finishedAt)
.append("duration", buildDuration)
.append("commentAuthor", commentAuthor)
.append("pipelineId", pipelineId)
.append("pipelineIid", pipelineIid)
.append("pipelineSource", pipelineSource)
.append("pipelineUrl", pipelineUrl)
.append("commitMessage", commitMessage)
.append("commitTitle", commitTitle)
.append("commitAuthorName", commitAuthorName)
.append("commitAuthorEmail", commitAuthorEmail)
.append("commitUrl", commitUrl)
.append("projectWebUrl", projectWebUrl)
.append("projectPathWithNamespace", projectPathWithNamespace)
.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,6 @@ void changeBuildStatus(
List<Label> getLabels(String projectId);

List<Pipeline> getPipelines(String projectName);

List<MergeRequest> getCommitMergeRequests(String projectId, String sha);
}
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,16 @@ List<Pipeline> execute(GitLabClient client) {
});
}

@Override
public List<MergeRequest> getCommitMergeRequests(final String projectId, final String sha) {
return execute(new GitLabOperation<List<MergeRequest>>() {
@Override
List<MergeRequest> execute(GitLabClient client) {
return client.getCommitMergeRequests(projectId, sha);
}
});
}

private GitLabClient delegate(boolean reset) {
if (reset || delegate == null) {
delegate = autodetectOrDie();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,6 @@ void acceptMergeRequest(
List<Label> getLabels(String projectId);

List<Pipeline> getPipelines(String projectName);

List<MergeRequest> getCommitMergeRequests(String projectId, String sha);
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,9 @@ public List<Label> getLabels(String projectId) {
public List<Pipeline> getPipelines(String projectName) {
return api.getPipelines(projectName);
}

@Override
public List<MergeRequest> getCommitMergeRequests(String projectId, String sha) {
return api.getCommitMergeRequests(projectId, sha);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,11 @@ User updateUser(
@Path("/projects/{projectId}/pipelines")
@Override
List<Pipeline> getPipelines(@PathParam("projectId") @Encoded String projectId);

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/projects/{projectId}/repository/commits/{sha}/merge_requests")
@Override
List<MergeRequest> getCommitMergeRequests(
@PathParam("projectId") @Encoded String projectId, @PathParam("sha") @Encoded String sha);
}
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,11 @@ User updateUser(
@Path("/projects/{projectId}/pipelines")
@Override
List<Pipeline> getPipelines(@PathParam("projectId") @Encoded String projectId);

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/projects/{projectId}/repository/commits/{sha}/merge_requests")
@Override
List<MergeRequest> getCommitMergeRequests(
@PathParam("projectId") @Encoded String projectId, @PathParam("sha") @Encoded String sha);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class Commit {

private String id;
private String message;
private String title;
private Date timestamp;
private String url;
private User author;
Expand All @@ -38,6 +39,14 @@ public void setMessage(String message) {
this.message = message;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public Date getTimestamp() {
return timestamp;
}
Expand Down
Loading