Skip to content

Commit 2c4ccf2

Browse files
authored
Merge pull request #5 from rimrul/aggregate-deduplication
Prevent duplicate issues for aggregated feeds
2 parents 6edc1cd + e15e714 commit 2c4ccf2

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Log issue creation but do nothing
3838

3939
Aggregate all items in a single issue
4040

41+
Note: If you use this Action to create issues from multiple aggregated feeds in the same repository, give them different prefixes and/or labels.
42+
4143
### `character-limit`
4244

4345
Limit the issue contents' size

dist/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38259,7 +38259,8 @@ const parseDurationInMilliseconds = (text) => {
3825938259

3826038260
const run = async () => {
3826138261
try {
38262-
const issueTitlePrefix = core.getInput('prefix')
38262+
let issueTitlePrefix = core.getInput('prefix')
38263+
issueTitlePrefix = issueTitlePrefix ? issueTitlePrefix + ' ' : ''
3826338264
let dryRun = core.getInput('dry-run')
3826438265
if (dryRun) dryRun = dryRun === 'true'
3826538266
let aggregate = core.getInput('aggregate')
@@ -38299,7 +38300,7 @@ const run = async () => {
3829938300

3830038301
// Iterate
3830138302
for (const item of feed.items) {
38302-
let title = `${issueTitlePrefix ? issueTitlePrefix + ' ' : ''}${item.title}`
38303+
let title = `${issueTitlePrefix}${item.title}`
3830338304
if (titlePattern && !title.match(titlePattern)) {
3830438305
core.debug(`Feed item skipped because it does not match the title pattern (${title})`)
3830538306
continue
@@ -38312,6 +38313,11 @@ const run = async () => {
3831238313
continue
3831338314
}
3831438315

38316+
if (aggregate && issues.find(x => x.title.startsWith(issueTitlePrefix) && Date.parse(x.created_at) > Date.parse(item.isoDate))) {
38317+
core.warning('Newer issue with same prefix already exists')
38318+
continue
38319+
}
38320+
3831538321
// Issue Content
3831638322
const content = item.content || item.description || ''
3831738323

@@ -38336,7 +38342,7 @@ const run = async () => {
3833638342
// Create Issue
3833738343
createdIssues.push({ title, body, labels })
3833838344
} else {
38339-
title = `${issueTitlePrefix ? issueTitlePrefix + ' ' : ''}${new Date().toTimeString()}`
38345+
title = `${issueTitlePrefix}${new Date().toTimeString()}`
3834038346
createdIssues[0].title = title
3834138347

3834238348
createdIssues[0].body += `\n\n${body}`

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ const parseDurationInMilliseconds = (text) => {
2222

2323
const run = async () => {
2424
try {
25-
const issueTitlePrefix = core.getInput('prefix')
25+
let issueTitlePrefix = core.getInput('prefix')
26+
issueTitlePrefix = issueTitlePrefix ? issueTitlePrefix + ' ' : ''
2627
let dryRun = core.getInput('dry-run')
2728
if (dryRun) dryRun = dryRun === 'true'
2829
let aggregate = core.getInput('aggregate')
@@ -62,7 +63,7 @@ const run = async () => {
6263

6364
// Iterate
6465
for (const item of feed.items) {
65-
let title = `${issueTitlePrefix ? issueTitlePrefix + ' ' : ''}${item.title}`
66+
let title = `${issueTitlePrefix}${item.title}`
6667
if (titlePattern && !title.match(titlePattern)) {
6768
core.debug(`Feed item skipped because it does not match the title pattern (${title})`)
6869
continue
@@ -75,6 +76,11 @@ const run = async () => {
7576
continue
7677
}
7778

79+
if (aggregate && issues.find(x => x.title.startsWith(issueTitlePrefix) && Date.parse(x.created_at) > Date.parse(item.isoDate))) {
80+
core.warning('Newer issue with same prefix already exists')
81+
continue
82+
}
83+
7884
// Issue Content
7985
const content = item.content || item.description || ''
8086

@@ -99,7 +105,7 @@ const run = async () => {
99105
// Create Issue
100106
createdIssues.push({ title, body, labels })
101107
} else {
102-
title = `${issueTitlePrefix ? issueTitlePrefix + ' ' : ''}${new Date().toTimeString()}`
108+
title = `${issueTitlePrefix}${new Date().toTimeString()}`
103109
createdIssues[0].title = title
104110

105111
createdIssues[0].body += `\n\n${body}`

0 commit comments

Comments
 (0)