Skip to content

Commit 6bbcf5d

Browse files
authored
Merge pull request #155 from 2m0nd/master
Add "Who triggered build" info, add settings enable/disable this info
2 parents affbcd8 + 9d78eea commit 6bbcf5d

File tree

20 files changed

+114
-11
lines changed

20 files changed

+114
-11
lines changed

pom.xml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<teamcity-version>9.1.7</teamcity-version>
88
<majorVersion>1</majorVersion>
99
<minorVersion>4</minorVersion>
10-
<patchVersion>6</patchVersion>
10+
<patchVersion>7</patchVersion>
1111
<currentVersion>${majorVersion}.${minorVersion}.${patchVersion}</currentVersion>
1212
</properties>
1313
<version>${currentVersion}</version>
@@ -43,6 +43,19 @@
4343
</plugins>
4444
</pluginManagement>
4545
<plugins>
46+
<plugin>
47+
<artifactId>maven-clean-plugin</artifactId>
48+
<version>3.1.0</version>
49+
<executions>
50+
<execution>
51+
<id>auto-clean</id>
52+
<phase>initialize</phase>
53+
<goals>
54+
<goal>clean</goal>
55+
</goals>
56+
</execution>
57+
</executions>
58+
</plugin>
4659
<plugin>
4760
<groupId>org.apache.maven.plugins</groupId>
4861
<artifactId>maven-compiler-plugin</artifactId>

tcslackbuildnotifier-core/src/main/java/slacknotifications/SlackNotification.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ public interface SlackNotification {
102102
public abstract void setShowCommits(boolean showCommits);
103103

104104
public abstract void setShowCommitters(boolean showCommitters);
105+
106+
public abstract void setShowTriggeredBy(boolean showTriggeredBy);
105107

106108
public abstract void setMaxCommitsToDisplay(int maxCommitsToDisplay);
107109

tcslackbuildnotifier-core/src/main/java/slacknotifications/SlackNotificationImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public class SlackNotificationImpl implements SlackNotification {
6565
private Boolean showElapsedBuildTime;
6666
private boolean showCommits;
6767
private boolean showCommitters;
68+
private boolean showTriggeredBy;
6869
private int maxCommitsToDisplay;
6970
private boolean mentionChannelEnabled;
7071
private boolean mentionSlackUserEnabled;
@@ -347,6 +348,10 @@ private List<Attachment> getAttachments() {
347348
attachment.addField("Changes By", committersString, false);
348349
}
349350
}
351+
352+
if (showTriggeredBy){
353+
attachment.addField("Triggered By", this.payload.getTriggeredBy(), false);
354+
}
350355

351356
// Mention the channel and/or the Slack Username of any committers if known
352357
if(payload.getIsFirstFailedBuild()
@@ -635,6 +640,11 @@ public void setShowCommitters(boolean showCommitters) {
635640
this.showCommitters = showCommitters;
636641
}
637642

643+
@Override
644+
public void setShowTriggeredBy(boolean showTriggeredBy) {
645+
this.showTriggeredBy = showTriggeredBy;
646+
}
647+
638648
@Override
639649
public void setMaxCommitsToDisplay(int maxCommitsToDisplay) {
640650
this.maxCommitsToDisplay = maxCommitsToDisplay;

tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/SlackNotificationListener.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public void getFromConfig(SlackNotification slackNotification, SlackNotification
7676
slackNotification.setShowElapsedBuildTime(myMainSettings.getShowElapsedBuildTime());
7777
slackNotification.setShowCommits(myMainSettings.getShowCommits());
7878
slackNotification.setShowCommitters(myMainSettings.getShowCommitters());
79+
slackNotification.setShowTriggeredBy(myMainSettings.getShowTriggeredBy());
7980
slackNotification.setShowFailureReason(myMainSettings.getShowFailureReason() == null ? SlackNotificationContentConfig.DEFAULT_SHOW_FAILURE_REASON : myMainSettings.getShowFailureReason());
8081
slackNotification.setMaxCommitsToDisplay(myMainSettings.getMaxCommitsToDisplay());
8182
slackNotification.setMentionChannelEnabled(slackNotificationConfig.getMentionChannelEnabled());
@@ -90,6 +91,7 @@ public void getFromConfig(SlackNotification slackNotification, SlackNotification
9091
slackNotification.setShowElapsedBuildTime(slackNotificationConfig.getContent().getShowElapsedBuildTime());
9192
slackNotification.setShowCommits(slackNotificationConfig.getContent().getShowCommits());
9293
slackNotification.setShowCommitters(slackNotificationConfig.getContent().getShowCommitters());
94+
slackNotification.setShowTriggeredBy(slackNotificationConfig.getContent().getShowTriggeredBy());
9395
slackNotification.setShowFailureReason(slackNotificationConfig.getContent().getShowFailureReason() == null ? SlackNotificationContentConfig.DEFAULT_SHOW_FAILURE_REASON : slackNotificationConfig.getContent().getShowFailureReason());
9496
}
9597
Loggers.ACTIVITIES.debug("SlackNotificationListener :: SlackNotification proxy set to "

tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/payload/content/SlackNotificationPayloadContent.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ private void populateCommonContent(SBuildServer server, SRunningBuild sRunningBu
198198
setBuildResult(sRunningBuild, previousBuild, buildState);
199199
setBuildFullName(sRunningBuild.getBuildType().getFullName());
200200
setBuildName(sRunningBuild.getBuildType().getName());
201+
setTriggeredBy(sRunningBuild.getTriggeredBy().getAsString());
201202
setBuildId(Long.toString(sRunningBuild.getBuildId()));
202203
setBuildTypeId(TeamCityIdResolver.getBuildTypeId(sRunningBuild.getBuildType()));
203204
setAgentName(sRunningBuild.getAgentName());
@@ -329,6 +330,14 @@ public void setBuildName(String buildName) {
329330
this.buildName = buildName;
330331
}
331332

333+
public String getTriggeredBy() {
334+
return triggeredBy;
335+
}
336+
337+
public void setTriggeredBy(String triggeredBy) {
338+
this.triggeredBy = triggeredBy;
339+
}
340+
332341
public String getBuildId() {
333342
return buildId;
334343
}

tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/settings/SlackNotificationConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class SlackNotificationConfig {
3434
private static final String SHOW_BUILD_AGENT = "showBuildAgent";
3535
private static final String SHOW_COMMITS = "showCommits";
3636
private static final String SHOW_COMMITTERS = "showCommitters";
37+
private static final String SHOW_TRIGGERED_BY = "showTriggeredBy";
3738
private static final String MAX_COMMITS_TO_DISPLAY = "maxCommitsToDisplay";
3839
private static final String SHOW_FAILURE_REASON = "showFailureReason";
3940

@@ -180,6 +181,9 @@ public SlackNotificationConfig(Element e) {
180181
}
181182
if (eContent.getAttribute(SHOW_COMMITTERS) != null){
182183
this.content.setShowCommitters(Boolean.parseBoolean(eContent.getAttributeValue(SHOW_COMMITTERS)));
184+
}
185+
if (eContent.getAttribute(SHOW_TRIGGERED_BY) != null){
186+
this.content.setShowTriggeredBy(Boolean.parseBoolean(eContent.getAttributeValue(SHOW_TRIGGERED_BY)));
183187
}
184188
if (eContent.getAttribute(MAX_COMMITS_TO_DISPLAY) != null){
185189
this.content.setMaxCommitsToDisplay(Integer.parseInt(eContent.getAttributeValue(MAX_COMMITS_TO_DISPLAY)));
@@ -288,6 +292,7 @@ public Element getAsElement(){
288292
customContentEl.setAttribute("showElapsedBuildTime", this.content.getShowElapsedBuildTime().toString());
289293
customContentEl.setAttribute(SHOW_COMMITS, this.content.getShowCommits().toString());
290294
customContentEl.setAttribute(SHOW_COMMITTERS, this.content.getShowCommitters().toString());
295+
customContentEl.setAttribute(SHOW_TRIGGERED_BY, this.content.getShowTriggeredBy().toString());
291296
customContentEl.setAttribute(SHOW_FAILURE_REASON, this.content.getShowFailureReason().toString());
292297
el.addContent(customContentEl);
293298
}

tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/settings/SlackNotificationContentConfig.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ public class SlackNotificationContentConfig {
99
public static final boolean DEFAULT_SHOW_ELAPSED_BUILD_TIME = true;
1010
public static final boolean DEFAULT_SHOW_COMMITS = true;
1111
public static final boolean DEFAULT_SHOW_COMMITTERS = true;
12+
public static final boolean DEFAULT_SHOW_TRIGGERED_BY = true;
1213
public static final boolean DEFAULT_SHOW_FAILURE_REASON = false;
1314
private String iconUrl = SlackNotificationMainConfig.DEFAULT_ICONURL;
1415
private String botName = SlackNotificationMainConfig.DEFAULT_BOTNAME;
1516
private Boolean showBuildAgent;
1617
private Boolean showElapsedBuildTime;
1718
private Boolean showCommits = true;
1819
private Boolean showCommitters = true;
20+
private Boolean showTriggeredBy = true;
1921
private int maxCommitsToDisplay = 5;
2022
private boolean enabled;
2123
private Boolean showFailureReason;
@@ -76,6 +78,14 @@ public void setShowCommitters(Boolean showCommitters) {
7678
this.showCommitters = showCommitters;
7779
}
7880

81+
public Boolean getShowTriggeredBy() {
82+
return showTriggeredBy;
83+
}
84+
85+
public void setShowTriggeredBy(Boolean showTriggeredBy) {
86+
this.showTriggeredBy = showTriggeredBy;
87+
}
88+
7989
public int getMaxCommitsToDisplay() {
8090
return maxCommitsToDisplay;
8191
}

tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/settings/SlackNotificationMainConfig.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class SlackNotificationMainConfig implements ChangeListener {
2525
private static final String SHOW_BUILD_AGENT = "showBuildAgent";
2626
private static final String SHOW_COMMITS = "showCommits";
2727
private static final String SHOW_COMMITTERS = "showCommitters";
28+
private static final String SHOW_TRIGGERED_BY = "showTriggeredBy";
2829
private static final String SHOW_FAILURE_REASON = "showFailureReason";
2930
private static final String MAX_COMMITS_TO_DISPLAY = "maxCommitsToDisplay";
3031
private static final String SHOW_ELAPSED_BUILD_TIME = "showElapsedBuildTime";
@@ -305,6 +306,9 @@ public void process(Element rootElement) {
305306
if(SlackNotificationMainConfig.this.content.getShowCommitters() != null) {
306307
rootElement.setAttribute(SHOW_COMMITTERS, Boolean.toString(SlackNotificationMainConfig.this.content.getShowCommitters()));
307308
}
309+
if(SlackNotificationMainConfig.this.content.getShowTriggeredBy() != null) {
310+
rootElement.setAttribute(SHOW_TRIGGERED_BY, Boolean.toString(SlackNotificationMainConfig.this.content.getShowTriggeredBy()));
311+
}
308312
if(SlackNotificationMainConfig.this.content.getShowFailureReason() != null) {
309313
rootElement.setAttribute(SHOW_FAILURE_REASON, Boolean.toString(SlackNotificationMainConfig.this.content.getShowFailureReason()));
310314
}
@@ -389,6 +393,10 @@ void readConfigurationFromXmlElement(Element slackNotificationsElement) {
389393
{
390394
content.setShowCommitters(Boolean.parseBoolean(slackNotificationsElement.getAttributeValue(SHOW_COMMITTERS)));
391395
}
396+
if(slackNotificationsElement.getAttribute(SHOW_TRIGGERED_BY) != null)
397+
{
398+
content.setShowTriggeredBy(Boolean.parseBoolean(slackNotificationsElement.getAttributeValue(SHOW_TRIGGERED_BY)));
399+
}
392400
if(slackNotificationsElement.getAttribute(MAX_COMMITS_TO_DISPLAY) != null)
393401
{
394402
content.setMaxCommitsToDisplay(Integer.parseInt(slackNotificationsElement.getAttributeValue(MAX_COMMITS_TO_DISPLAY)));

tcslackbuildnotifier-core/src/main/java/slacknotifications/teamcity/settings/SlackNotificationMainSettings.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ public boolean getShowCommitters(){
122122
return this.slackNotificationMainConfig.getContent().getShowCommitters();
123123
}
124124

125+
public boolean getShowTriggeredBy(){
126+
return this.slackNotificationMainConfig.getContent().getShowTriggeredBy();
127+
}
128+
125129
public Boolean getShowFailureReason() {
126130
return this.slackNotificationMainConfig.getContent().getShowFailureReason();
127131
}

tcslackbuildnotifier-core/src/test/resources/main-config-full.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
showElapsedBuildTime="true"
1111
showCommits="false"
1212
showCommitters="false"
13+
showTriggeredBy="false"
1314
maxCommitsToDisplay="15"
1415
showFailureReason="true">
1516
<proxy host="myproxy.mycompany.com" port="8080" username="some-username" password="some-password" />

0 commit comments

Comments
 (0)