Skip to content

Commit

Permalink
Remove deprecated code and fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zxBCN Farre_Basurte,Juan_Antonio (IT EDS) EXTERNAL committed Jan 22, 2022
1 parent f247054 commit 9af90bc
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 381 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
- RM: test component causes new jenkins (run) instance after branch is created for release
([#823](https://github.com/opendevstack/ods-jenkins-shared-library/issues/823))
- 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))
- Remove support for EDP 1.0 projects in the Release Manager ([#748](https://github.com/opendevstack/ods-jenkins-shared-library/pull/748))

## [3.0] - 2020-08-11

Expand Down
67 changes: 0 additions & 67 deletions src/org/ods/orchestration/service/JiraService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -240,34 +240,6 @@ class JiraService {
return createIssueType("Bug", projectKey, summary, description, fixVersion)
}

@NonCPS
Map getDocGenData(String projectKey) {
if (!projectKey?.trim()) {
throw new IllegalArgumentException('Error: unable to get documentation generation data from Jira. ' +
'\'projectKey\' is undefined.')
}

def response = Unirest.get("${this.baseURL}/rest/platform/1.0/docgenreports/{projectKey}")
.routeParam("projectKey", projectKey.toUpperCase())
.basicAuth(this.username, this.password)
.header("Accept", "application/json")
.asString()

response.ifFailure {
def message = 'Error: unable to get documentation generation data. Jira responded with code: ' +
"'${response.getStatus()}' and message: '${response.getBody()}'."

if (response.getStatus() == 404) {
message = 'Error: unable to get documentation generation data. ' +
"Jira could not be found at: '${this.baseURL}'."
}

throw new RuntimeException(message)
}

return new JsonSlurperClassic().parseText(StringCleanup.removeCharacters(response.getBody(), CHARACTER_REMOVEABLE))
}

@NonCPS
Map getDeltaDocGenData(String projectKey, String version) {
if (!projectKey?.trim()) {
Expand Down Expand Up @@ -685,43 +657,4 @@ class JiraService {
new JsonSlurperClassic().parseText(response.getBody()).getOrDefault("fields", [:])
}

@NonCPS
Boolean isVersionEnabledForDelta(String projectKey, String versionName) {
if (!projectKey?.trim()) {
throw new IllegalArgumentException('Error: unable to check project versions from Jira. ' +
'\'projectKey\' is undefined.')
}

if (!versionName?.trim()) {
throw new IllegalArgumentException('Error: unable to check project versions from Jira. ' +
'\'versionName\' is undefined.')
}

def response = Unirest.get("${this.baseURL}/rest/platform/1.1/productreleases/{projectKey}/versions/{version}")
.routeParam('projectKey', projectKey.toUpperCase())
.routeParam('version', versionName)
.basicAuth(this.username, this.password)
.header('Accept', 'application/json')
.asString()

response.ifFailure {
if (response.getStatus() == 400) {
if(response.getBody().contains("Invalid project versionName.")) {
return false
}
}
def message = 'Error: unable to get project versions in url ' +
"${this.baseURL}/rest/platform/1.1/productreleases/${projectKey.toUpperCase()}/versions/${versionName}" +
' Jira responded with code: ' +
"'${response.getStatus()}' and message: '${response.getBody()}'."

if (response.getStatus() == 404) {
message = "Error: unable to get project versions. Jira could not be found at: '${this.baseURL}'."
}

throw new RuntimeException(message)
}
return true
}

}
39 changes: 13 additions & 26 deletions src/org/ods/orchestration/usecase/LeVADocumentUseCase.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1649,14 +1649,8 @@ class LeVADocumentUseCase extends DocGenUseCase {
def documentationTrackingIssueFields = this.project.getJiraFieldsForIssueType(JiraUseCase.IssueTypes.DOCUMENTATION_TRACKING)
def documentationTrackingIssueDocumentVersionField = documentationTrackingIssueFields[JiraUseCase.CustomIssueFields.DOCUMENT_VERSION]

if (this.project.isVersioningEnabled) {
if (!this.project.isDeveloperPreviewMode() && !this.project.hasWipJiraIssues()) {
// In case of generating a final document, we add the label for the version that should be released
this.jiraUseCase.jira.updateTextFieldsOnIssue(jiraIssueKey,
[(documentationTrackingIssueDocumentVersionField.id): "${docVersionId}"])
}
} else {
// TODO removeme for ODS 4.0
if (!this.project.isDeveloperPreviewMode() && !this.project.hasWipJiraIssues()) {
// In case of generating a final document, we add the label for the version that should be released
this.jiraUseCase.jira.updateTextFieldsOnIssue(jiraIssueKey,
[(documentationTrackingIssueDocumentVersionField.id): "${docVersionId}"])
}
Expand Down Expand Up @@ -1761,25 +1755,18 @@ class LeVADocumentUseCase extends DocGenUseCase {
}

protected String getVersion(Project project, String doc) {
def version

if (project.isVersioningEnabled) {
version = project.getDocumentVersionFromHistories(doc)
if (!version) {
// The document has not (yet) been generated in this pipeline run.
def envs = Environment.values().collect { it.toString() }
def trackingIssues = this.getDocumentTrackingIssuesForHistory(doc, envs)
version = this.jiraUseCase.getLatestDocVersionId(trackingIssues)
if (project.isWorkInProgress ||
LeVADocumentScheduler.getFirstCreationEnvironment(doc) ==
project.buildParams.targetEnvironmentToken ) {
// Either this is a developer preview or the history is to be updated in this environment.
version += 1L
}
def version = project.getDocumentVersionFromHistories(doc)
if (!version) {
// The document has not (yet) been generated in this pipeline run.
def envs = Environment.values().collect { it.toString() }
def trackingIssues = this.getDocumentTrackingIssuesForHistory(doc, envs)
version = this.jiraUseCase.getLatestDocVersionId(trackingIssues)
if (project.isWorkInProgress ||
LeVADocumentScheduler.getFirstCreationEnvironment(doc) ==
project.buildParams.targetEnvironmentToken ) {
// Either this is a developer preview or the history is to be updated in this environment.
version += 1L
}
} else {
// TODO removeme in ODS 4.x
version = "${project.buildParams.version}-${this.steps.env.BUILD_NUMBER}"
}

if (project.isWorkInProgress) {
Expand Down
61 changes: 5 additions & 56 deletions src/org/ods/orchestration/util/Project.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ class Project {
protected ILogger logger
protected Map config
protected String targetProject
protected Boolean isVersioningEnabled = false

protected Map data = [:]

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

def version = null
if (this.isVersioningEnabled) {
version = this.getVersionName()
}
def version = this.getVersionName()

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

boolean getIsVersioningEnabled() {
isVersioningEnabled
}

static boolean isPromotionMode(String targetEnvironmentToken) {
['Q', 'P'].contains(targetEnvironmentToken)
}
Expand Down Expand Up @@ -1058,23 +1050,6 @@ class Project {
]
}

/**
* Checks if the JIRA version supports the versioning feature
* If jira or JiraUsecase is not enabled -> false
* If templates version is 1.0 -> false
* Otherwise, check from Jira
* @ true if versioning is enabled
*/
boolean checkIfVersioningIsEnabled(String projectKey, String versionName) {
if (!this.jiraUseCase) return false
if (!this.jiraUseCase.jira) return false
def levaDocsCapability = this.getCapability('LeVADocs')
if (levaDocsCapability.templatesVersion == '1.0') {
return false
}
return this.jiraUseCase.jira.isVersionEnabledForDelta(projectKey, versionName)
}

protected Map loadJiraData(String projectKey) {
def result = [
components: [:],
Expand All @@ -1092,16 +1067,8 @@ class Project {
// than once. However, it's also called via this.project.versionFromReleaseStatusIssue in JiraUseCase.groovy.
def currentVersion = this.getVersionFromReleaseStatusIssue() // TODO why is param.version not sufficient here?

this.isVersioningEnabled = this.checkIfVersioningIsEnabled(projectKey, currentVersion)
if (this.isVersioningEnabled) {
// We detect the correct version even if the build is WIP
logger.info("Project has versioning enabled.")
result = this.loadJiraDataForCurrentVersion(projectKey, currentVersion)
} else {
// TODO remove in ODS 4.0 version
logger.info("Versioning not supported for this release")
result = this.loadFullJiraData(projectKey)
}
// We detect the correct version even if the build is WIP
result = this.loadJiraDataForCurrentVersion(projectKey, currentVersion)
}

return result
Expand All @@ -1112,17 +1079,6 @@ class Project {
return this.jiraUseCase.getVersionFromReleaseStatusIssue()
}

protected Map loadFullJiraData(String projectKey) {
def result = this.jiraUseCase.jira.getDocGenData(projectKey)
if (result?.project?.id == null) {
throw new IllegalArgumentException(
"Error: unable to load documentation generation data from Jira. 'project.id' is undefined.")
}
def docChapterData = this.getDocumentChapterData(projectKey)
result << [(JiraDataItem.TYPE_DOCS as String): docChapterData]
return result
}

protected Map loadVersionJiraData(String projectKey, String versionName) {
def result = this.jiraUseCase.jira.getDeltaDocGenData(projectKey, versionName)
if (result?.project?.id == null) {
Expand All @@ -1135,16 +1091,9 @@ class Project {
return result
}

protected Map<String, Map> getDocumentChapterData(String projectKey, String versionName = null) {
protected Map<String, Map> getDocumentChapterData(String projectKey, String versionName) {
def docChapters = this.jiraUseCase.getDocumentChapterData(projectKey, versionName)
if (docChapters.isEmpty() && !this.isVersioningEnabled) {
//TODO remove for ODS 4.0
//If versioning is not enabled, the query should always return results. If not, there is an issue with
// the jira project itself.
throw new IllegalStateException("Error: could not find document chapters for project ${projectKey}.")
} else {
return docChapters
}
return docChapters
}

protected Map loadJiraDataForCurrentVersion(String projectKey, String versionName) {
Expand Down
39 changes: 20 additions & 19 deletions test/groovy/org/ods/orchestration/service/JiraServiceSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1008,10 +1008,11 @@ class JiraServiceSpec extends SpecHelper {
}


Map getDocGenDataRequestData(Map mixins = [:]) {
Map getDeltaDocGenDataRequestData(Map mixins = [:]) {
def result = [
data: [
projectKey: "DEMO"
projectKey: "DEMO",
version: "1.0"
],
headers: [
"Accept": "application/json"
Expand All @@ -1020,12 +1021,12 @@ class JiraServiceSpec extends SpecHelper {
username: "username"
]

result.path = "/rest/platform/1.0/docgenreports/${result.data.projectKey}"
result.path = "/rest/platform/1.1/deltadocgenreports/${result.data.projectKey}/${result.data.version}"

return result << mixins
}

Map getDocGenDataResponseData(Map mixins = [:]) {
Map getDeltaDocGenDataResponseData(Map mixins = [:]) {
def result = [
body: JsonOutput.toJson([
project: [:],
Expand All @@ -1042,14 +1043,14 @@ class JiraServiceSpec extends SpecHelper {

def "get doc gen data with invalid project key"() {
given:
def request = getDocGenDataRequestData()
def response = getDocGenDataResponseData()
def request = getDeltaDocGenDataRequestData()
def response = getDeltaDocGenDataResponseData()

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

when:
def result = service.getDocGenData(null)
def result = service.getDeltaDocGenData(null, request.data.version)

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

def "get doc gen data"() {
given:
def request = getDocGenDataRequestData()
def response = getDocGenDataResponseData()
def request = getDeltaDocGenDataRequestData()
def response = getDeltaDocGenDataResponseData()

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

when:
def result = service.getDocGenData("DEMO")
def result = service.getDeltaDocGenData("DEMO", request.data.version)

then:
result == [
Expand All @@ -1085,8 +1086,8 @@ class JiraServiceSpec extends SpecHelper {

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

when:
service.getDocGenData("DEMO")
service.getDeltaDocGenData("DEMO", request.data.version)

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

def "get doc gen data with HTTP 404 failure"() {
given:
def request = getDocGenDataRequestData()
def response = getDocGenDataResponseData([
def request = getDeltaDocGenDataRequestData()
def response = getDeltaDocGenDataResponseData([
status: 404
])

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

when:
service.getDocGenData("DEMO")
service.getDeltaDocGenData("DEMO", request.data.version)

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

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

when:
service.getDocGenData("DEMO")
service.getDeltaDocGenData("DEMO", request.data.version)

then:
def e = thrown(RuntimeException)
Expand Down
Loading

0 comments on commit 9af90bc

Please sign in to comment.