-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathenforce-draft.js
More file actions
50 lines (45 loc) · 1.61 KB
/
enforce-draft.js
File metadata and controls
50 lines (45 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// @ts-check
/**
* Labels a PR that was converted to draft and leaves an informational comment.
* Skips if a bot comment already exists (to avoid duplicates on reopen).
*
* @param {object} params
* @param {import('@actions/github').getOctokit} params.github
* @param {import('@actions/github').context} params.context
* @param {import('@actions/core')} params.core
*/
module.exports = async ({ github, context, core }) => {
const pullRequest = context.payload.pull_request;
const repo = context.repo;
await github.rest.issues.addLabels({
...repo,
issue_number: pullRequest.number,
labels: ['converted-to-draft'],
});
// Check for existing bot comment to avoid duplicates on reopen
const comments = await github.rest.issues.listComments({
...repo,
issue_number: pullRequest.number,
});
const botComment = comments.data.find(c =>
c.user.type === 'Bot' &&
c.body.includes('automatically converted to draft')
);
if (botComment) {
core.info('Bot comment already exists, skipping.');
return;
}
const contributingUrl = `https://github.com/${repo.owner}/${repo.repo}/blob/${context.payload.repository.default_branch}/CONTRIBUTING.md`;
await github.rest.issues.createComment({
...repo,
issue_number: pullRequest.number,
body: [
`This PR has been automatically converted to draft. All PRs must start as drafts per our [contributing guidelines](${contributingUrl}).`,
'',
'**Next steps:**',
'1. Ensure CI passes',
'2. Fill in the PR description completely',
'3. Mark as "Ready for review" when you\'re done',
].join('\n'),
});
};