Skip to content

Commit

Permalink
Fixes issues #41, #47 and #49
Browse files Browse the repository at this point in the history
 - Handle when filter list is not intialised.
 - Pass the correct object back to the page so that the list of 
    webhooks for a build is the bean expected, not just a list.
  • Loading branch information
netwolfuk committed Sep 8, 2016
1 parent 077b848 commit 43788df
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public WebHookConfig (String url, Boolean enabled, BuildState states, String pay
this.uniqueKey = Rand.toString();
this.extraParameters = new TreeMap<>();
this.templates = new TreeMap<>();
this.filters = new ArrayList<>();
this.setUrl(url);
this.setEnabled(enabled);
this.setBuildStates(states);
Expand Down Expand Up @@ -291,7 +292,7 @@ public Element getAsElement(){
}
el.addContent(buildsEl);

if (this.filters.size() > 0){
if (this.filters != null && this.filters.size() > 0){
Element filtersEl = new Element("trigger-filters");
for (WebHookFilterConfig f : this.filters){
filtersEl.addContent(f.getAsElement());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,15 @@ protected ModelAndView doHandle(HttpServletRequest request, HttpServletResponse
SUser myUser = SessionUser.getUser(request);
params.put("hasPermission", myUser.isPermissionGrantedForProject(project.getProjectId(), Permission.EDIT_PROJECT));

List<WebHookConfig> configs = projSettings.getBuildWebHooksAsList(sBuildType);
ProjectWebHooksBean bean = ProjectWebHooksBean.buildWithoutNew(projSettings, sBuildType,
project,
myManager.getRegisteredFormatsAsCollection(),
myTemplateResolver.findWebHookTemplatesForProject(project)
);

params.put("webHookList", bean);
params.put("formatList", RegisteredWebHookTemplateBean.build(myTemplateResolver.findWebHookTemplatesForProject(project),
myManager.getRegisteredFormats()).getTemplateList());
params.put("webHookList", configs);
params.put("webHooksDisabled", !projSettings.isEnabled());
params.put("projectId", project.getProjectId());
params.put("haveProject", "true");
Expand All @@ -185,8 +190,8 @@ protected ModelAndView doHandle(HttpServletRequest request, HttpServletResponse
params.put("buildName", sBuildType.getName());
params.put("buildExternalId", TeamCityIdResolver.getExternalBuildId(sBuildType));
params.put("buildTypeList", project.getBuildTypes());
params.put("noWebHooks", configs.size() == 0);
params.put("webHooks", configs.size() != 0);
params.put("noWebHooks", bean.getWebHookList().size() == 0);
params.put("webHooks", bean.getWebHookList().size() != 0);

params.put("projectWebHooksAsJson", ProjectWebHooksBeanJsonSerialiser.serialise(
TemplatesAndProjectWebHooksBean.build(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ public static ProjectWebHooksBean build(WebHookProjectSettings projSettings, SBu
return bean;

}

public static ProjectWebHooksBean buildWithoutNew(WebHookProjectSettings projSettings, SBuildType sBuildType, SProject project, Collection<WebHookPayload> registeredPayloads, List<WebHookTemplate> templateList){
ProjectWebHooksBean bean = new ProjectWebHooksBean();
List<SBuildType> projectBuildTypes = TeamCityIdResolver.getOwnBuildTypes(project);
Set<String> enabledBuildTypes = new HashSet<String>();
enabledBuildTypes.add(sBuildType.getBuildTypeId());

bean.projectId = TeamCityIdResolver.getInternalProjectId(project);
bean.webHookList = new LinkedHashMap<String, WebhookConfigAndBuildTypeListHolder>();

/* Iterate over the rest of the webhooks in this project and add them to the json config */
for (WebHookConfig config : projSettings.getBuildWebHooksAsList(sBuildType)){
addWebHookConfigHolder(bean, projectBuildTypes, config, registeredPayloads, templateList);
}

return bean;

}


private static void addWebHookConfigHolder(ProjectWebHooksBean bean,
Expand Down

0 comments on commit 43788df

Please sign in to comment.