Skip to content

Commit

Permalink
Fix duplicate work items when adding labels in bulk ( #117 with tests) (
Browse files Browse the repository at this point in the history
#132)

* Fix duplicate work items when adding labels in bulk

* Update tests

Co-authored-by: Jesse Brack <[email protected]>
  • Loading branch information
jag-j and jessebrack authored Nov 20, 2021
1 parent 8f1efd5 commit 9df5aad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
14 changes: 6 additions & 8 deletions api/actions/__test__/createWorkItem.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down
10 changes: 8 additions & 2 deletions api/actions/createWorkItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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]});
}
Expand All @@ -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}`);
Expand Down Expand Up @@ -107,4 +114,3 @@ module.exports = {
return null;
}
};

0 comments on commit 9df5aad

Please sign in to comment.