Skip to content

Commit

Permalink
Merge pull request jenkinsci#128 from illay1994/master
Browse files Browse the repository at this point in the history
Add two variable gitlabUserName and gitlabUserEmail
  • Loading branch information
omehegan committed Dec 1, 2015
2 parents adb97ff + 2c9e473 commit 258f65b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 12 deletions.
70 changes: 60 additions & 10 deletions src/main/java/com/dabsquared/gitlabjenkins/GitLabMergeRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.gitlab.api.models.GitlabCommitStatus;
import org.gitlab.api.models.GitlabMergeRequest;
import org.gitlab.api.models.GitlabProject;
import org.gitlab.api.models.GitlabUser;

/**
* Represents for WebHook payload
Expand Down Expand Up @@ -87,9 +88,9 @@ public static class ObjectAttributes {

private Integer sourceProjectId;

private Integer authorId;
private User author;

private Integer assigneeId;
private User assignee;

private String title;

Expand Down Expand Up @@ -161,20 +162,34 @@ public void setSourceProjectId(Integer sourceProjectId) {
this.sourceProjectId = sourceProjectId;
}

public Integer getAuthorId() {
return authorId;
public User getAuthor() {
return author;
}

public void setAuthorId(Integer authorId) {
this.authorId = authorId;
public void setAuthor(User author) {
this.author = author;
}

public Integer getAssigneeId() {
return assigneeId;
public void setAuthor(GitlabUser author) {
this.author = new User();
this.author.setId(author.getId());
this.author.setEmail(author.getEmail());
this.author.setName(author.getName());
}

public void setAssigneeId(Integer assigneeId) {
this.assigneeId = assigneeId;
public User getAssignee() {
return assignee;
}

public void setAssignee(User assignee) {
this.assignee = assignee;
}

public void setAssignee(GitlabUser assignee) {
this.assignee = new User();
this.assignee.setId(assignee.getId());
this.assignee.setEmail(assignee.getEmail());
this.assignee.setName(assignee.getName());
}

public String getTitle() {
Expand Down Expand Up @@ -339,5 +354,40 @@ public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
}
}
public static class User {

private Integer id;

private String name;

private String email;

public User() {
}

public Integer getId() { return id;}

public void setId(Integer id) { this.id = id; }

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
}
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/dabsquared/gitlabjenkins/GitLabPushTrigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ private Action[] createActions(GitLabPushRequest req) {
values.put("gitlabBranch", new StringParameterValue("gitlabBranch", branch));

values.put("gitlabActionType", new StringParameterValue("gitlabActionType", "PUSH"));
values.put("gitlabUserName", new StringParameterValue("gitlabUserName", req.getCommits().get(0).getAuthor().getName()));
values.put("gitlabUserEmail", new StringParameterValue("gitlabUserEmail", req.getCommits().get(0).getAuthor().getEmail()));
values.put("gitlabMergeRequestTitle", new StringParameterValue("gitlabMergeRequestTitle", ""));
values.put("gitlabMergeRequestId", new StringParameterValue("gitlabMergeRequestId", ""));
values.put("gitlabMergeRequestAssignee", new StringParameterValue("gitlabMergeRequestAssignee", ""));

LOGGER.log(Level.INFO, "Trying to get name and URL for job: {0}", job.getName());
String sourceRepoName = getDesc().getSourceRepoNameDefault(job);
Expand Down Expand Up @@ -358,6 +363,15 @@ private Action[] createActions(GitLabMergeRequest req) {
values.put("gitlabSourceBranch", new StringParameterValue("gitlabSourceBranch", getSourceBranch(req)));
values.put("gitlabTargetBranch", new StringParameterValue("gitlabTargetBranch", req.getObjectAttribute().getTargetBranch()));
values.put("gitlabActionType", new StringParameterValue("gitlabActionType", "MERGE"));
if (req.getObjectAttribute().getAuthor() != null) {
values.put("gitlabUserName", new StringParameterValue("gitlabUserName", req.getObjectAttribute().getAuthor().getName()));
values.put("gitlabUserEmail", new StringParameterValue("gitlabUserEmail", req.getObjectAttribute().getAuthor().getEmail()));
}
values.put("gitlabMergeRequestTitle", new StringParameterValue("gitlabMergeRequestTitle", req.getObjectAttribute().getTitle()));
values.put("gitlabMergeRequestId", new StringParameterValue("gitlabMergeRequestId", req.getObjectAttribute().getIid().toString()));
if (req.getObjectAttribute().getAssignee() != null) {
values.put("gitlabMergeRequestAssignee", new StringParameterValue("gitlabMergeRequestAssignee", req.getObjectAttribute().getAssignee().getName()));
}


LOGGER.log(Level.INFO, "Trying to get name and URL for job: {0}", job.getName());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/dabsquared/gitlabjenkins/GitLabWebHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,9 @@ protected void buildOpenMergeRequests(GitLabPushTrigger trigger, Integer project
newReq.setObject_kind("merge_request");
newReq.setObjectAttribute(new GitLabMergeRequest.ObjectAttributes());
if (mr.getAssignee() != null)
newReq.getObjectAttribute().setAssigneeId(mr.getAssignee().getId());
newReq.getObjectAttribute().setAssignee(mr.getAssignee());
if (mr.getAuthor() != null)
newReq.getObjectAttribute().setAuthorId(mr.getAuthor().getId());
newReq.getObjectAttribute().setAuthor(mr.getAuthor());
newReq.getObjectAttribute().setDescription(mr.getDescription());
newReq.getObjectAttribute().setId(mr.getId());
newReq.getObjectAttribute().setIid(mr.getIid());
Expand Down

0 comments on commit 258f65b

Please sign in to comment.