private JsonObject createCommitAttachment(SRunningBuild build) { List<SVcsModification> changes = build.getChanges(SelectPrevBuildPolicy.SINCE_LAST_SUCCESSFULLY_FINISHED_BUILD, true); StringBuilder commitMessage = new StringBuilder(); /* * If this field starts to feel too long in slack, we should only use the first item in the array, which would be the latest change * */ for ( int i = 0 ; i < changes.size() ; i++ ){ SVcsModification modification = changes.get(i); String desc = modification.getDescription(); commitMessage.append("‣ "); commitMessage.append(desc); if( i < changes.size() - 1 ) { commitMessage.append("\n"); } } if (changes.size() < 1) { return null; } String commitMessageString = commitMessage.toString(); JsonObject attachment = new JsonObject(); attachment.addProperty("title", "Commit Messages"); attachment.addProperty("fallback" , commitMessageString); attachment.addProperty("text" , commitMessageString); attachment.addProperty("color" , "#2FA8B9"); return attachment; }
public void populateCommits(SRunningBuild sRunningBuild) { List<SVcsModification> changes = sRunningBuild.getContainingChanges(); if (changes == null) { return; } for (SVcsModification change : changes) { Collection<SUser> committers = change.getCommitters(); String slackUserId = null; if (!committers.isEmpty()) { SUser committer = committers.iterator().next(); slackUserId = committer.getPropertyValue(SlackNotificator.USERID_KEY); Loggers.ACTIVITIES.debug("Resolved committer " + change.getUserName() + " to Slack User " + slackUserId); } commits.add(new Commit(change.getVersion(), change.getDescription(), change.getUserName(), slackUserId)); } }
public static WebHooksChange build(SVcsModification modification) { WebHooksChange change = new WebHooksChange(); change.setComment(modification.getDescription()); change.setUsername(modification.getUserName()); change.setVcsRoot(modification.getVcsRoot().getName()); for (VcsFileModification fileModification: modification.getChanges()){ change.files.add(fileModification.getRelativeFileName()); } return change; }