From eb936b4236d4a7b751cfe40ec4a3b7cb16e5ddba Mon Sep 17 00:00:00 2001 From: mohd hassaan <sr.hassan23@gmail.com> Date: Wed, 1 May 2019 12:58:30 +0530 Subject: [PATCH] fix: autoclose resolved deprecated issues (#3611) --- lib/platform/azure/index.js | 8 ++++++++ lib/platform/bitbucket-server/index.js | 8 ++++++++ lib/platform/bitbucket/index.js | 8 ++++++++ lib/platform/github/index.js | 1 + lib/platform/gitlab/index.js | 1 + lib/workers/repository/process/deprecated.js | 20 ++++++++++++++++++- .../platform/__snapshots__/index.spec.js.snap | 3 +++ .../repository/process/deprecated.spec.js | 8 ++++++++ 8 files changed, 56 insertions(+), 1 deletion(-) diff --git a/lib/platform/azure/index.js b/lib/platform/azure/index.js index f25b2873f5..08ec3e41b9 100644 --- a/lib/platform/azure/index.js +++ b/lib/platform/azure/index.js @@ -35,6 +35,7 @@ module.exports = { addAssignees, addReviewers, deleteLabel, + getIssueList, // Comments ensureComment, ensureCommentRemoval, @@ -481,6 +482,13 @@ function ensureIssue() { // istanbul ignore next function ensureIssueClosing() {} +// istanbul ignore next +function getIssueList() { + logger.debug(`getIssueList()`); + // TODO: Needs implementation + return []; +} + /** * * @param {number} issueNo diff --git a/lib/platform/bitbucket-server/index.js b/lib/platform/bitbucket-server/index.js index 77ca73f54f..f8737c52cf 100644 --- a/lib/platform/bitbucket-server/index.js +++ b/lib/platform/bitbucket-server/index.js @@ -37,6 +37,7 @@ module.exports = { addAssignees, addReviewers, deleteLabel, + getIssueList, // Comments ensureComment, ensureCommentRemoval, @@ -420,6 +421,13 @@ function ensureIssue(title, body) { return null; } +// istanbul ignore next +function getIssueList() { + logger.debug(`getIssueList()`); + // TODO: Needs implementation + return []; +} + // istanbul ignore next function ensureIssueClosing(title) { logger.debug(`ensureIssueClosing(${title})`); diff --git a/lib/platform/bitbucket/index.js b/lib/platform/bitbucket/index.js index 2b14cfe66e..829693bc54 100644 --- a/lib/platform/bitbucket/index.js +++ b/lib/platform/bitbucket/index.js @@ -35,6 +35,7 @@ module.exports = { addAssignees, addReviewers, deleteLabel, + getIssueList, // Comments ensureComment, ensureCommentRemoval, @@ -372,6 +373,13 @@ async function ensureIssue(title, body) { return null; } +// istanbul ignore next +function getIssueList() { + logger.debug(`getIssueList()`); + // TODO: Needs implementation + return []; +} + async function ensureIssueClosing(title) { const issues = await findOpenIssues(title); for (const issue of issues) { diff --git a/lib/platform/github/index.js b/lib/platform/github/index.js index a8614335d6..e037204200 100644 --- a/lib/platform/github/index.js +++ b/lib/platform/github/index.js @@ -46,6 +46,7 @@ module.exports = { addAssignees, addReviewers, deleteLabel, + getIssueList, // Comments ensureComment, ensureCommentRemoval, diff --git a/lib/platform/gitlab/index.js b/lib/platform/gitlab/index.js index 63c2d4308f..fa30840c2e 100644 --- a/lib/platform/gitlab/index.js +++ b/lib/platform/gitlab/index.js @@ -37,6 +37,7 @@ module.exports = { addAssignees, addReviewers, deleteLabel, + getIssueList, // Comments ensureComment, ensureCommentRemoval, diff --git a/lib/workers/repository/process/deprecated.js b/lib/workers/repository/process/deprecated.js index 67fe038026..585c4f3c26 100644 --- a/lib/workers/repository/process/deprecated.js +++ b/lib/workers/repository/process/deprecated.js @@ -28,7 +28,10 @@ async function raiseDeprecationWarnings(config, packageFiles) { } } } + logger.debug({ deprecatedPackages }); + const issueTitleList = []; + const issueTitlePrefix = 'Dependency deprecation warning:'; for (const [depName, val] of Object.entries(deprecatedPackages)) { const { deprecationMessage, depPackageFiles } = val; logger.info( @@ -39,7 +42,8 @@ async function raiseDeprecationWarnings(config, packageFiles) { }, 'dependency is deprecated' ); - const issueTitle = `Dependency deprecation warning: ${depName} (${manager})`; + const issueTitle = `${issueTitlePrefix} ${depName} (${manager})`; + issueTitleList.push(issueTitle); let issueBody = deprecationMessage; issueBody += `\n\nAffected package file(s): ${depPackageFiles .map(f => '`' + f + '`') @@ -53,5 +57,19 @@ async function raiseDeprecationWarnings(config, packageFiles) { await platform.ensureIssue(issueTitle, issueBody, ensureOnce); } } + logger.debug( + 'Checking for existing deprecated package issues missing in current deprecatedPackages' + ); + const issueList = await platform.getIssueList(); + if (issueList && issueList.length) { + const deprecatedIssues = issueList.filter( + i => i.title.startsWith(issueTitlePrefix) && i.state === 'open' + ); + for (const i of deprecatedIssues) { + if (!issueTitleList.includes(i.title)) { + await platform.ensureIssueClosing(i.title); + } + } + } } } diff --git a/test/platform/__snapshots__/index.spec.js.snap b/test/platform/__snapshots__/index.spec.js.snap index 2b4835616e..f38e1c5af3 100644 --- a/test/platform/__snapshots__/index.spec.js.snap +++ b/test/platform/__snapshots__/index.spec.js.snap @@ -25,6 +25,7 @@ Array [ "addAssignees", "addReviewers", "deleteLabel", + "getIssueList", "ensureComment", "ensureCommentRemoval", "getPrList", @@ -67,6 +68,7 @@ Array [ "addAssignees", "addReviewers", "deleteLabel", + "getIssueList", "ensureComment", "ensureCommentRemoval", "getPrList", @@ -109,6 +111,7 @@ Array [ "addAssignees", "addReviewers", "deleteLabel", + "getIssueList", "ensureComment", "ensureCommentRemoval", "getPrList", diff --git a/test/workers/repository/process/deprecated.spec.js b/test/workers/repository/process/deprecated.spec.js index 3db9cae53c..6db91efd0e 100644 --- a/test/workers/repository/process/deprecated.spec.js +++ b/test/workers/repository/process/deprecated.spec.js @@ -52,8 +52,16 @@ describe('workers/repository/process/deprecated', () => { }, ], }; + const mockIssue = [ + { + title: 'Dependency deprecation warning: mockDependency (mockManager)', + state: 'open', + }, + ]; + platform.getIssueList = jest.fn(() => mockIssue); await raiseDeprecationWarnings(config, packageFiles); expect(platform.ensureIssue.mock.calls).toMatchSnapshot(); + expect(platform.getIssueList).toHaveBeenCalledTimes(1); expect(platform.ensureIssue).toHaveBeenCalledTimes(1); }); }); -- GitLab