Skip to content

Commit 9e1f8a2

Browse files
authored
handle converting pr to/from draft (#13)
* handle converting pr to/from draft * extend WIP regex to other common cases
1 parent f68df57 commit 9e1f8a2

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/handlers/checkSuite.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default (app: Probot) => {
1212

1313
const pr = await PullRequest.getFromNumber(context, prNum);
1414

15-
if (pr.wip) return;
15+
if (pr.wip || pr.data.draft) return;
1616

1717
const suites = (
1818
await context.octokit.checks.listSuitesForRef({

src/handlers/pullRequest.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { Probot } from 'probot';
2+
3+
import { labels } from '../labels.js';
24
import PullRequest from '../classes/PullRequest.js';
35

46
export default (app: Probot) => {
@@ -7,7 +9,7 @@ export default (app: Probot) => {
79

810
let title = pr.data.title;
911

10-
if (!pr.wip) {
12+
if (!pr.wip && !pr.data.draft) {
1113
title = `[WIP] ${title}`;
1214
await pr.setTitle(title);
1315
}
@@ -36,4 +38,18 @@ export default (app: Probot) => {
3638
await pr.clearLabels();
3739
}
3840
});
41+
42+
app.on(['pull_request.converted_to_draft'], async context => {
43+
const pr = new PullRequest(context);
44+
await pr.addLabel('wip');
45+
});
46+
47+
app.on(['pull_request.ready_for_review'], async context => {
48+
const pr = new PullRequest(context);
49+
50+
const title = pr.data.title.replace(labels.wip.regex ?? '', '');
51+
await pr.setTitle(title);
52+
53+
await pr.addLabel('readyForReview');
54+
});
3955
};

src/labels.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type Label = {
77

88
export const labels: Record<string, Label> = {
99
wip: {
10-
regex: /^\[WIP\]\s/i,
10+
regex: /^\s*(\[WIP\]\s*|WIP:\s*|WIP\s+)+/i,
1111
name: ':construction: WIP',
1212
color: '#FBCA04',
1313
description: 'Still under development, not yet ready for review',

0 commit comments

Comments
 (0)