Skip to content

Commit

Permalink
feat: check if PR can be merged by checking mergeable property
Browse files Browse the repository at this point in the history
  • Loading branch information
jamacku committed Nov 8, 2023
1 parent b20a73f commit 7c6d05b
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 5 deletions.
6 changes: 6 additions & 0 deletions dist/action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/action.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/pull-request.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dist/pull-request.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/pull-request.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions dist/schema/pull-request.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/schema/pull-request.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/schema/pull-request.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ async function action(
message.push(`🟢 Pull Request meet requirements, title has correct form`);
}

if (pr.mergeable !== true) {
err.push(
`🔴 Pull Request can't be merged, \`mergeable\` is \`${pr.mergeable}\``
);
} else {
message.push(
`🟢 Pull Request meet requirements, \`mergeable\` is \`true\``
);
}

switch (pr?.mergeableState) {
case 'clean':
message.push(
Expand Down
4 changes: 3 additions & 1 deletion src/pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { debug } from '@actions/core';

import { CustomOctokit } from './octokit';

import { pullRequestApiSchema } from './schema/pull-request';
import { PullRequestApi, pullRequestApiSchema } from './schema/pull-request';
import { PullRequestMetadata } from './schema/input';

export class PullRequest {
Expand All @@ -11,6 +11,7 @@ export class PullRequest {

title = '';
targetBranch = '';
mergeable: PullRequestApi['mergeable'] = null;
mergeableState = 'unknown';
draft: boolean | undefined;
currentLabels: string[] = [];
Expand Down Expand Up @@ -44,6 +45,7 @@ export class PullRequest {

this.title = safeData.title;
this.targetBranch = safeData.base;
this.mergeable = safeData.mergeable;

Check warning on line 48 in src/pull-request.ts

View check run for this annotation

Codecov / codecov/patch

src/pull-request.ts#L48

Added line #L48 was not covered by tests
this.mergeableState = safeData.mergeable_state;
this.currentLabels = safeData.labels;
this.draft = safeData.draft;
Expand Down
1 change: 1 addition & 0 deletions src/schema/pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const pullRequestApiSchema = z.object({
),
draft: z.boolean(),
merged: z.boolean(),
mergeable: z.boolean().nullable(),
mergeable_state: z.string(),
});

Expand Down

0 comments on commit 7c6d05b

Please sign in to comment.