Skip to content

Commit

Permalink
fix changesRequested label never clearing (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-fidd authored Jul 12, 2024
1 parent 9e1f8a2 commit ebde529
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/classes/PullRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { Context, ProbotOctokit } from 'probot';
import { labels } from '../labels.js';

type TContext = Context<'pull_request' | 'pull_request_review'>;
type ReviewStatus =
| 'changesRequested'
| 'needsMoreApprovals'
| 'approved'
| 'readyForReview';

type BarebonesContext = {
octokit: ProbotOctokit;
Expand Down Expand Up @@ -104,9 +109,7 @@ export default class PullRequest {
}
}

async getReviewStatus(): Promise<
'changesRequested' | 'needsMoreApprovals' | 'approved' | undefined
> {
async getReviewStatus(): Promise<ReviewStatus> {
const reviews = (
await this.octokit.pulls.listReviews({
owner: this.owner,
Expand All @@ -119,7 +122,7 @@ export default class PullRequest {
['APPROVED', 'CHANGES_REQUESTED'].includes(r.state),
);

if (reviews.length < 1) return;
if (reviews.length < 1) return 'readyForReview';

const latestReviewsObj: { [key: number]: { state: string; time: number } } =
{};
Expand Down
10 changes: 10 additions & 0 deletions src/handlers/pullRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ export default (app: Probot) => {
}
});

app.on(['pull_request.synchronize'], async context => {
const pr = new PullRequest(context);

if (pr.wip || pr.data.draft) return;

const reviewStatus = await pr.getReviewStatus();

await pr.addLabel(reviewStatus);
});

app.on(['pull_request.closed'], async context => {
const pr = new PullRequest(context);

Expand Down
5 changes: 3 additions & 2 deletions src/handlers/pullRequestReview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import PullRequest from '../classes/PullRequest.js';
export default (app: Probot) => {
app.on(['pull_request_review'], async context => {
const pr = new PullRequest(context);
const reviewStatus = await pr.getReviewStatus();

if (!reviewStatus) return;
if (pr.wip || pr.data.draft) return;

const reviewStatus = await pr.getReviewStatus();

await pr.addLabel(reviewStatus);
});
Expand Down

0 comments on commit ebde529

Please sign in to comment.