Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

getting the Build's as generic as possible.

Switching it to Run where applicable. There few places that required it to be AbstractBuild we just do an InstanceOf check.
This should help prevent any future job types from not showing up on the view.
  • Loading branch information...
commit e5daebd3c3b4d63e0e0e09d35d1259d490e5841a 1 parent 591f11a
Joel Johnson authored
35 src/main/java/com/attask/jenkins/dashboard/PipelineDashboard.java
@@ -101,7 +101,7 @@ public Table getDisplayRows() {
101 101 // LOGGER.info("getDisplayRows starting");
102 102
103 103 Jenkins jenkins = Jenkins.getInstance();
104   - Map<String, Build[]> map = findMatchingBuilds(jenkins, jobs, descriptionRegex, descriptionRegexGroup);
  104 + Map<String, Run[]> map = findMatchingBuilds(jenkins, jobs, descriptionRegex, descriptionRegexGroup);
105 105 // LOGGER.info("map size: " + map.size());
106 106
107 107 Table result = generateRowData(jenkins.getRootUrl(), User.current(), map, this.showBuildName, this.showFailureCount);
@@ -110,10 +110,10 @@ public Table getDisplayRows() {
110 110 return result;
111 111 }
112 112
113   - protected Map<String, Build[]> findMatchingBuilds(ItemGroup<TopLevelItem> jenkins, List<String> jobs, String descriptionRegex, int descriptionRegexGroup) {
  113 + protected Map<String, Run[]> findMatchingBuilds(ItemGroup<TopLevelItem> jenkins, List<String> jobs, String descriptionRegex, int descriptionRegexGroup) {
114 114 if(jenkins == null || jobs == null || descriptionRegex == null) return Collections.emptyMap();
115 115
116   - Map<String, Build[]> map = new HashMap<String, Build[]>();
  116 + Map<String, Run[]> map = new HashMap<String, Run[]>();
117 117 for (String jobName : jobs) {
118 118 try {
119 119 Job job = (Job) jenkins.getItem(jobName);
@@ -121,7 +121,7 @@ public Table getDisplayRows() {
121 121 RunList builds = job.getBuilds();
122 122 if(builds == null) continue;
123 123 for (Object buildObj : builds) {
124   - Build build = (Build)buildObj;
  124 + Run build = (Run)buildObj;
125 125 String buildDescription = build.getDescription();
126 126 if(buildDescription == null || buildDescription.trim().isEmpty()) {
127 127 continue;
@@ -131,7 +131,7 @@ public Table getDisplayRows() {
131 131 if(buildDescription.matches(descriptionRegex)) {
132 132 String key = buildDescription.replaceFirst(descriptionRegex, "$" + descriptionRegexGroup);
133 133 if(!map.containsKey(key)) {
134   - map.put(key, new Build[jobs.size()]);
  134 + map.put(key, new Run[jobs.size()]);
135 135 }
136 136 map.get(key)[jobs.indexOf(jobName)] = build;
137 137 }
@@ -146,7 +146,7 @@ public Table getDisplayRows() {
146 146 return map;
147 147 }
148 148
149   - protected Table generateRowData(String rootUrl, User currentUser, Map<String, Build[]> map, boolean showBuildName, boolean showFailureCount) {
  149 + protected Table generateRowData(String rootUrl, User currentUser, Map<String, Run[]> map, boolean showBuildName, boolean showFailureCount) {
150 150 if(rootUrl == null) rootUrl = "";
151 151 if(map == null) return Table.EMPTY_TABLE;
152 152
@@ -162,19 +162,22 @@ public int compare(Row row1, Row row2) {
162 162 for (String rowName : map.keySet()) {
163 163 try {
164 164 // LOGGER.info("Row " + rowName);
165   - Build[] builds = map.get(rowName);
  165 + Run[] builds = map.get(rowName);
166 166 List<Column> columns = new LinkedList<Column>();
167 167 Date date = null;
168 168 String displayName = rowName;
169 169 boolean isCulprit = false;
170 170 boolean hasMultiple = false;
171 171
172   - for (Build build : builds) {
  172 + for (Run build : builds) {
173 173 if(build != null) {
174 174 // LOGGER.info("\t" + build.getDisplayName() + " " + build.getDescription());
175 175 if(date == null) {
176 176 date = build.getTime();
177   - hasMultiple = !build.getChangeSet().isEmptySet() && build.getChangeSet().getItems().length > 1;
  177 + if(build instanceof AbstractBuild) {
  178 + AbstractBuild abstractBuild = (AbstractBuild) build;
  179 + hasMultiple = !abstractBuild.getChangeSet().isEmptySet() && abstractBuild.getChangeSet().getItems().length > 1;
  180 + }
178 181 }
179 182
180 183 String rowDisplayName = "";
@@ -238,7 +241,7 @@ public int compare(Row row1, Row row2) {
238 241 return new Table(result, lastSuccessfulRow);
239 242 }
240 243
241   - private boolean getUserIsCommitter(User currentUser, Build build) {
  244 + private boolean getUserIsCommitter(User currentUser, Run build) {
242 245 if(currentUser == null || build == null) return false;
243 246
244 247 String description = build.getDescription();
@@ -247,11 +250,13 @@ private boolean getUserIsCommitter(User currentUser, Build build) {
247 250 }
248 251
249 252 //noinspection unchecked
250   - for (Object changeO : build.getChangeSet()) {
251   - ChangeLogSet.Entry change = (ChangeLogSet.Entry)changeO;
252   - User culprit = change.getAuthor();
253   - if((culprit.getId() != null && culprit.getId().equals(currentUser.getId())) || (culprit.getFullName() != null && culprit.getFullName().equals(currentUser.getFullName()))) {
254   - return true;
  253 + if(build instanceof AbstractBuild) {
  254 + for (Object changeObj : ((AbstractBuild)build).getChangeSet()) {
  255 + ChangeLogSet.Entry change = (ChangeLogSet.Entry)changeObj;
  256 + User culprit = change.getAuthor();
  257 + if((culprit.getId() != null && culprit.getId().equals(currentUser.getId())) || (culprit.getFullName() != null && culprit.getFullName().equals(currentUser.getFullName()))) {
  258 + return true;
  259 + }
255 260 }
256 261 }
257 262

0 comments on commit e5daebd

Please sign in to comment.
Something went wrong with that request. Please try again.