Skip to content

Commit

Permalink
fix: only print stories and defects once
Browse files Browse the repository at this point in the history
  • Loading branch information
BearAlliance committed Nov 6, 2019
1 parent 371565e commit aa3dd6e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
42 changes: 42 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,46 @@ describe('rally', () => {
`**Defects Referenced:**\n - [DE123456](https://rally1.rallydev.com/#/search?keywords=DE123456)`
);
});

it('only prints defect references one time', () => {
global.danger = {
bitbucket_server: {
pr: {
title: 'My Test Title',
description: 'some description closes DE123456'
}
},
git: {
commits: [
{ message: 'chore: do something' },
{ message: 'contributes to DE123456' }
]
}
};
rally();
expect(global.markdown).toHaveBeenCalledWith(
`**Defects Referenced:**\n - [DE123456](https://rally1.rallydev.com/#/search?keywords=DE123456)`
);
});

it('only prints story references one time', () => {
global.danger = {
bitbucket_server: {
pr: {
title: 'My Test Title',
description: 'some description closes US1234567'
}
},
git: {
commits: [
{ message: 'chore: do something' },
{ message: 'contributes to US1234567' }
]
}
};
rally();
expect(global.markdown).toHaveBeenCalledWith(
`**Stories Referenced:**\n - [US1234567](https://rally1.rallydev.com/#/search?keywords=US1234567)`
);
});
});
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ export interface RallyPluginConfig {
domain?: string;
}

function unique(array: any[]) {
const seen: any[] = [];
return array.filter(item => {
const duplicate = seen.includes(item);
seen.push(item);
return !duplicate;
});
}

/**
* tools for linking rally stories to pull requests
*/
Expand All @@ -35,7 +44,7 @@ export default function rally(
);

if (storyNumbers) {
const output = storyNumbers.reduce(
const output = unique(storyNumbers).reduce(
(acc, storyNumber) =>
acc.concat(
`\n - [${storyNumber}](${domain}/#/search?keywords=${storyNumber})`
Expand All @@ -45,7 +54,7 @@ export default function rally(
markdown(output);
}
if (defectNumbers) {
const output = defectNumbers.reduce(
const output = unique(defectNumbers).reduce(
(acc, defectNumber) =>
acc.concat(
`\n - [${defectNumber}](${domain}/#/search?keywords=${defectNumber})`
Expand Down

0 comments on commit aa3dd6e

Please sign in to comment.