Skip to content

Commit 9af90bc

Browse files
author
zxBCN Farre_Basurte,Juan_Antonio (IT EDS) EXTERNAL
committed
Remove deprecated code and fix unit tests
1 parent f247054 commit 9af90bc

File tree

8 files changed

+43
-381
lines changed

8 files changed

+43
-381
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
- RM: test component causes new jenkins (run) instance after branch is created for release
7272
([#823](https://github.com/opendevstack/ods-jenkins-shared-library/issues/823))
7373
- Improve error message when two coded tests are linked to the same test issue ([#826](https://github.com/opendevstack/ods-jenkins-shared-library/pull/826))
74+
- Remove support for EDP 1.0 projects in the Release Manager ([#748](https://github.com/opendevstack/ods-jenkins-shared-library/pull/748))
7475

7576
## [3.0] - 2020-08-11
7677

src/org/ods/orchestration/service/JiraService.groovy

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -240,34 +240,6 @@ class JiraService {
240240
return createIssueType("Bug", projectKey, summary, description, fixVersion)
241241
}
242242

243-
@NonCPS
244-
Map getDocGenData(String projectKey) {
245-
if (!projectKey?.trim()) {
246-
throw new IllegalArgumentException('Error: unable to get documentation generation data from Jira. ' +
247-
'\'projectKey\' is undefined.')
248-
}
249-
250-
def response = Unirest.get("${this.baseURL}/rest/platform/1.0/docgenreports/{projectKey}")
251-
.routeParam("projectKey", projectKey.toUpperCase())
252-
.basicAuth(this.username, this.password)
253-
.header("Accept", "application/json")
254-
.asString()
255-
256-
response.ifFailure {
257-
def message = 'Error: unable to get documentation generation data. Jira responded with code: ' +
258-
"'${response.getStatus()}' and message: '${response.getBody()}'."
259-
260-
if (response.getStatus() == 404) {
261-
message = 'Error: unable to get documentation generation data. ' +
262-
"Jira could not be found at: '${this.baseURL}'."
263-
}
264-
265-
throw new RuntimeException(message)
266-
}
267-
268-
return new JsonSlurperClassic().parseText(StringCleanup.removeCharacters(response.getBody(), CHARACTER_REMOVEABLE))
269-
}
270-
271243
@NonCPS
272244
Map getDeltaDocGenData(String projectKey, String version) {
273245
if (!projectKey?.trim()) {
@@ -685,43 +657,4 @@ class JiraService {
685657
new JsonSlurperClassic().parseText(response.getBody()).getOrDefault("fields", [:])
686658
}
687659

688-
@NonCPS
689-
Boolean isVersionEnabledForDelta(String projectKey, String versionName) {
690-
if (!projectKey?.trim()) {
691-
throw new IllegalArgumentException('Error: unable to check project versions from Jira. ' +
692-
'\'projectKey\' is undefined.')
693-
}
694-
695-
if (!versionName?.trim()) {
696-
throw new IllegalArgumentException('Error: unable to check project versions from Jira. ' +
697-
'\'versionName\' is undefined.')
698-
}
699-
700-
def response = Unirest.get("${this.baseURL}/rest/platform/1.1/productreleases/{projectKey}/versions/{version}")
701-
.routeParam('projectKey', projectKey.toUpperCase())
702-
.routeParam('version', versionName)
703-
.basicAuth(this.username, this.password)
704-
.header('Accept', 'application/json')
705-
.asString()
706-
707-
response.ifFailure {
708-
if (response.getStatus() == 400) {
709-
if(response.getBody().contains("Invalid project versionName.")) {
710-
return false
711-
}
712-
}
713-
def message = 'Error: unable to get project versions in url ' +
714-
"${this.baseURL}/rest/platform/1.1/productreleases/${projectKey.toUpperCase()}/versions/${versionName}" +
715-
' Jira responded with code: ' +
716-
"'${response.getStatus()}' and message: '${response.getBody()}'."
717-
718-
if (response.getStatus() == 404) {
719-
message = "Error: unable to get project versions. Jira could not be found at: '${this.baseURL}'."
720-
}
721-
722-
throw new RuntimeException(message)
723-
}
724-
return true
725-
}
726-
727660
}

src/org/ods/orchestration/usecase/LeVADocumentUseCase.groovy

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,14 +1649,8 @@ class LeVADocumentUseCase extends DocGenUseCase {
16491649
def documentationTrackingIssueFields = this.project.getJiraFieldsForIssueType(JiraUseCase.IssueTypes.DOCUMENTATION_TRACKING)
16501650
def documentationTrackingIssueDocumentVersionField = documentationTrackingIssueFields[JiraUseCase.CustomIssueFields.DOCUMENT_VERSION]
16511651

1652-
if (this.project.isVersioningEnabled) {
1653-
if (!this.project.isDeveloperPreviewMode() && !this.project.hasWipJiraIssues()) {
1654-
// In case of generating a final document, we add the label for the version that should be released
1655-
this.jiraUseCase.jira.updateTextFieldsOnIssue(jiraIssueKey,
1656-
[(documentationTrackingIssueDocumentVersionField.id): "${docVersionId}"])
1657-
}
1658-
} else {
1659-
// TODO removeme for ODS 4.0
1652+
if (!this.project.isDeveloperPreviewMode() && !this.project.hasWipJiraIssues()) {
1653+
// In case of generating a final document, we add the label for the version that should be released
16601654
this.jiraUseCase.jira.updateTextFieldsOnIssue(jiraIssueKey,
16611655
[(documentationTrackingIssueDocumentVersionField.id): "${docVersionId}"])
16621656
}
@@ -1761,25 +1755,18 @@ class LeVADocumentUseCase extends DocGenUseCase {
17611755
}
17621756

17631757
protected String getVersion(Project project, String doc) {
1764-
def version
1765-
1766-
if (project.isVersioningEnabled) {
1767-
version = project.getDocumentVersionFromHistories(doc)
1768-
if (!version) {
1769-
// The document has not (yet) been generated in this pipeline run.
1770-
def envs = Environment.values().collect { it.toString() }
1771-
def trackingIssues = this.getDocumentTrackingIssuesForHistory(doc, envs)
1772-
version = this.jiraUseCase.getLatestDocVersionId(trackingIssues)
1773-
if (project.isWorkInProgress ||
1774-
LeVADocumentScheduler.getFirstCreationEnvironment(doc) ==
1775-
project.buildParams.targetEnvironmentToken ) {
1776-
// Either this is a developer preview or the history is to be updated in this environment.
1777-
version += 1L
1778-
}
1758+
def version = project.getDocumentVersionFromHistories(doc)
1759+
if (!version) {
1760+
// The document has not (yet) been generated in this pipeline run.
1761+
def envs = Environment.values().collect { it.toString() }
1762+
def trackingIssues = this.getDocumentTrackingIssuesForHistory(doc, envs)
1763+
version = this.jiraUseCase.getLatestDocVersionId(trackingIssues)
1764+
if (project.isWorkInProgress ||
1765+
LeVADocumentScheduler.getFirstCreationEnvironment(doc) ==
1766+
project.buildParams.targetEnvironmentToken ) {
1767+
// Either this is a developer preview or the history is to be updated in this environment.
1768+
version += 1L
17791769
}
1780-
} else {
1781-
// TODO removeme in ODS 4.x
1782-
version = "${project.buildParams.version}-${this.steps.env.BUILD_NUMBER}"
17831770
}
17841771

17851772
if (project.isWorkInProgress) {

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

Lines changed: 5 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ class Project {
267267
protected ILogger logger
268268
protected Map config
269269
protected String targetProject
270-
protected Boolean isVersioningEnabled = false
271270

272271
protected Map data = [:]
273272

@@ -346,10 +345,7 @@ class Project {
346345
// Get more info of the versions from Jira
347346
this.data.jira.project.version = this.loadCurrentVersionDataFromJira()
348347

349-
def version = null
350-
if (this.isVersioningEnabled) {
351-
version = this.getVersionName()
352-
}
348+
def version = this.getVersionName()
353349

354350
// FIXME: contrary to the comment below, the bug data from this method is still relevant
355351
// implementation needs to be cleaned up and bug data should be delivered through plugin's
@@ -547,10 +543,6 @@ class Project {
547543
!getIsPromotionMode()
548544
}
549545

550-
boolean getIsVersioningEnabled() {
551-
isVersioningEnabled
552-
}
553-
554546
static boolean isPromotionMode(String targetEnvironmentToken) {
555547
['Q', 'P'].contains(targetEnvironmentToken)
556548
}
@@ -1058,23 +1050,6 @@ class Project {
10581050
]
10591051
}
10601052

1061-
/**
1062-
* Checks if the JIRA version supports the versioning feature
1063-
* If jira or JiraUsecase is not enabled -> false
1064-
* If templates version is 1.0 -> false
1065-
* Otherwise, check from Jira
1066-
* @ true if versioning is enabled
1067-
*/
1068-
boolean checkIfVersioningIsEnabled(String projectKey, String versionName) {
1069-
if (!this.jiraUseCase) return false
1070-
if (!this.jiraUseCase.jira) return false
1071-
def levaDocsCapability = this.getCapability('LeVADocs')
1072-
if (levaDocsCapability.templatesVersion == '1.0') {
1073-
return false
1074-
}
1075-
return this.jiraUseCase.jira.isVersionEnabledForDelta(projectKey, versionName)
1076-
}
1077-
10781053
protected Map loadJiraData(String projectKey) {
10791054
def result = [
10801055
components: [:],
@@ -1092,16 +1067,8 @@ class Project {
10921067
// than once. However, it's also called via this.project.versionFromReleaseStatusIssue in JiraUseCase.groovy.
10931068
def currentVersion = this.getVersionFromReleaseStatusIssue() // TODO why is param.version not sufficient here?
10941069

1095-
this.isVersioningEnabled = this.checkIfVersioningIsEnabled(projectKey, currentVersion)
1096-
if (this.isVersioningEnabled) {
1097-
// We detect the correct version even if the build is WIP
1098-
logger.info("Project has versioning enabled.")
1099-
result = this.loadJiraDataForCurrentVersion(projectKey, currentVersion)
1100-
} else {
1101-
// TODO remove in ODS 4.0 version
1102-
logger.info("Versioning not supported for this release")
1103-
result = this.loadFullJiraData(projectKey)
1104-
}
1070+
// We detect the correct version even if the build is WIP
1071+
result = this.loadJiraDataForCurrentVersion(projectKey, currentVersion)
11051072
}
11061073

11071074
return result
@@ -1112,17 +1079,6 @@ class Project {
11121079
return this.jiraUseCase.getVersionFromReleaseStatusIssue()
11131080
}
11141081

1115-
protected Map loadFullJiraData(String projectKey) {
1116-
def result = this.jiraUseCase.jira.getDocGenData(projectKey)
1117-
if (result?.project?.id == null) {
1118-
throw new IllegalArgumentException(
1119-
"Error: unable to load documentation generation data from Jira. 'project.id' is undefined.")
1120-
}
1121-
def docChapterData = this.getDocumentChapterData(projectKey)
1122-
result << [(JiraDataItem.TYPE_DOCS as String): docChapterData]
1123-
return result
1124-
}
1125-
11261082
protected Map loadVersionJiraData(String projectKey, String versionName) {
11271083
def result = this.jiraUseCase.jira.getDeltaDocGenData(projectKey, versionName)
11281084
if (result?.project?.id == null) {
@@ -1135,16 +1091,9 @@ class Project {
11351091
return result
11361092
}
11371093

1138-
protected Map<String, Map> getDocumentChapterData(String projectKey, String versionName = null) {
1094+
protected Map<String, Map> getDocumentChapterData(String projectKey, String versionName) {
11391095
def docChapters = this.jiraUseCase.getDocumentChapterData(projectKey, versionName)
1140-
if (docChapters.isEmpty() && !this.isVersioningEnabled) {
1141-
//TODO remove for ODS 4.0
1142-
//If versioning is not enabled, the query should always return results. If not, there is an issue with
1143-
// the jira project itself.
1144-
throw new IllegalStateException("Error: could not find document chapters for project ${projectKey}.")
1145-
} else {
1146-
return docChapters
1147-
}
1096+
return docChapters
11481097
}
11491098

11501099
protected Map loadJiraDataForCurrentVersion(String projectKey, String versionName) {

test/groovy/org/ods/orchestration/service/JiraServiceSpec.groovy

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,10 +1008,11 @@ class JiraServiceSpec extends SpecHelper {
10081008
}
10091009

10101010

1011-
Map getDocGenDataRequestData(Map mixins = [:]) {
1011+
Map getDeltaDocGenDataRequestData(Map mixins = [:]) {
10121012
def result = [
10131013
data: [
1014-
projectKey: "DEMO"
1014+
projectKey: "DEMO",
1015+
version: "1.0"
10151016
],
10161017
headers: [
10171018
"Accept": "application/json"
@@ -1020,12 +1021,12 @@ class JiraServiceSpec extends SpecHelper {
10201021
username: "username"
10211022
]
10221023

1023-
result.path = "/rest/platform/1.0/docgenreports/${result.data.projectKey}"
1024+
result.path = "/rest/platform/1.1/deltadocgenreports/${result.data.projectKey}/${result.data.version}"
10241025

10251026
return result << mixins
10261027
}
10271028

1028-
Map getDocGenDataResponseData(Map mixins = [:]) {
1029+
Map getDeltaDocGenDataResponseData(Map mixins = [:]) {
10291030
def result = [
10301031
body: JsonOutput.toJson([
10311032
project: [:],
@@ -1042,14 +1043,14 @@ class JiraServiceSpec extends SpecHelper {
10421043

10431044
def "get doc gen data with invalid project key"() {
10441045
given:
1045-
def request = getDocGenDataRequestData()
1046-
def response = getDocGenDataResponseData()
1046+
def request = getDeltaDocGenDataRequestData()
1047+
def response = getDeltaDocGenDataResponseData()
10471048

10481049
def server = createServer(WireMock.&get, request, response)
10491050
def service = createService(server.port(), request.username, request.password)
10501051

10511052
when:
1052-
def result = service.getDocGenData(null)
1053+
def result = service.getDeltaDocGenData(null, request.data.version)
10531054

10541055
then:
10551056
def e = thrown(IllegalArgumentException)
@@ -1061,14 +1062,14 @@ class JiraServiceSpec extends SpecHelper {
10611062

10621063
def "get doc gen data"() {
10631064
given:
1064-
def request = getDocGenDataRequestData()
1065-
def response = getDocGenDataResponseData()
1065+
def request = getDeltaDocGenDataRequestData()
1066+
def response = getDeltaDocGenDataResponseData()
10661067

10671068
def server = createServer(WireMock.&get, request, response)
10681069
def service = createService(server.port(), request.username, request.password)
10691070

10701071
when:
1071-
def result = service.getDocGenData("DEMO")
1072+
def result = service.getDeltaDocGenData("DEMO", request.data.version)
10721073

10731074
then:
10741075
result == [
@@ -1085,8 +1086,8 @@ class JiraServiceSpec extends SpecHelper {
10851086

10861087
def "get doc gen data with HTTP 400 failure"() {
10871088
given:
1088-
def request = getDocGenDataRequestData()
1089-
def response = getDocGenDataResponseData([
1089+
def request = getDeltaDocGenDataRequestData()
1090+
def response = getDeltaDocGenDataResponseData([
10901091
body: "Sorry, doesn't work!",
10911092
status: 400
10921093
])
@@ -1095,7 +1096,7 @@ class JiraServiceSpec extends SpecHelper {
10951096
def service = createService(server.port(), request.username, request.password)
10961097

10971098
when:
1098-
service.getDocGenData("DEMO")
1099+
service.getDeltaDocGenData("DEMO", request.data.version)
10991100

11001101
then:
11011102
def e = thrown(RuntimeException)
@@ -1107,16 +1108,16 @@ class JiraServiceSpec extends SpecHelper {
11071108

11081109
def "get doc gen data with HTTP 404 failure"() {
11091110
given:
1110-
def request = getDocGenDataRequestData()
1111-
def response = getDocGenDataResponseData([
1111+
def request = getDeltaDocGenDataRequestData()
1112+
def response = getDeltaDocGenDataResponseData([
11121113
status: 404
11131114
])
11141115

11151116
def server = createServer(WireMock.&get, request, response)
11161117
def service = createService(server.port(), request.username, request.password)
11171118

11181119
when:
1119-
service.getDocGenData("DEMO")
1120+
service.getDeltaDocGenData("DEMO", request.data.version)
11201121

11211122
then:
11221123
def e = thrown(RuntimeException)
@@ -1128,8 +1129,8 @@ class JiraServiceSpec extends SpecHelper {
11281129

11291130
def "get doc gen data with HTTP 500 failure"() {
11301131
given:
1131-
def request = getDocGenDataRequestData()
1132-
def response = getDocGenDataResponseData([
1132+
def request = getDeltaDocGenDataRequestData()
1133+
def response = getDeltaDocGenDataResponseData([
11331134
body: "Sorry, doesn't work!",
11341135
status: 500
11351136
])
@@ -1138,7 +1139,7 @@ class JiraServiceSpec extends SpecHelper {
11381139
def service = createService(server.port(), request.username, request.password)
11391140

11401141
when:
1141-
service.getDocGenData("DEMO")
1142+
service.getDeltaDocGenData("DEMO", request.data.version)
11421143

11431144
then:
11441145
def e = thrown(RuntimeException)

0 commit comments

Comments
 (0)