Skip to content

Commit b353eba

Browse files
committed
fix changesRequested label never clearing
1 parent 9e1f8a2 commit b353eba

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/classes/PullRequest.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import { Context, ProbotOctokit } from 'probot';
33
import { labels } from '../labels.js';
44

55
type TContext = Context<'pull_request' | 'pull_request_review'>;
6+
type ReviewStatus =
7+
| 'changesRequested'
8+
| 'needsMoreApprovals'
9+
| 'approved'
10+
| 'readyForReview';
611

712
type BarebonesContext = {
813
octokit: ProbotOctokit;
@@ -104,9 +109,7 @@ export default class PullRequest {
104109
}
105110
}
106111

107-
async getReviewStatus(): Promise<
108-
'changesRequested' | 'needsMoreApprovals' | 'approved' | undefined
109-
> {
112+
async getReviewStatus(): Promise<ReviewStatus> {
110113
const reviews = (
111114
await this.octokit.pulls.listReviews({
112115
owner: this.owner,
@@ -119,7 +122,7 @@ export default class PullRequest {
119122
['APPROVED', 'CHANGES_REQUESTED'].includes(r.state),
120123
);
121124

122-
if (reviews.length < 1) return;
125+
if (reviews.length < 1) return 'readyForReview';
123126

124127
const latestReviewsObj: { [key: number]: { state: string; time: number } } =
125128
{};

src/handlers/pullRequest.ts

+10
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ export default (app: Probot) => {
2929
}
3030
});
3131

32+
app.on(['pull_request.synchronize'], async context => {
33+
const pr = new PullRequest(context);
34+
35+
if (pr.wip || pr.data.draft) return;
36+
37+
const reviewStatus = await pr.getReviewStatus();
38+
39+
await pr.addLabel(reviewStatus);
40+
});
41+
3242
app.on(['pull_request.closed'], async context => {
3343
const pr = new PullRequest(context);
3444

src/handlers/pullRequestReview.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import PullRequest from '../classes/PullRequest.js';
55
export default (app: Probot) => {
66
app.on(['pull_request_review'], async context => {
77
const pr = new PullRequest(context);
8-
const reviewStatus = await pr.getReviewStatus();
98

10-
if (!reviewStatus) return;
9+
if (pr.wip || pr.data.draft) return;
10+
11+
const reviewStatus = await pr.getReviewStatus();
1112

1213
await pr.addLabel(reviewStatus);
1314
});

0 commit comments

Comments
 (0)