Skip to content

Commit 903f399

Browse files
committed
Remove obsolete try/catch block
1 parent 317eaf6 commit 903f399

File tree

1 file changed

+49
-54
lines changed

1 file changed

+49
-54
lines changed

scripts/reporter/duplicate/index.js

Lines changed: 49 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,76 +3,71 @@ import config from 'config';
33
import { Octokit } from 'octokit';
44

55
async function removeDuplicateIssues() {
6-
try {
7-
const repository = config.get('@opentermsarchive/engine.reporter.githubIssues.repositories.declarations');
6+
const repository = config.get('@opentermsarchive/engine.reporter.githubIssues.repositories.declarations');
87

9-
if (!repository.includes('/') || repository.includes('https://')) {
10-
throw new Error(`Configuration entry "reporter.githubIssues.repositories.declarations" is expected to be a string in the format <owner>/<repo>, but received: "${repository}"`);
11-
}
8+
if (!repository.includes('/') || repository.includes('https://')) {
9+
throw new Error(`Configuration entry "reporter.githubIssues.repositories.declarations" is expected to be a string in the format <owner>/<repo>, but received: "${repository}"`);
10+
}
1211

13-
const [ owner, repo ] = repository.split('/');
12+
const [ owner, repo ] = repository.split('/');
1413

15-
const octokit = new Octokit({ auth: process.env.OTA_ENGINE_GITHUB_TOKEN });
14+
const octokit = new Octokit({ auth: process.env.OTA_ENGINE_GITHUB_TOKEN });
1615

17-
console.log(`Getting issues from repository ${repository}…`);
16+
console.log(`Getting issues from repository ${repository}…`);
1817

19-
const issues = await octokit.paginate('GET /repos/{owner}/{repo}/issues', {
20-
owner,
21-
repo,
22-
state: 'open',
23-
per_page: 100,
24-
});
18+
const issues = await octokit.paginate('GET /repos/{owner}/{repo}/issues', {
19+
owner,
20+
repo,
21+
state: 'open',
22+
per_page: 100,
23+
});
2524

26-
const onlyIssues = issues.filter(issue => !issue.pull_request);
27-
const issuesByTitle = new Map();
28-
let counter = 0;
25+
const onlyIssues = issues.filter(issue => !issue.pull_request);
26+
const issuesByTitle = new Map();
27+
let counter = 0;
2928

30-
console.log(`Found ${onlyIssues.length} issues`);
29+
console.log(`Found ${onlyIssues.length} issues`);
3130

32-
for (const issue of onlyIssues) {
33-
if (!issuesByTitle.has(issue.title)) {
34-
issuesByTitle.set(issue.title, [issue]);
35-
} else {
36-
issuesByTitle.get(issue.title).push(issue);
37-
}
31+
for (const issue of onlyIssues) {
32+
if (!issuesByTitle.has(issue.title)) {
33+
issuesByTitle.set(issue.title, [issue]);
34+
} else {
35+
issuesByTitle.get(issue.title).push(issue);
3836
}
37+
}
3938

40-
for (const [ title, duplicateIssues ] of issuesByTitle) {
41-
if (duplicateIssues.length === 1) continue;
42-
43-
const originalIssue = duplicateIssues.reduce((oldest, current) => (new Date(current.created_at) < new Date(oldest.created_at) ? current : oldest));
44-
45-
console.log(`\nFound ${duplicateIssues.length - 1} duplicates for issue #${originalIssue.number} "${title}"`);
46-
47-
for (const issue of duplicateIssues) {
48-
if (issue.number === originalIssue.number) {
49-
continue;
50-
}
39+
for (const [ title, duplicateIssues ] of issuesByTitle) {
40+
if (duplicateIssues.length === 1) continue;
5141

52-
await octokit.request('PATCH /repos/{owner}/{repo}/issues/{issue_number}', { /* eslint-disable-line no-await-in-loop */
53-
owner,
54-
repo,
55-
issue_number: issue.number,
56-
state: 'closed',
57-
});
42+
const originalIssue = duplicateIssues.reduce((oldest, current) => (new Date(current.created_at) < new Date(oldest.created_at) ? current : oldest));
5843

59-
await octokit.request('POST /repos/{owner}/{repo}/issues/{issue_number}/comments', { /* eslint-disable-line no-await-in-loop */
60-
owner,
61-
repo,
62-
issue_number: issue.number,
63-
body: `This issue is detected as duplicate as it has the same title as #${originalIssue.number}. It most likely was created accidentally by an engine older than [v2.3.2](https://github.com/OpenTermsArchive/engine/releases/tag/v2.3.2). Closing automatically.`,
64-
});
44+
console.log(`\nFound ${duplicateIssues.length - 1} duplicates for issue #${originalIssue.number} "${title}"`);
6545

66-
counter++;
67-
console.log(`Closed issue #${issue.number}: ${issue.html_url}`);
46+
for (const issue of duplicateIssues) {
47+
if (issue.number === originalIssue.number) {
48+
continue;
6849
}
69-
}
7050

71-
console.log(`\nDuplicate removal process completed; ${counter} issues closed`);
72-
} catch (error) {
73-
console.log(`Failed to remove duplicate issues: ${error.stack}`);
74-
process.exit(1);
51+
await octokit.request('PATCH /repos/{owner}/{repo}/issues/{issue_number}', { /* eslint-disable-line no-await-in-loop */
52+
owner,
53+
repo,
54+
issue_number: issue.number,
55+
state: 'closed',
56+
});
57+
58+
await octokit.request('POST /repos/{owner}/{repo}/issues/{issue_number}/comments', { /* eslint-disable-line no-await-in-loop */
59+
owner,
60+
repo,
61+
issue_number: issue.number,
62+
body: `This issue is detected as duplicate as it has the same title as #${originalIssue.number}. It most likely was created accidentally by an engine older than [v2.3.2](https://github.com/OpenTermsArchive/engine/releases/tag/v2.3.2). Closing automatically.`,
63+
});
64+
65+
counter++;
66+
console.log(`Closed issue #${issue.number}: ${issue.html_url}`);
67+
}
7568
}
69+
70+
console.log(`\nDuplicate removal process completed; ${counter} issues closed`);
7671
}
7772

7873
removeDuplicateIssues();

0 commit comments

Comments
 (0)