diff --git a/api/actions/__test__/createWorkItem.spec.js b/api/actions/__test__/createWorkItem.spec.js index 0c99b86..1a16278 100644 --- a/api/actions/__test__/createWorkItem.spec.js +++ b/api/actions/__test__/createWorkItem.spec.js @@ -56,8 +56,7 @@ const req = { html_url: 'github/git2gus-test/#30', title: 'new issue', body: '### some title\nsome description', - number: 30, - labels: [{ name: 'BUG P1' }] + number: 30 }, label: 'BUG P1', repository: { @@ -87,7 +86,7 @@ const reqWithProductTagLabel = { title: 'new issue', body: 'some description', number: 30, - labels: [{ name: 'BUG P1' }, { name: 'testTagLabel' }] + labels: [{ name: 'testTagLabel' }] }, label: 'BUG P1', repository: { @@ -121,7 +120,7 @@ const reqWithOnlyProductTagLabels = { title: 'new issue', body: 'some description', number: 30, - labels: [{ name: 'BUG P1' }, { name: 'notAProductTagLabel' }] + labels: [{ name: 'notAProductTagLabel' }] }, label: 'BUG P1', repository: { @@ -154,7 +153,7 @@ const reqWithIssueTypeLabels = { title: 'new issue', body: 'some description', number: 30, - labels: [{ name: 'feature' }, { name: 'notAValidLabel' }] + labels: [{ name: 'notAValidLabel' }] }, label: 'feature', repository: { @@ -187,7 +186,7 @@ const reqWithIssueTypeUserStory = { title: 'new feature request', body: 'some description', number: 30, - labels: [{ name: 'feature' }, { name: 'notAValidLabel' }] + labels: [{ name: 'notAValidLabel' }] }, label: 'feature', repository: { @@ -219,8 +218,7 @@ const reqWithGusTitlePrefix = { html_url: 'github/git2gus-test/#30', title: 'new issue', body: 'some description', - number: 30, - labels: [{ name: 'BUG P1' }] + number: 30 }, label: 'BUG P1', repository: { diff --git a/api/actions/createWorkItem.js b/api/actions/createWorkItem.js index b7f762a..8661db5 100644 --- a/api/actions/createWorkItem.js +++ b/api/actions/createWorkItem.js @@ -25,6 +25,8 @@ module.exports = { let { issue: { title } } = req.body; + // Only grab the label being added for comparison against Salesforce labels + const { label : labelAdded } = req.body; const { config } = req.git2gus; const { hideWorkItemUrl } = config; let productTag = config.productTag; @@ -39,6 +41,10 @@ module.exports = { if(config.issueTypeLabels) { console.log('createWorkItem will work with custom issueTypeLabels for issue titled: ', title); Object.keys(config.issueTypeLabels).forEach(issueTypeLabel => { + // If the label added is a Salesforce custom label, give it the correct base label + if (labelAdded.name === issueTypeLabel) { + labelAdded.name = config.issueTypeLabels[issueTypeLabel]; + } if (labels.some(label => label.name === issueTypeLabel)) { labels.push({name: config.issueTypeLabels[issueTypeLabel]}); } @@ -47,7 +53,8 @@ module.exports = { let normalizedTitle = getTitleWithOptionalPrefix(config, title); console.log('createWorkItem will create GUS work item with title: ', normalizedTitle); - if (labels.some(label => Github.isSalesforceLabel(label.name)) && productTag) { + // Only check the label being added + if (Github.isSalesforceLabel(labelAdded.name) && productTag) { console.log('Verified valid label and product tag for issue titled: ', title); const priority = Github.getPriority(labels); console.log(`Found priority: ${priority} for issue titled: ${title}`); @@ -107,4 +114,3 @@ module.exports = { return null; } }; -