Skip to content

Commit

Permalink
Merge pull request jenkinsci#129 from TomAndrews/merge-request-fixes
Browse files Browse the repository at this point in the history
Assorted minor fixes for merge requests
  • Loading branch information
omehegan committed Dec 1, 2015
2 parents bad5130 + 6e3b157 commit adb97ff
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/main/java/com/dabsquared/gitlabjenkins/GitLabWebHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,7 @@ public void generatePushBuild(String json, Job project, StaplerRequest req, Stap
protected void buildOpenMergeRequests(GitLabPushTrigger trigger, Integer projectId, String projectRef) {
try {
GitLab api = new GitLab();
// TODO Replace this with a call to GitlabAPI.getOpenMergeRequests, once timols has deployed version 1.1.7
String tailUrl = GitlabProject.URL + "/" + projectId + GitlabMergeRequest.URL + "?state=opened&per_page=100";
List<GitlabMergeRequest> mergeRequests = api.instance().retrieve().getAll(tailUrl, GitlabMergeRequest[].class);
List<GitlabMergeRequest> mergeRequests = api.instance().getOpenMergeRequests(projectId);

for (org.gitlab.api.models.GitlabMergeRequest mr : mergeRequests) {
if (projectRef.endsWith(mr.getSourceBranch()) ||
Expand All @@ -419,8 +417,8 @@ protected void buildOpenMergeRequests(GitLabPushTrigger trigger, Integer project
+ mr.getSourceBranch() + "\n target: "
+ mr.getTargetBranch() + "\n state: "
+ mr.getState() + "\n assign: "
+ mr.getAssignee() + "\n author: "
+ mr.getAuthor() + "\n id: "
+ mr.getAssignee().getName() + "\n author: "
+ mr.getAuthor().getName() + "\n id: "
+ mr.getId() + "\n iid: "
+ mr.getIid() + "\n last commit: "
+ lastCommit.getId() + "\n\n");
Expand Down Expand Up @@ -479,10 +477,6 @@ public void generateMergeRequestBuild(String json, Job project, StaplerRequest r
return;
}
}
if(request.getObjectAttribute().getDescription().contains("[ci-skip]")) {
LOGGER.log(Level.INFO, "Skipping MR " + request.getObjectAttribute().getTitle() + " due to ci-skip.");
return;
}

Authentication old = SecurityContextHolder.getContext().getAuthentication();
SecurityContextHolder.getContext().setAuthentication(ACL.SYSTEM);
Expand All @@ -499,6 +493,12 @@ public void generateMergeRequestBuild(String json, Job project, StaplerRequest r
if (trigger == null) {
return;
}

if(trigger.getCiSkip() && request.getObjectAttribute().getDescription().contains("[ci-skip]")) {
LOGGER.log(Level.INFO, "Skipping MR " + request.getObjectAttribute().getTitle() + " due to ci-skip.");
return;
}

trigger.onPost(request);
} finally {
SecurityContextHolder.getContext().setAuthentication(old);
Expand Down

0 comments on commit adb97ff

Please sign in to comment.