Skip to content

Commit

Permalink
JENKINS-46482 Return String instead of StringParameterValue.
Browse files Browse the repository at this point in the history
  • Loading branch information
ceilfors committed Sep 1, 2017
1 parent 08d6145 commit 2535481
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 30 deletions.
Expand Up @@ -23,7 +23,7 @@ class ParameterMappingAction implements EnvironmentContributingAction {
void buildEnvVars(AbstractBuild<?, ?> build, EnvVars env) {
parameterMappings.each { parameterMapping ->
env.put(parameterMapping.jenkinsParameter,
parameterMapping.parameterResolver.resolve(issue).value as String)
parameterMapping.parameterResolver.resolve(issue))
}
}

Expand Down
Expand Up @@ -3,7 +3,6 @@ package com.ceilfors.jenkins.plugins.jiratrigger.parameter
import com.atlassian.jira.rest.client.api.domain.Issue
import com.atlassian.jira.rest.client.api.domain.IssueField
import com.ceilfors.jenkins.plugins.jiratrigger.JiraTriggerException
import hudson.model.StringParameterValue
import org.codehaus.jettison.json.JSONArray
import org.codehaus.jettison.json.JSONObject

Expand All @@ -19,11 +18,11 @@ class CustomFieldParameterResolver implements ParameterResolver {
this.customFieldParameterMapping = customFieldParameterMapping
}

StringParameterValue resolve(Issue issue) {
String resolve(Issue issue) {
String customFieldId = "customfield_${customFieldParameterMapping.customFieldId}"
IssueField field = issue.fields.toList().find { f -> f.id == customFieldId }
if (field) {
new StringParameterValue(customFieldParameterMapping.jenkinsParameter, extractValue(field))
extractValue(field)
} else {
throw new JiraTriggerException(ParameterErrorCode.FAILED_TO_RESOLVE)
.add('customFieldId', customFieldId)
Expand Down
Expand Up @@ -2,7 +2,6 @@ package com.ceilfors.jenkins.plugins.jiratrigger.parameter

import com.atlassian.jira.rest.client.api.domain.Issue
import com.ceilfors.jenkins.plugins.jiratrigger.JiraTriggerException
import hudson.model.StringParameterValue

/**
* @author ceilfors
Expand All @@ -15,9 +14,8 @@ class IssueAttributePathParameterResolver implements ParameterResolver {
this.issueAttributePathParameterMapping = issueAttributePathParameterMapping
}

StringParameterValue resolve(Issue issue) {
String attributeValue = resolveProperty(issue.properties, issueAttributePathParameterMapping.issueAttributePath)
new StringParameterValue(issueAttributePathParameterMapping.jenkinsParameter, attributeValue)
String resolve(Issue issue) {
resolveProperty(issue.properties, issueAttributePathParameterMapping.issueAttributePath)
}

/**
Expand Down
@@ -1,14 +1,12 @@
package com.ceilfors.jenkins.plugins.jiratrigger.parameter

import com.atlassian.jira.rest.client.api.domain.Issue
import hudson.model.StringParameterValue

/**
* Responsible for providing a parameter value for Jenkins by digesting JIRA information.
*
* @author ceilfors
*/
interface ParameterResolver {

StringParameterValue resolve(Issue issue)
String resolve(Issue issue)
}
Expand Up @@ -3,7 +3,6 @@ package com.ceilfors.jenkins.plugins.jiratrigger.parameter
import com.atlassian.jira.rest.client.api.domain.Issue
import com.ceilfors.jenkins.plugins.jiratrigger.JiraTriggerException
import com.ceilfors.jenkins.plugins.jiratrigger.webhook.WebhookChangelogEventJsonParser
import hudson.model.StringParameterValue
import org.codehaus.jettison.json.JSONObject
import spock.lang.Specification
import spock.lang.Unroll
Expand All @@ -24,12 +23,10 @@ class CustomFieldParameterResolverTest extends Specification {
when:
CustomFieldParameterMapping mapping = new CustomFieldParameterMapping('parameter', customFieldId)
CustomFieldParameterResolver subject = new CustomFieldParameterResolver(mapping)
StringParameterValue result = subject.resolve(createIssueFromFile('single_value_custom_field'))
String result = subject.resolve(createIssueFromFile('single_value_custom_field'))

then:
result != null
result.value == attributeValue
result.name == 'parameter'
result == attributeValue

where:
customFieldType | customFieldId | attributeValue
Expand All @@ -54,12 +51,10 @@ class CustomFieldParameterResolverTest extends Specification {
when:
CustomFieldParameterMapping mapping = new CustomFieldParameterMapping('parameter', customFieldId)
CustomFieldParameterResolver subject = new CustomFieldParameterResolver(mapping)
StringParameterValue result = subject.resolve(createIssueFromFile('multi_value_custom_field'))
String result = subject.resolve(createIssueFromFile('multi_value_custom_field'))

then:
result != null
result.value == attributeValue
result.name == 'parameter'
result == attributeValue

where:
customFieldType | customFieldId | attributeValue
Expand All @@ -75,12 +70,10 @@ class CustomFieldParameterResolverTest extends Specification {
when:
CustomFieldParameterMapping mapping = new CustomFieldParameterMapping('parameter', customFieldId)
CustomFieldParameterResolver subject = new CustomFieldParameterResolver(mapping)
StringParameterValue result = subject.resolve(createIssueFromFile('empty_custom_field'))
String result = subject.resolve(createIssueFromFile('empty_custom_field'))

then:
result != null
result.value == attributeValue
result.name == 'parameter'
result == attributeValue

where:
customFieldType | customFieldId | attributeValue
Expand Down
Expand Up @@ -3,7 +3,6 @@ package com.ceilfors.jenkins.plugins.jiratrigger.parameter
import com.atlassian.jira.rest.client.api.domain.Issue
import com.atlassian.jira.rest.client.internal.json.IssueJsonParser
import com.ceilfors.jenkins.plugins.jiratrigger.JiraTriggerException
import hudson.model.StringParameterValue
import org.codehaus.jettison.json.JSONObject
import spock.lang.Specification
import spock.lang.Unroll
Expand All @@ -25,12 +24,10 @@ class IssueAttributePathParameterResolverTest extends Specification {
IssueAttributePathParameterResolver resolver = new IssueAttributePathParameterResolver(mapping)

when:
StringParameterValue result = resolver.resolve(createIssueFromFile('TEST-136'))
String result = resolver.resolve(createIssueFromFile('TEST-136'))

then:
result != null
result.value == attributeValue
result.name == 'parameter'
result == attributeValue

where:
attributePath | attributeValue
Expand All @@ -49,7 +46,6 @@ class IssueAttributePathParameterResolverTest extends Specification {
IssueAttributePathParameterResolver resolver = new IssueAttributePathParameterResolver(mapping)

when:

resolver.resolve(createIssueFromFile('TEST-136'))

then:
Expand Down

0 comments on commit 2535481

Please sign in to comment.