Skip to content

Commit

Permalink
Merge pull request #156 from A4Vision/master
Browse files Browse the repository at this point in the history
Refactor SlackNotificationPayloadContent - extract delegate class
  • Loading branch information
marvin-w authored May 22, 2018
2 parents ac76dda + a6968d7 commit cebcc50
Show file tree
Hide file tree
Showing 2 changed files with 251 additions and 231 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package slacknotifications.teamcity.payload.content;

import jetbrains.buildServer.serverSide.SRunningBuild;
import jetbrains.buildServer.users.SUser;
import jetbrains.buildServer.vcs.SVcsModification;
import slacknotifications.teamcity.Loggers;
import slacknotifications.teamcity.SlackNotificator;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class PayloadContentCommits {
private List<Commit> commits;

public PayloadContentCommits() {
commits = new ArrayList<Commit>();
}

public void populateCommits(SRunningBuild sRunningBuild) {
List<SVcsModification> changes = sRunningBuild.getContainingChanges();
if (changes == null) {
return;
}

for (SVcsModification change : changes) {
Collection<SUser> committers = change.getCommitters();
String slackUserName = null;
if (committers != null && !committers.isEmpty()) {
SUser committer = committers.iterator().next();
slackUserName = committer.getPropertyValue(SlackNotificator.USERNAME_KEY);
Loggers.ACTIVITIES.debug("Resolved committer " + change.getUserName() + " to Slack User " + slackUserName);
}
commits.add(new Commit(change.getVersion(), change.getDescription(), change.getUserName(), slackUserName));
}
}

public List<Commit> getCommits() {
return commits;
}

public void setCommits(List<Commit> commits) {
this.commits = commits;
}
}
Loading

0 comments on commit cebcc50

Please sign in to comment.