Skip to content

Commit d9e91f2

Browse files
authored
fix(github-actions): dynamic message for PR vs issue
1 parent bcac304 commit d9e91f2

2 files changed

Lines changed: 32 additions & 17 deletions

File tree

.github/local-actions/lock-closed/lib/main.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@ import {
88
} from '../../../../github-actions/utils.js';
99
import {setTimeout as setTimeoutPromise} from 'timers/promises';
1010

11+
/**
12+
* The URL of the policy. This is used to link to the policy from the lock message.
13+
*/
14+
const POLICY_URL =
15+
'https://github.com/angular/angular/blob/f0fbced1c55bc8b8ed9df01cea99df42f3e7eae3/contributing-docs/auto-issue-locking.md';
16+
17+
/**
18+
* Generates a lock message for a GitHub issue or pull request.
19+
* @param itemType The type of the item, either 'pull request' or 'issue'.
20+
* @returns The lock message string.
21+
*/
22+
function getLockMessage(itemType: 'pull request' | 'issue'): string {
23+
return `${itemType.charAt(0).toUpperCase() + itemType.slice(1)} has been automatically locked due to inactivity.
24+
Please file a new issue if you are encountering a similar or related problem.
25+
26+
Read more about our [automatic conversation locking policy](${POLICY_URL}).
27+
28+
<sub>_This action has been performed automatically by a bot._</sub>`;
29+
}
30+
1131
async function lockIssue(
1232
client: Octokit,
1333
issue: number,
@@ -58,15 +78,6 @@ async function runLockClosedAction(github: Octokit, repo: string): Promise<void>
5878

5979
// Fixed amount of days a closed issue must be inactive before being locked
6080
const days = 30;
61-
// Standardized Angular Team message for locking issues
62-
const policyUrl =
63-
'https://github.com/angular/angular/blob/f0fbced1c55bc8b8ed9df01cea99df42f3e7eae3/contributing-docs/auto-issue-locking.md';
64-
const message =
65-
'This issue has been automatically locked due to inactivity.\n' +
66-
'Please file a new issue if you are encountering a similar or related problem.\n\n' +
67-
`Read more about our [automatic conversation locking policy](${policyUrl}).\n\n` +
68-
'<sub>_This action has been performed automatically by a bot._</sub>';
69-
7081
// Set the threshold date based on the days inactive
7182
const threshold = new Date();
7283
threshold.setDate(threshold.getDate() - days);
@@ -100,6 +111,7 @@ async function runLockClosedAction(github: Octokit, repo: string): Promise<void>
100111
continue;
101112
}
102113
console.info(`Locking ${itemType} #${item.number}`);
114+
const message = getLockMessage(itemType);
103115
await lockIssue(github, item.number, repo, message);
104116
await setTimeoutPromise(250);
105117
++lockCount;

.github/local-actions/lock-closed/main.js

Lines changed: 11 additions & 8 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)