Skip to content

Commit 6ec3a46

Browse files
committed
with an additional checkbox to enable manual linking
1 parent ff81ac9 commit 6ec3a46

File tree

6 files changed

+57
-14
lines changed

6 files changed

+57
-14
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ junit (
9090
autoUnlinkIssue: false,
9191
additionalAttachments: false,
9292
overrideResolvedIssues: false,
93+
manualAddIssue: false,
9394
)
9495
]
9596
)
@@ -123,6 +124,8 @@ If you check the **Auto unlink issues when test passes** check box, this plugin
123124

124125
If you check the **Auto override resolved issues** check box, this plugin will create new issues automatically for failing tests that are linked to already resolved issues.
125126

127+
If you check the **Manually link or raise issues** check box, this plugin will allow to manually link or create issues to the failing tests in new builds also if auto raise is not enabled.
128+
126129
![image of job config settings](img/job-config1.png)
127130

128131
Only after configuring the fields above, if you want you can override the **Summary** and **Description** values by clicking the **Advanced** button.

src/main/java/org/jenkinsci/plugins/JiraTestResultReporter/JiraTestDataPublisher.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ public boolean getOverrideResolvedIssues() {
135135
return JobConfigMapping.getInstance().getOverrideResolvedIssues(getJobName());
136136
}
137137

138+
public boolean getManualAddIssue() {
139+
return JobConfigMapping.getInstance().getManualAddIssue(getJobName());
140+
}
141+
138142
/**
139143
* Getter for list of attachments by test method identified by its classname and name
140144
* @param className
@@ -184,10 +188,11 @@ public void setAdditionalAttachments(boolean additionalAttachments) {
184188
.withProjectKey(this.jobConfig.getProjectKey())
185189
.withIssueType(this.jobConfig.getIssueType())
186190
.withAutoRaiseIssues(this.jobConfig.getAutoRaiseIssue())
187-
.withOverrideResolvedIssues(this.jobConfig.getOverrideResolvedIssues())
188191
.withAutoResolveIssues(this.jobConfig.getAutoResolveIssue())
189192
.withAutoUnlinkIssues(this.jobConfig.getAutoUnlinkIssue())
190193
.withAdditionalAttachments(additionalAttachments)
194+
.withOverrideResolvedIssues(this.jobConfig.getOverrideResolvedIssues())
195+
.withManualAddIssues(this.jobConfig.getManualAddIssue())
191196
.withConfigs(this.jobConfig.getConfigs())
192197
.build();
193198
}
@@ -201,6 +206,7 @@ public void setAdditionalAttachments(boolean additionalAttachments) {
201206
* @param autoResolveIssue
202207
* @param autoUnlinkIssue
203208
* @param overrideResolvedIssues
209+
* @param manualAddIssue
204210
*/
205211
@DataBoundConstructor
206212
public JiraTestDataPublisher(
@@ -210,7 +216,8 @@ public JiraTestDataPublisher(
210216
boolean autoRaiseIssue,
211217
boolean autoResolveIssue,
212218
boolean autoUnlinkIssue,
213-
boolean overrideResolvedIssues) {
219+
boolean overrideResolvedIssues,
220+
boolean manualAddIssue) {
214221

215222
long defaultIssueType;
216223
try {
@@ -223,9 +230,10 @@ public JiraTestDataPublisher(
223230
.withProjectKey(projectKey)
224231
.withIssueType(defaultIssueType)
225232
.withAutoRaiseIssues(autoRaiseIssue)
226-
.withOverrideResolvedIssues(overrideResolvedIssues)
227233
.withAutoResolveIssues(autoResolveIssue)
228234
.withAutoUnlinkIssues(autoUnlinkIssue)
235+
.withOverrideResolvedIssues(overrideResolvedIssues)
236+
.withManualAddIssues(manualAddIssue)
229237
.withConfigs(Util.fixNull(configs))
230238
.build();
231239

@@ -294,6 +302,10 @@ public TestResultAction.Data contributeTestData(
294302
hasTestData |= unlinkIssuesForPassedTests(listener, project, job, envVars, getTestCaseResults(testResult));
295303
}
296304

305+
if (JobConfigMapping.getInstance().getManualAddIssue(project)) {
306+
hasTestData |= true;
307+
}
308+
297309
if (hasTestData) {
298310
// Workaround to make feasible to use the publisher in parallel executions
299311
if (!reportedTestDataBefore(envVars)) {

src/main/java/org/jenkinsci/plugins/JiraTestResultReporter/JiraUtils.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,13 @@ public static Set<String> searchIssueKeys(Job job, EnvVars envVars, CaseResult t
203203
return issueKeys;
204204
}
205205

206-
IssueInput issueInput = JiraUtils.createIssueInput(job, test, envVars, JiraIssueTrigger.JOB);
207-
SearchResult searchResult = JiraUtils.findIssues(job, test, envVars, issueInput);
208-
if (searchResult != null && searchResult.getTotal() > 0) {
209-
for (Issue issue : searchResult.getIssues()) {
210-
issueKeys.add(issue.getKey());
206+
if (!JobConfigMapping.getInstance().getManualAddIssue(job)) {
207+
IssueInput issueInput = JiraUtils.createIssueInput(job, test, envVars, JiraIssueTrigger.JOB);
208+
SearchResult searchResult = JiraUtils.findIssues(job, test, envVars, issueInput);
209+
if (searchResult != null && searchResult.getTotal() > 0) {
210+
for (Issue issue : searchResult.getIssues()) {
211+
issueKeys.add(issue.getKey());
212+
}
211213
}
212214
}
213215
return issueKeys;

src/main/java/org/jenkinsci/plugins/JiraTestResultReporter/JobConfigMapping.java

+25-6
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ public static class JobConfigEntry implements Serializable {
5757
protected Long issueType;
5858
protected List<AbstractFields> configs;
5959
protected boolean autoRaiseIssue;
60-
protected boolean overrideResolvedIssues;
6160
protected boolean autoResolveIssue;
6261
protected boolean autoUnlinkIssue;
6362
protected boolean additionalAttachments;
63+
protected boolean overrideResolvedIssues;
64+
protected boolean manualAddIssue;
6465
protected transient Pattern issueKeyPattern;
6566

6667
/**
@@ -76,16 +77,18 @@ public JobConfigEntry(
7677
boolean autoRaiseIssue,
7778
boolean autoResolveIssue,
7879
boolean autoUnlinkIssue,
80+
boolean additionalAttachments,
7981
boolean overrideResolvedIssues,
80-
boolean additionalAttachments) {
82+
boolean manualAddIssue) {
8183
this.projectKey = projectKey;
8284
this.issueType = issueType;
8385
this.configs = configs;
8486
this.autoRaiseIssue = autoRaiseIssue;
8587
this.autoResolveIssue = autoResolveIssue;
8688
this.autoUnlinkIssue = autoUnlinkIssue;
87-
this.overrideResolvedIssues = overrideResolvedIssues;
8889
this.additionalAttachments = additionalAttachments;
90+
this.overrideResolvedIssues = overrideResolvedIssues;
91+
this.manualAddIssue = manualAddIssue;
8992
compileIssueKeyPattern();
9093
}
9194

@@ -133,6 +136,10 @@ public boolean getOverrideResolvedIssues() {
133136
return overrideResolvedIssues;
134137
}
135138

139+
public boolean getManualAddIssue() {
140+
return manualAddIssue;
141+
}
142+
136143
/**
137144
* Getter for the issue key pattern
138145
* @return
@@ -165,7 +172,7 @@ public static class JobConfigEntryBuilder extends JobConfigEntry {
165172
* Constructor
166173
*/
167174
public JobConfigEntryBuilder() {
168-
super(null, null, new ArrayList<>(), false, false, false, false, false);
175+
super(null, null, new ArrayList<>(), false, false, false, false, false, false);
169176
}
170177

171178
public JobConfigEntryBuilder withProjectKey(String projectKey) {
@@ -209,6 +216,11 @@ public JobConfigEntryBuilder withOverrideResolvedIssues(boolean overrideResolved
209216
return this;
210217
}
211218

219+
public JobConfigEntryBuilder withManualAddIssues(boolean manualAddIssue) {
220+
this.manualAddIssue = manualAddIssue;
221+
return this;
222+
}
223+
212224
public JobConfigEntry build() {
213225
if (projectKey == null) {
214226
throw new IllegalStateException("The Project Key may not be null");
@@ -376,17 +388,19 @@ public synchronized void saveConfig(
376388
boolean autoRaiseIssue,
377389
boolean autoResolveIssue,
378390
boolean autoUnlinkIssue,
391+
boolean additionalAttachments,
379392
boolean overrideResolvedIssues,
380-
boolean additionalAttachments) {
393+
boolean manualAddIssue) {
381394
JobConfigEntry entry = new JobConfigEntry(
382395
projectKey,
383396
issueType,
384397
configs,
385398
autoRaiseIssue,
386399
autoResolveIssue,
387400
autoUnlinkIssue,
401+
additionalAttachments,
388402
overrideResolvedIssues,
389-
additionalAttachments);
403+
manualAddIssue);
390404
saveConfig(project, entry);
391405
}
392406

@@ -472,6 +486,11 @@ public boolean getOverrideResolvedIssues(Job project) {
472486
return entry != null ? entry.getOverrideResolvedIssues() : false;
473487
}
474488

489+
public boolean getManualAddIssue(Job project) {
490+
JobConfigEntry entry = getJobConfigEntry(project);
491+
return entry != null ? entry.getManualAddIssue() : false;
492+
}
493+
475494
/**
476495
* Getter for the issue key pattern, used to validate user input
477496
* @param project

src/main/resources/org/jenkinsci/plugins/JiraTestResultReporter/JiraTestDataPublisher/config.jelly

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
<f:checkbox/>
3232
</f:entry>
3333

34+
<f:entry title="Manually link or raise issues" field="manualAddIssue">
35+
<f:checkbox/>
36+
</f:entry>
37+
3438
<f:advanced>
3539
<j:set var="items" value="${ instance.configs != null ? instance.configs : descriptor.templates }"/>
3640
<f:entry field="configs">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>
2+
Allow issues to be manually linked via the jenkins webinterface for failing tests that aren't linked yet.
3+
</div>

0 commit comments

Comments
 (0)