1111import jetbrains .buildServer .web .util .SessionUser ;
1212import org .jetbrains .annotations .Nullable ;
1313import org .springframework .web .servlet .ModelAndView ;
14+ import slacknotifications .SlackNotification ;
1415import slacknotifications .teamcity .BuildState ;
1516import slacknotifications .teamcity .BuildStateEnum ;
1617import slacknotifications .teamcity .TeamCityIdResolver ;
1718import slacknotifications .teamcity .extension .bean .ProjectSlackNotificationsBean ;
1819import slacknotifications .teamcity .extension .bean .ProjectSlackNotificationsBeanJsonSerialiser ;
1920import slacknotifications .teamcity .payload .SlackNotificationPayloadManager ;
21+ import slacknotifications .teamcity .settings .SlackNotificationContentConfig ;
22+ import slacknotifications .teamcity .settings .SlackNotificationMainSettings ;
2023import slacknotifications .teamcity .settings .SlackNotificationProjectSettings ;
2124
2225import javax .servlet .http .HttpServletRequest ;
@@ -37,20 +40,22 @@ public class SlackNotificationAjaxEditPageController extends BaseController {
3740 protected static final String BUILD_SUCCESSFUL = "BuildSuccessful" ;
3841
3942 private final WebControllerManager myWebManager ;
40- private SBuildServer myServer ;
43+ private final SlackNotificationMainSettings myMainSettings ;
44+ private SBuildServer myServer ;
4145 private ProjectSettingsManager mySettings ;
4246 private final String myPluginPath ;
4347 private final SlackNotificationPayloadManager myManager ;
4448
4549 public SlackNotificationAjaxEditPageController (SBuildServer server , WebControllerManager webManager ,
4650 ProjectSettingsManager settings , SlackNotificationProjectSettings whSettings , SlackNotificationPayloadManager manager ,
47- PluginDescriptor pluginDescriptor ) {
51+ PluginDescriptor pluginDescriptor , SlackNotificationMainSettings mainSettings ) {
4852 super (server );
4953 myWebManager = webManager ;
5054 myServer = server ;
5155 mySettings = settings ;
5256 myPluginPath = pluginDescriptor .getPluginResourcesPath ();
5357 myManager = manager ;
58+ myMainSettings = mainSettings ;
5459 }
5560
5661 public void register (){
@@ -117,19 +122,56 @@ protected ModelAndView doHandle(HttpServletRequest request, HttpServletResponse
117122 Boolean mentionSlackUserEnabled = false ;
118123 Boolean buildTypeAll = false ;
119124 Boolean buildTypeSubProjects = false ;
125+ SlackNotificationContentConfig content = new SlackNotificationContentConfig ();
120126 Set <String > buildTypes = new HashSet <String >();
121127 if ((request .getParameter ("slackNotificationsEnabled" ) != null )
122128 && (request .getParameter ("slackNotificationsEnabled" ).equalsIgnoreCase ("on" ))){
123129 enabled = true ;
124130 }
125131 if ((request .getParameter ("mentionChannelEnabled" ) != null )
126132 && (request .getParameter ("mentionChannelEnabled" ).equalsIgnoreCase ("on" ))){
133+
127134 mentionChannelEnabled = true ;
128135 }
129136 if ((request .getParameter ("mentionSlackUserEnabled" ) != null )
130137 && (request .getParameter ("mentionSlackUserEnabled" ).equalsIgnoreCase ("on" ))){
131138 mentionSlackUserEnabled = true ;
132139 }
140+
141+ content .setEnabled ((request .getParameter ("customContentEnabled" ) != null )
142+ && (request .getParameter ("customContentEnabled" ).equalsIgnoreCase ("on" )));
143+
144+ if (content .isEnabled ()){
145+
146+ if ((request .getParameter ("maxCommitsToDisplay" ) != null )
147+ && (request .getParameter ("maxCommitsToDisplay" ).length () > 0 )){
148+ content .setMaxCommitsToDisplay (convertToInt (request .getParameter ("maxCommitsToDisplay" ), SlackNotificationContentConfig .DEFAULT_MAX_COMMITS ));
149+ }
150+
151+ content .setShowBuildAgent ((request .getParameter ("showBuildAgent" ) != null )
152+ && (request .getParameter ("showBuildAgent" ).equalsIgnoreCase ("on" )));
153+
154+ content .setShowCommits ((request .getParameter ("showCommits" ) != null )
155+ && (request .getParameter ("showCommits" ).equalsIgnoreCase ("on" )));
156+
157+ content .setShowCommitters ((request .getParameter ("showCommitters" ) != null )
158+ && (request .getParameter ("showCommitters" ).equalsIgnoreCase ("on" )));
159+
160+ content .setShowElapsedBuildTime ((request .getParameter ("showElapsedBuildTime" ) != null )
161+ && (request .getParameter ("showElapsedBuildTime" ).equalsIgnoreCase ("on" )));
162+
163+
164+ if ((request .getParameter ("botName" ) != null )
165+ && (request .getParameter ("botName" ).length () > 0 )){
166+ content .setBotName (request .getParameter ("botName" ));
167+ }
168+
169+ if ((request .getParameter ("iconUrl" ) != null )
170+ && (request .getParameter ("iconUrl" ).length () > 0 )){
171+ content .setIconUrl (request .getParameter ("iconUrl" ));
172+ }
173+ }
174+
133175 BuildState states = new BuildState ();
134176
135177 checkAndAddBuildState (request , states , BuildStateEnum .BUILD_SUCCESSFUL , BUILD_SUCCESSFUL );
@@ -168,7 +210,8 @@ protected ModelAndView doHandle(HttpServletRequest request, HttpServletResponse
168210 } else {
169211 projSettings .updateSlackNotification (myProject .getProjectId (),request .getParameter ("slackNotificationId" ),
170212 request .getParameter ("channel" ), enabled ,
171- states , buildTypeAll , buildTypeSubProjects , buildTypes , mentionChannelEnabled , mentionSlackUserEnabled );
213+ states , buildTypeAll , buildTypeSubProjects , buildTypes , mentionChannelEnabled , mentionSlackUserEnabled ,
214+ content );
172215 if (projSettings .updateSuccessful ()){
173216 myProject .persist ();
174217 params .put ("messages" , "<errors />" );
@@ -217,12 +260,22 @@ protected ModelAndView doHandle(HttpServletRequest request, HttpServletResponse
217260 params .put ("slackNotificationList" , projSettings .getSlackNotificationsAsList ());
218261 params .put ("slackNotificationsDisabled" , !projSettings .isEnabled ());
219262 params .put ("slackNotificationsEnabledAsChecked" , projSettings .isEnabledAsChecked ());
220- params .put ("projectSlackNotificationsAsJson" , ProjectSlackNotificationsBeanJsonSerialiser .serialise (ProjectSlackNotificationsBean .build (projSettings , project )));
263+ params .put ("projectSlackNotificationsAsJson" , ProjectSlackNotificationsBeanJsonSerialiser .serialise (ProjectSlackNotificationsBean .build (projSettings , project , myMainSettings )));
221264 }
222265 } else {
223266 params .put ("haveProject" , "false" );
224267 }
225268
226269 return new ModelAndView (myPluginPath + "SlackNotification/ajaxEdit.jsp" , params );
227270 }
271+
272+
273+ private int convertToInt (String s , int defaultValue ){
274+ try {
275+ int myInt = Integer .parseInt (s );
276+ return myInt ;
277+ } catch (NumberFormatException e ){
278+ return defaultValue ;
279+ }
280+ }
228281}
0 commit comments