Skip to content

Commit 4836a29

Browse files
jordivxVila
andauthored
Simplify successor management since now issue links are no longer inherited (#1116)
* Update project loadJiraDataForCurrentVersion after having created inherited links * Created protected method to reduce nested block depth * Updated CHANGELOG and added javadoc * Added javadoc in added method --------- Co-authored-by: Vila <jordi.vila@boehringer-ingelheim.com>
1 parent 89b3de9 commit 4836a29

File tree

3 files changed

+83
-13
lines changed

3 files changed

+83
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Deprecation of vuln-type and scanners config in Trivy ([#1150](https://github.com/opendevstack/ods-jenkins-shared-library/issues/1150))
1111
* Add preserve-digests cli option to skopeo copy command in CopyImageStage ([#1166](https://github.com/opendevstack/ods-jenkins-shared-library/issues/1166))
1212
* Allow registry/image:tag sources in CopyImageStage instead of directly falling back to internal registry ([#1177](https://github.com/opendevstack/ods-jenkins-shared-library/pull/1177))
13-
13+
* Simplify successor management since now issue links are no longer inherited ([#1116](https://github.com/opendevstack/ods-jenkins-shared-library/pull/1116))
1414

1515
### Fixed
1616
* Fix Tailor deployment drifts for D, Q envs ([#1055](https://github.com/opendevstack/ods-jenkins-shared-library/pull/1055))

src/org/ods/orchestration/util/Project.groovy

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,8 @@ class Project {
13011301
logger.info("loadJiraData: Found a predecessor project version with ID '${previousVersionId}'. Loading its data.")
13021302
def savedDataFromOldVersion = this.loadSavedJiraData(previousVersionId)
13031303
def mergedData = this.mergeJiraData(savedDataFromOldVersion, newData)
1304+
mergedData = this.overrideDeltaDocgenDataLinks(mergedData, newData)
1305+
mergedData = this.removeObsoleteIssuesFromComponents(mergedData)
13041306
result << this.addKeyAndVersionToComponentsWithout(mergedData)
13051307
result.previousVersion = previousVersionId
13061308
} else {
@@ -1349,6 +1351,75 @@ class Project {
13491351
}
13501352
}
13511353

1354+
/**
1355+
* It uses the data from the deltadocgen of the latest version as a source of truth in terms of links.
1356+
* If an issue appears in the deltadocgen report, we use all its data adding the expanded predecessors.
1357+
* If an issue appears as a link in the old data but in the deltadocgen report doesn't show the same link in the other
1358+
* direction, then we remove that link.
1359+
*
1360+
* @param mergedData resulting data of merging last release json report and deltadocgen
1361+
* @param deltaDocgenData result of deltadocgen endpoint for the latest version
1362+
* @return the merged data with the proper links
1363+
*/
1364+
protected Map overrideDeltaDocgenDataLinks(Map<String,Map> mergedData, Map<String,Map> deltaDocgenData) {
1365+
mergedData.findAll { JiraDataItem.REGULAR_ISSUE_TYPES.contains(it.key) }.each { issueType, issues ->
1366+
issues.values().each { Map issueToUpdate ->
1367+
if(deltaDocgenData[issueType] && deltaDocgenData[issueType][issueToUpdate.key]) {
1368+
def resultData = deltaDocgenData[issueType][issueToUpdate.key]
1369+
resultData << [expandedPredecessors: mergedData[issueType][issueToUpdate.key]['expandedPredecessors']]
1370+
mergedData[issueType][issueToUpdate.key] = resultData
1371+
} else {
1372+
mergedData[issueType][issueToUpdate.key].findAll { JiraDataItem.REGULAR_ISSUE_TYPES.contains(it.key) }.each { relatedIssueType, relatedIssues ->
1373+
def relatedIssuesToRemove = findRelatedIssuesToRemove(relatedIssues, deltaDocgenData, relatedIssueType, issueType, issueToUpdate)
1374+
mergedData[issueType][issueToUpdate.key][relatedIssueType].removeAll { relatedIssuesToRemove.contains(it) }
1375+
}
1376+
}
1377+
}
1378+
}
1379+
return mergedData
1380+
}
1381+
1382+
/**
1383+
* The method checks each issue in the 'relatedIssues' list against the related issues in the 'deltaDocgenData'.
1384+
* If the issueToUpdate key does not appear in the deltaDocgenData as a related issue but the deltaDocGen has some
1385+
* issues related for that issue type, the issue is added to the list of issues to be removed.
1386+
*
1387+
* @param relatedIssues A list of related issues to be examined.
1388+
* @param deltaDocgenData A map containing data from the deltaDocGen
1389+
* @param relatedIssueType The type of the related issue.
1390+
* @param issueType The type of the issue.
1391+
* @param issueToUpdate A map containing the issue to be updated.
1392+
*
1393+
* @return A list of related issues that need to be removed.
1394+
*/
1395+
protected static List findRelatedIssuesToRemove(List<String> relatedIssues, Map deltaDocgenData, String relatedIssueType, String issueType, Map issueToUpdate) {
1396+
def relatedIssuesToRemove = []
1397+
relatedIssues.each {
1398+
if (deltaDocgenData[relatedIssueType][it] && deltaDocgenData[relatedIssueType][it][issueType] && !deltaDocgenData[relatedIssueType][it][issueType].contains(issueToUpdate.key)) {
1399+
relatedIssuesToRemove.add(it)
1400+
}
1401+
}
1402+
return relatedIssuesToRemove
1403+
}
1404+
1405+
/**
1406+
* It removes any issue in the components map that does not appear under the technology map it should belong
1407+
*
1408+
* @param mergedData resulting data of merging last release json report and deltadocgen
1409+
* @return the merged data with the proper issues in the components map
1410+
*/
1411+
protected Map removeObsoleteIssuesFromComponents(Map<String,Map> mergedData) {
1412+
mergedData[JiraDataItem.TYPE_COMPONENTS].collectEntries { component, componentIssues ->
1413+
JiraDataItem.REGULAR_ISSUE_TYPES.each { issueType ->
1414+
if(componentIssues[issueType]) {
1415+
componentIssues[issueType].removeAll { !mergedData[issueType].keySet().contains(it) }
1416+
}
1417+
}
1418+
[(component): componentIssues]
1419+
}
1420+
return mergedData
1421+
}
1422+
13521423
protected Map loadJiraDataBugs(Map tests, String versionName = null) {
13531424
if (!this.jiraUseCase) return [:]
13541425
if (!this.jiraUseCase.jira) return [:]

test/groovy/org/ods/orchestration/util/ProjectSpec.groovy

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,7 +2319,6 @@ class ProjectSpec extends SpecHelper {
23192319
def firstVersion = '1.0'
23202320
def secondVersion = '2.0'
23212321

2322-
def cmp ={ name -> [key: "CMP-${name}" as String, name: "Component 1"]}
23232322
def req = { name, String version = null -> [key: "REQ-${name}" as String, description:name, versions:[version]] }
23242323
def ts = { name, String version = null -> [key: "TS-${name}" as String, description:name, versions:[version]] }
23252324
def rsk = { name, String version = null -> [key: "RSK-${name}" as String, description:name, versions:[version]] }
@@ -2345,23 +2344,23 @@ class ProjectSpec extends SpecHelper {
23452344
ts1 << [requirements: [req1.key], tests: [tst1.key, tst2.key]]
23462345
rsk1 << [requirements: [req1.key], mitigations: [mit1.key]]
23472346
mit1 << [requirements: [req1.key], risks: [rsk1.key]]
2348-
req2 << [predecessors: [req1.key], tests: [tst4.key]]
2349-
tst3 << [predecessors: [tst1.key]]
2347+
req2 << [predecessors: [req1.key], tests: [tst2.key,tst3.key,tst4.key], techSpecs: [ts2.key], risks: [rsk2.key], mitigations: [mit2.key]]
2348+
tst3 << [predecessors: [tst1.key], requirements: [req2.key], techSpecs: [ts2.key]]
23502349
tst4 << [requirements: [req2.key]]
2351-
rsk2 << [predecessors: [rsk1.key], requirements: [req1.key]]
2352-
mit2 << [predecessors: [mit1.key], requirements: [req1.key], risks: [rsk1.key]]
2353-
ts2 << [predecessors: [ts1.key]]
2350+
rsk2 << [predecessors: [rsk1.key], requirements: [req2.key], mitigations: [mit2.key]]
2351+
mit2 << [predecessors: [mit1.key], requirements: [req2.key], risks: [rsk2.key]]
2352+
ts2 << [predecessors: [ts1.key], requirements: [req2.key], tests: [tst2.key, tst3.key]]
23542353

2355-
def req2Updated = req2.clone() + [tests: [tst4.key, tst3.key, tst2.key], techSpecs: [ts2.key], risks: [rsk2.key], mitigations: [mit2.key]]
2354+
def req2Updated = req2.clone()
23562355
req2Updated << [expandedPredecessors: [[key: req1.key, versions: req1.versions]]]
2357-
def tst2Updated = tst2.clone() + [requirements: [req2.key], techSpecs: [ts2.key]]
2358-
def tst3Updated = tst3.clone() + [requirements: [req2.key], techSpecs: [ts2.key]]
2356+
def tst2Updated = tst2.clone()
2357+
def tst3Updated = tst3.clone()
23592358
tst3Updated << [expandedPredecessors: [[key: tst1.key, versions: tst1.versions]]]
2360-
def rsk2Updated = rsk2.clone() + [requirements: [req2.key], mitigations: [mit2.key]]
2359+
def rsk2Updated = rsk2.clone()
23612360
rsk2Updated << [expandedPredecessors: [[key: rsk1.key, versions: rsk1.versions]]]
2362-
def mit2Updated = mit2.clone() + [requirements: [req2.key], risks: [rsk2.key]]
2361+
def mit2Updated = mit2.clone()
23632362
mit2Updated << [expandedPredecessors: [[key: mit1.key, versions: mit1.versions]]]
2364-
def ts2Updated = ts2.clone() + [requirements: [req2.key], tests: [tst3.key, tst2.key]]
2363+
def ts2Updated = ts2.clone()
23652364
ts2Updated << [expandedPredecessors: [[key: ts1.key, versions: ts1.versions]]]
23662365

23672366
def storedData = [

0 commit comments

Comments
 (0)