diff --git a/lib/platform/github/index.js b/lib/platform/github/index.js index f4992d40302e026cde375f343fdbec6f08e25971..04dd8c66006454f584ffd2a2680cca6f4f39f1e2 100644 --- a/lib/platform/github/index.js +++ b/lib/platform/github/index.js @@ -602,8 +602,8 @@ async function getIssueList() { logger.debug('Retrieving issueList'); const res = await get( `repos/${config.parentRepo || - config.repository}/issues?filter=created&state=all&per_page=100&sort=updated`, - { paginate: true, useCache: false } + config.repository}/issues?filter=created&state=open&per_page=100&sort=updated`, + { useCache: false } ); // istanbul ignore if if (!is.array(res.body)) { @@ -612,7 +612,6 @@ async function getIssueList() { } config.issueList = res.body.map(i => ({ number: i.number, - state: i.state, title: i.title, })); logger.debug('Retrieved ' + config.issueList.length + ' issues'); @@ -623,9 +622,7 @@ async function getIssueList() { async function findIssue(title) { logger.debug(`findIssue(${title})`); try { - const [issue] = (await getIssueList()).filter( - i => i.state === 'open' && i.title === title - ); + const [issue] = (await getIssueList()).filter(i => i.title === title); if (!issue) { return null; } @@ -643,25 +640,20 @@ async function findIssue(title) { } } -async function ensureIssue(title, body, once = false) { +async function ensureIssue(title, body) { logger.debug(`ensureIssue()`); try { const issueList = await getIssueList(); const issues = issueList.filter(i => i.title === title).reverse(); if (issues.length) { if (issues.length > 1) { + logger.warn('Found duplicate issues'); for (const issue of issues.slice(1)) { - if (issue.state === 'open') { - logger.warn('Closing duplicate issue ' + issue.number); - await closeIssue(issue.number); - } + logger.debug('Closing duplicate issue ' + issue.number); + await closeIssue(issue.number); } } const [issue] = issues; - if (once && issue.state === 'closed') { - logger.debug('Issue is closed - skipping'); - return null; - } const issueBody = (await get( `repos/${config.parentRepo || config.repository}/issues/${issue.number}` )).body.body; @@ -678,13 +670,13 @@ async function ensureIssue(title, body, once = false) { return 'updated'; } } else { + logger.info('Issue created'); await get.post(`repos/${config.parentRepo || config.repository}/issues`, { body: { title, body, }, }); - logger.info('Issue created'); // reset issueList so that it will be fetched again as-needed delete config.issueList; return 'created'; @@ -715,7 +707,7 @@ async function ensureIssueClosing(title) { logger.debug(`ensureIssueClosing()`); const issueList = await getIssueList(); for (const issue of issueList) { - if (issue.state === 'open' && issue.title === title) { + if (issue.title === title) { await closeIssue(issue.number); logger.info({ number: issue.number }, 'Issue closed'); } diff --git a/lib/workers/repository/process/deprecated.js b/lib/workers/repository/process/deprecated.js index 67fe0380269798be39a2786f335a2a4b80e62095..2891c7401d9d4d35480132d569be536581bf6afb 100644 --- a/lib/workers/repository/process/deprecated.js +++ b/lib/workers/repository/process/deprecated.js @@ -49,8 +49,7 @@ async function raiseDeprecationWarnings(config, packageFiles) { if (config.dryRun) { logger.info('DRY-RUN: Ensure deprecation warning issue for ' + depName); } else { - const ensureOnce = true; - await platform.ensureIssue(issueTitle, issueBody, ensureOnce); + await platform.ensureIssue(issueTitle, issueBody); } } } diff --git a/test/platform/github/index.spec.js b/test/platform/github/index.spec.js index 9545da9b62210a8a466c23d0fa85aa2ccc382ee2..94495a99a7c9e81e8e899b0af06999b3a8e23cd6 100644 --- a/test/platform/github/index.spec.js +++ b/test/platform/github/index.spec.js @@ -1007,12 +1007,10 @@ describe('platform/github', () => { { number: 1, title: 'title-1', - state: 'open', }, { number: 2, title: 'title-2', - state: 'open', }, ], }); @@ -1028,67 +1026,26 @@ describe('platform/github', () => { { number: 1, title: 'title-1', - state: 'open', }, { number: 2, title: 'title-2', - state: 'open', }, ], })); const res = await github.ensureIssue('new-title', 'new-content'); expect(res).toEqual('created'); }); - it('creates issue if not ensuring only once', async () => { - get.mockImplementationOnce(() => ({ - body: [ - { - number: 1, - title: 'title-1', - state: 'closed', - }, - { - number: 2, - title: 'title-2', - state: 'open', - }, - ], - })); - const res = await github.ensureIssue('title-1', 'new-content'); - expect(res).toEqual(null); - }); - it('does not create issue if ensuring only once', async () => { - get.mockImplementationOnce(() => ({ - body: [ - { - number: 1, - title: 'title-1', - state: 'closed', - }, - { - number: 2, - title: 'title-2', - state: 'open', - }, - ], - })); - const once = true; - const res = await github.ensureIssue('title-1', 'new-content', once); - expect(res).toEqual(null); - }); it('updates issue', async () => { get.mockReturnValueOnce({ body: [ { number: 1, title: 'title-1', - state: 'open', }, { number: 2, title: 'title-2', - state: 'open', }, ], }); @@ -1102,12 +1059,10 @@ describe('platform/github', () => { { number: 1, title: 'title-1', - state: 'open', }, { number: 2, title: 'title-2', - state: 'open', }, ], }); @@ -1121,12 +1076,10 @@ describe('platform/github', () => { { number: 1, title: 'title-1', - state: 'open', }, { number: 2, title: 'title-1', - state: 'open', }, ], }); @@ -1142,12 +1095,10 @@ describe('platform/github', () => { { number: 1, title: 'title-1', - state: 'open', }, { number: 2, title: 'title-2', - state: 'open', }, ], })); diff --git a/test/workers/repository/process/__snapshots__/deprecated.spec.js.snap b/test/workers/repository/process/__snapshots__/deprecated.spec.js.snap index 9c947fce9b0c74496a34981b1752b764223cb7d5..ab0d3eaae9a2d13d6c4e2aefc7dbf881885df715 100644 --- a/test/workers/repository/process/__snapshots__/deprecated.spec.js.snap +++ b/test/workers/repository/process/__snapshots__/deprecated.spec.js.snap @@ -15,7 +15,6 @@ If you don't care about this, you can close this issue and not be warned about \ \`\`\` ", - true, ], ] `;