accept-to-ship-action 0.6.7 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -3
- package/dist/canRepoAutoMerge.d.ts +3 -0
- package/dist/canRepoAutoMerge.js +27 -0
- package/dist/enablePullRequestAutoMerge.d.ts +5 -0
- package/dist/enablePullRequestAutoMerge.js +86 -0
- package/dist/getOcktokit.js +8 -7
- package/dist/getPullRequest.d.ts +1 -1
- package/dist/getPullRequestAutoMergeable.d.ts +7 -0
- package/dist/getPullRequestAutoMergeable.js +35 -0
- package/dist/index.js +50 -2
- package/dist/isPullRequestMerged.d.ts +3 -0
- package/dist/isPullRequestMerged.js +46 -0
- package/dist/mergePullRequest.d.ts +0 -1
- package/dist/mergePullRequest.js +3 -36
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ jobs:
|
|
|
57
57
|
steps:
|
|
58
58
|
- uses: actions/checkout@v3
|
|
59
59
|
|
|
60
|
-
- uses: CatChen/accept-to-ship-action@v0.
|
|
60
|
+
- uses: CatChen/accept-to-ship-action@v0.7
|
|
61
61
|
with:
|
|
62
62
|
github-token: ${{ secrets.GITHUB_TOKEN }} # optional
|
|
63
63
|
merge-method: merge # optional
|
|
@@ -65,7 +65,8 @@ jobs:
|
|
|
65
65
|
checks-watch-interval: 10 # optional
|
|
66
66
|
fail-if-timeout: false # optional
|
|
67
67
|
request-zero-accept-zero: false # optional
|
|
68
|
-
custom-hashtag: '#accept2ship' #optional
|
|
68
|
+
custom-hashtag: '#accept2ship' # optional
|
|
69
|
+
use-auto-merge: false # optional
|
|
69
70
|
|
|
70
71
|
pass-to-ship:
|
|
71
72
|
name: Pass to Ship
|
|
@@ -82,7 +83,7 @@ jobs:
|
|
|
82
83
|
steps:
|
|
83
84
|
- uses: actions/checkout@v3
|
|
84
85
|
|
|
85
|
-
- uses: CatChen/accept-to-ship-action@v0.
|
|
86
|
+
- uses: CatChen/accept-to-ship-action@v0.7
|
|
86
87
|
with:
|
|
87
88
|
request-zero-accept-zero: true
|
|
88
89
|
custom-hashtag: '#pass2ship'
|
|
@@ -118,6 +119,16 @@ Change `#accept2ship` to another hashtag. Use multiple instances of this Action
|
|
|
118
119
|
|
|
119
120
|
When this option is set to `true` this Action will not wait for any approval if no review was requested. Otherwise, this Action will wait for at least one approval if no review was requested. It's useful to set this to `true` with a different hashtag set in `custom-hashtag` to merge certain Pull Requests after running and passing all the checks. See the `#pass2ship` configuration in the examples from above. The default value is `false`.
|
|
120
121
|
|
|
122
|
+
### `use-auto-merge`
|
|
123
|
+
|
|
124
|
+
When this option is set to `true` this Action will try to use GitHub's auto-merge after the Pull Request receives the necessary approvals. Otherwise, this Action will wait for the Pull Request's checks and merge the Pull Request when the checks pass.
|
|
125
|
+
|
|
126
|
+
Auto-merge is only available when:
|
|
127
|
+
|
|
128
|
+
1. Auto-merge is [enabled for the repo](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/managing-auto-merge-for-pull-requests-in-your-repository).
|
|
129
|
+
2. The base branch of the Pull Request is a [protected branch](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/about-protected-branches) or protected by [rulesets](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-rulesets/about-rulesets).
|
|
130
|
+
3. At least one of the branch protection conditions isn't met. (When all conditions are met the Pull Request is mergeable and the auto-merge is no longer available.)
|
|
131
|
+
|
|
121
132
|
## FAQ
|
|
122
133
|
|
|
123
134
|
### Where do I need to put the `#accept2ship` hashtag?
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.canRepoAutoMerge = canRepoAutoMerge;
|
|
13
|
+
function canRepoAutoMerge(owner, repo, octokit) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const { repository: { autoMergeAllowed }, } = yield octokit.graphql(`
|
|
16
|
+
query($owner: String!, $repo: String!) {
|
|
17
|
+
repository(owner: $owner, name: $repo) {
|
|
18
|
+
autoMergeAllowed
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
`, {
|
|
22
|
+
owner,
|
|
23
|
+
repo,
|
|
24
|
+
});
|
|
25
|
+
return autoMergeAllowed;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Octokit } from '@octokit/core';
|
|
2
|
+
import type { Api } from '@octokit/plugin-rest-endpoint-methods/dist-types/types';
|
|
3
|
+
import { PullRequest } from '@octokit/webhooks-types/schema';
|
|
4
|
+
import { getMergeMethod } from './getMergeMethod';
|
|
5
|
+
export declare function enablePullRequestAutoMerge(owner: string, repo: string, pullRequest: PullRequest, pullRequestId: string, mergeMethod: ReturnType<typeof getMergeMethod>, octokit: Octokit & Api): Promise<void>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.enablePullRequestAutoMerge = enablePullRequestAutoMerge;
|
|
13
|
+
const core_1 = require("@actions/core");
|
|
14
|
+
const github_1 = require("@actions/github");
|
|
15
|
+
const request_error_1 = require("@octokit/request-error");
|
|
16
|
+
const isPullRequestMerged_1 = require("./isPullRequestMerged");
|
|
17
|
+
function enablePullRequestAutoMerge(owner, repo, pullRequest, pullRequestId, mergeMethod, octokit) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
const pullRequestNumber = pullRequest.number;
|
|
21
|
+
try {
|
|
22
|
+
yield octokit.graphql(`
|
|
23
|
+
mutation($pullRequestId: ID!, $mergeMethod: PullRequestMergeMethod) {
|
|
24
|
+
enablePullRequestAutoMerge(input: { pullRequestId: $pullRequestId, mergeMethod: $mergeMethod }) {
|
|
25
|
+
clientMutationId
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
`, {
|
|
29
|
+
pullRequestId,
|
|
30
|
+
mergeMethod: mergeMethod.toUpperCase(),
|
|
31
|
+
});
|
|
32
|
+
(0, core_1.setOutput)('skipped', false);
|
|
33
|
+
try {
|
|
34
|
+
(0, core_1.info)(`Run ID: ${github_1.context.runId}`);
|
|
35
|
+
const { data: job } = yield octokit.rest.actions.getWorkflowRun({
|
|
36
|
+
owner,
|
|
37
|
+
repo,
|
|
38
|
+
run_id: github_1.context.runId,
|
|
39
|
+
});
|
|
40
|
+
(0, core_1.info)(`Job ID: ${job.id} (${job.html_url})`);
|
|
41
|
+
const { data: comment } = yield octokit.rest.issues.createComment({
|
|
42
|
+
owner,
|
|
43
|
+
repo,
|
|
44
|
+
issue_number: pullRequestNumber,
|
|
45
|
+
body: `Auto-merge is enabled by a [GitHub Action](${job.html_url})`,
|
|
46
|
+
});
|
|
47
|
+
(0, core_1.info)(`Comment is created: ${comment.html_url}`);
|
|
48
|
+
}
|
|
49
|
+
catch (requestError) {
|
|
50
|
+
if (requestError instanceof request_error_1.RequestError) {
|
|
51
|
+
(0, core_1.info)(`Failed to comment on the Pull Request: [${requestError.status}] ${requestError.message}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (requestError) {
|
|
56
|
+
if (requestError instanceof request_error_1.RequestError) {
|
|
57
|
+
(0, core_1.warning)(`Failed to enable auto-merge for the Pull Request: [${requestError.status}] ${requestError.message}`);
|
|
58
|
+
// If it's merged by someone else in a race condition we treat it as skipped,
|
|
59
|
+
// because it's the same as someone else merged it before we try.
|
|
60
|
+
const merged = yield (0, isPullRequestMerged_1.isPullRequestMerged)(owner, repo, pullRequestNumber, octokit);
|
|
61
|
+
(0, core_1.setOutput)('skipped', !merged);
|
|
62
|
+
if (merged) {
|
|
63
|
+
try {
|
|
64
|
+
const { data: pullRequest } = yield octokit.rest.pulls.get({
|
|
65
|
+
owner,
|
|
66
|
+
repo,
|
|
67
|
+
pull_number: pullRequestNumber,
|
|
68
|
+
});
|
|
69
|
+
(0, core_1.warning)(`This Pull Request has been merged by: ${(_a = pullRequest.merged_by) === null || _a === void 0 ? void 0 : _a.login} (${(_b = pullRequest.merged_by) === null || _b === void 0 ? void 0 : _b.html_url})`);
|
|
70
|
+
}
|
|
71
|
+
catch (_c) {
|
|
72
|
+
(0, core_1.warning)(`This Pull Request has been merged by unknown user.`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// If it's not merged by someone else in a race condition then we treat it as a real error.
|
|
77
|
+
(0, core_1.error)(`This Pull Request remains unmerged.`);
|
|
78
|
+
(0, core_1.setFailed)(`Failed to merge this Pull Request when conditions are met.`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
throw requestError;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
package/dist/getOcktokit.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getOctokit = getOctokit;
|
|
4
|
+
const core_1 = require("@actions/core");
|
|
4
5
|
const utils_js_1 = require("@actions/github/lib/utils.js");
|
|
5
6
|
const plugin_retry_1 = require("@octokit/plugin-retry");
|
|
6
7
|
const plugin_throttling_1 = require("@octokit/plugin-throttling");
|
|
@@ -10,27 +11,27 @@ function getOctokit(githubToken) {
|
|
|
10
11
|
throttle: {
|
|
11
12
|
onRateLimit: (retryAfter, options, _, retryCount) => {
|
|
12
13
|
if (retryCount === 0) {
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
(0, core_1.warning)(`Request quota exhausted for request ${options.method} ${options.url}`);
|
|
15
|
+
(0, core_1.info)(`Retrying after ${retryAfter} seconds!`);
|
|
15
16
|
return true;
|
|
16
17
|
}
|
|
17
18
|
else {
|
|
18
|
-
|
|
19
|
+
(0, core_1.error)(`Request quota exhausted for request ${options.method} ${options.url}`);
|
|
19
20
|
}
|
|
20
21
|
},
|
|
21
22
|
onSecondaryRateLimit: (retryAfter, options, _, retryCount) => {
|
|
22
23
|
if (retryCount === 0) {
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
(0, core_1.warning)(`Abuse detected for request ${options.method} ${options.url}`);
|
|
25
|
+
(0, core_1.info)(`Retrying after ${retryAfter} seconds!`);
|
|
25
26
|
return true;
|
|
26
27
|
}
|
|
27
28
|
else {
|
|
28
|
-
|
|
29
|
+
(0, core_1.warning)(`Abuse detected for request ${options.method} ${options.url}`);
|
|
29
30
|
}
|
|
30
31
|
},
|
|
31
32
|
},
|
|
32
33
|
retry: {
|
|
33
|
-
doNotRetry: ['429'],
|
|
34
|
+
doNotRetry: ['403', '429'],
|
|
34
35
|
},
|
|
35
36
|
}));
|
|
36
37
|
octokit.graphql = octokit.graphql.defaults({
|
package/dist/getPullRequest.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Octokit } from '@octokit/core';
|
|
2
2
|
import type { Api } from '@octokit/plugin-rest-endpoint-methods/dist-types/types';
|
|
3
|
-
import type { PullRequest } from '@octokit/webhooks-
|
|
3
|
+
import type { PullRequest } from '@octokit/webhooks-types/schema';
|
|
4
4
|
export declare function getPullRequest(owner: string, repo: string, pullRequestNumber: number, octokit: Octokit & Api): Promise<PullRequest>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Octokit } from '@octokit/core';
|
|
2
|
+
import type { Api } from '@octokit/plugin-rest-endpoint-methods/dist-types/types';
|
|
3
|
+
import { PullRequest } from '@octokit/webhooks-types/schema';
|
|
4
|
+
export declare function getPullRequestAutoMergeable(owner: string, repo: string, pullRequest: PullRequest, octokit: Octokit & Api): Promise<{
|
|
5
|
+
pullRequestId: string;
|
|
6
|
+
viewerCanEnableAutoMerge: boolean;
|
|
7
|
+
}>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getPullRequestAutoMergeable = getPullRequestAutoMergeable;
|
|
13
|
+
function getPullRequestAutoMergeable(owner, repo, pullRequest, octokit) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const pullRequestNumber = pullRequest.number;
|
|
16
|
+
const { repository: { pullRequest: { pullRequestId, viewerCanEnableAutoMerge }, }, } = yield octokit.graphql(`
|
|
17
|
+
query($owner: String!, $repo: String!, $pullRequestNumber: Int!) {
|
|
18
|
+
repository(owner: $owner, name: $repo) {
|
|
19
|
+
pullRequest(number: $pullRequestNumber) {
|
|
20
|
+
pullRequestId: id
|
|
21
|
+
viewerCanEnableAutoMerge
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
`, {
|
|
26
|
+
owner,
|
|
27
|
+
repo,
|
|
28
|
+
pullRequestNumber,
|
|
29
|
+
});
|
|
30
|
+
return {
|
|
31
|
+
pullRequestId,
|
|
32
|
+
viewerCanEnableAutoMerge,
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -12,14 +12,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
const node_perf_hooks_1 = require("node:perf_hooks");
|
|
13
13
|
const core_1 = require("@actions/core");
|
|
14
14
|
const github_1 = require("@actions/github");
|
|
15
|
+
const canRepoAutoMerge_1 = require("./canRepoAutoMerge");
|
|
16
|
+
const enablePullRequestAutoMerge_1 = require("./enablePullRequestAutoMerge");
|
|
15
17
|
const getCheckRuns_1 = require("./getCheckRuns");
|
|
16
18
|
const getMergeMethod_1 = require("./getMergeMethod");
|
|
17
19
|
const getOcktokit_1 = require("./getOcktokit");
|
|
18
20
|
const getPullRequest_1 = require("./getPullRequest");
|
|
21
|
+
const getPullRequestAutoMergeable_1 = require("./getPullRequestAutoMergeable");
|
|
19
22
|
const getPullRequestComments_1 = require("./getPullRequestComments");
|
|
20
23
|
const getPullRequestReviewRequests_1 = require("./getPullRequestReviewRequests");
|
|
21
24
|
const getPullRequestReviews_1 = require("./getPullRequestReviews");
|
|
22
25
|
const getWorkflowRunJobs_1 = require("./getWorkflowRunJobs");
|
|
26
|
+
const isPullRequestMerged_1 = require("./isPullRequestMerged");
|
|
23
27
|
const mergePullRequest_1 = require("./mergePullRequest");
|
|
24
28
|
const sleep_1 = require("./sleep");
|
|
25
29
|
const APPROVED = 'APPROVED';
|
|
@@ -42,7 +46,7 @@ function handlePullRequest(pullRequestNumber) {
|
|
|
42
46
|
const octokit = (0, getOcktokit_1.getOctokit)(githubToken);
|
|
43
47
|
const owner = github_1.context.repo.owner;
|
|
44
48
|
const repo = github_1.context.repo.repo;
|
|
45
|
-
const mergedBeforeValidations = yield (0,
|
|
49
|
+
const mergedBeforeValidations = yield (0, isPullRequestMerged_1.isPullRequestMerged)(owner, repo, pullRequestNumber, octokit);
|
|
46
50
|
if (mergedBeforeValidations) {
|
|
47
51
|
(0, core_1.error)(`This Pull Request has been merged already.`);
|
|
48
52
|
return;
|
|
@@ -51,6 +55,16 @@ function handlePullRequest(pullRequestNumber) {
|
|
|
51
55
|
const hashTagLabel = customHashTag.replace(/^#*/, '');
|
|
52
56
|
const hashTag = `#${hashTagLabel}`;
|
|
53
57
|
const pullRequest = yield (0, getPullRequest_1.getPullRequest)(owner, repo, pullRequestNumber, octokit);
|
|
58
|
+
if (pullRequest.auto_merge !== null) {
|
|
59
|
+
if (pullRequest.auto_merge.enabled_by !== null) {
|
|
60
|
+
(0, core_1.info)(`Auto-merge is enabled by ${pullRequest.auto_merge.enabled_by.login} (${pullRequest.auto_merge.enabled_by.html_url})`);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
(0, core_1.info)(`Auto-merge is enabled`);
|
|
64
|
+
}
|
|
65
|
+
(0, core_1.setOutput)('skipped', true);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
54
68
|
const accept2shipTitle = (_b = (_a = pullRequest.title) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes(hashTag);
|
|
55
69
|
(0, core_1.info)(`${hashTag} ${accept2shipTitle ? '' : 'not '}found in title`);
|
|
56
70
|
const accept2shipBody = (_d = (_c = pullRequest.body) === null || _c === void 0 ? void 0 : _c.toLowerCase()) === null || _d === void 0 ? void 0 : _d.includes(hashTag);
|
|
@@ -131,6 +145,40 @@ function handlePullRequest(pullRequestNumber) {
|
|
|
131
145
|
return;
|
|
132
146
|
}
|
|
133
147
|
(0, core_1.endGroup)();
|
|
148
|
+
const useAutoMerge = (0, core_1.getBooleanInput)('use-auto-merge');
|
|
149
|
+
if (useAutoMerge) {
|
|
150
|
+
if (yield (0, canRepoAutoMerge_1.canRepoAutoMerge)(owner, repo, octokit)) {
|
|
151
|
+
const pullRequestAutoMergeable = yield (0, getPullRequestAutoMergeable_1.getPullRequestAutoMergeable)(owner, repo, pullRequest, octokit);
|
|
152
|
+
if (pullRequestAutoMergeable.viewerCanEnableAutoMerge) {
|
|
153
|
+
const mergeMethod = (0, getMergeMethod_1.getMergeMethod)();
|
|
154
|
+
(0, core_1.info)(`Enabling auto-merge with merge method: ${mergeMethod}`);
|
|
155
|
+
yield (0, enablePullRequestAutoMerge_1.enablePullRequestAutoMerge)(owner, repo, pullRequest, pullRequestAutoMergeable.pullRequestId, mergeMethod, octokit);
|
|
156
|
+
core_1.summary.addRaw(`Pull Request #${pullRequestNumber} has auto-merge enabled.`, true);
|
|
157
|
+
return; // No need to wait for the checks and try to merge.
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
const pullRequest = yield (0, getPullRequest_1.getPullRequest)(owner, repo, pullRequestNumber, octokit);
|
|
161
|
+
if (pullRequest.mergeable) {
|
|
162
|
+
(0, core_1.info)(`Auto-merge is not allowed when the Pull Request is mergeable`);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
const merged = yield (0, isPullRequestMerged_1.isPullRequestMerged)(owner, repo, pullRequestNumber, octokit);
|
|
166
|
+
(0, core_1.setOutput)('skipped', !merged);
|
|
167
|
+
if (merged) {
|
|
168
|
+
(0, core_1.info)(`Auto-merge is not allowed when the Pull Request is already merged`);
|
|
169
|
+
return; // No need to wait for the checks.
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
(0, core_1.warning)(`Auto-merge is not allowed for this Pull Request`);
|
|
173
|
+
(0, core_1.warning)(`Please set up branch protection for the base branch: ${pullRequest.base.ref}`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
(0, core_1.error)(`Auto-merge is not enabled for the base repository: ${pullRequest.base.repo.html_url}`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
134
182
|
const jobs = yield (0, getWorkflowRunJobs_1.getWorkflowRunJobs)(owner, repo, octokit);
|
|
135
183
|
(0, core_1.info)(`Current workflow name: ${github_1.context.workflow}`);
|
|
136
184
|
(0, core_1.info)(`Current run id: ${github_1.context.runId}`);
|
|
@@ -237,7 +285,7 @@ function handlePullRequest(pullRequestNumber) {
|
|
|
237
285
|
worthChecking = false;
|
|
238
286
|
}
|
|
239
287
|
}
|
|
240
|
-
const mergedAfterValidations = yield (0,
|
|
288
|
+
const mergedAfterValidations = yield (0, isPullRequestMerged_1.isPullRequestMerged)(owner, repo, pullRequestNumber, octokit);
|
|
241
289
|
if (mergedAfterValidations) {
|
|
242
290
|
(0, core_1.error)(`This Pull Request has been merged already.`);
|
|
243
291
|
return;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.isPullRequestMerged = isPullRequestMerged;
|
|
13
|
+
const request_error_1 = require("@octokit/request-error");
|
|
14
|
+
function isPullRequestMerged(owner, repo, pullRequestNumber, octokit) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
try {
|
|
17
|
+
const { status } = yield octokit.rest.pulls.checkIfMerged({
|
|
18
|
+
owner,
|
|
19
|
+
repo,
|
|
20
|
+
pull_number: pullRequestNumber,
|
|
21
|
+
});
|
|
22
|
+
if (status === 204) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (requestError) {
|
|
30
|
+
if (requestError instanceof request_error_1.RequestError) {
|
|
31
|
+
if (requestError.status === 204) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
else if (requestError.status === 404) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
throw new Error(`Failed to check if pull request is merged: [${requestError.status}] ${requestError.message}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
throw requestError;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Octokit } from '@octokit/core';
|
|
2
2
|
import type { Api } from '@octokit/plugin-rest-endpoint-methods/dist-types/types';
|
|
3
3
|
import { getMergeMethod } from './getMergeMethod';
|
|
4
|
-
export declare function checkIfPullRequestMerged(owner: string, repo: string, pullRequestNumber: number, octokit: Octokit & Api): Promise<boolean>;
|
|
5
4
|
export declare function mergePullRequest(owner: string, repo: string, pullRequestNumber: number, mergeMethod: ReturnType<typeof getMergeMethod>, octokit: Octokit & Api): Promise<void>;
|
package/dist/mergePullRequest.js
CHANGED
|
@@ -9,45 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.checkIfPullRequestMerged = checkIfPullRequestMerged;
|
|
13
12
|
exports.mergePullRequest = mergePullRequest;
|
|
14
13
|
const console_1 = require("console");
|
|
15
14
|
const core_1 = require("@actions/core");
|
|
16
15
|
const github_1 = require("@actions/github");
|
|
17
16
|
const request_error_1 = require("@octokit/request-error");
|
|
18
|
-
|
|
19
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
try {
|
|
21
|
-
const { status } = yield octokit.rest.pulls.checkIfMerged({
|
|
22
|
-
owner,
|
|
23
|
-
repo,
|
|
24
|
-
pull_number: pullRequestNumber,
|
|
25
|
-
});
|
|
26
|
-
if (status === 204) {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
catch (requestError) {
|
|
34
|
-
if (requestError instanceof request_error_1.RequestError) {
|
|
35
|
-
if (requestError.status === 204) {
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
else if (requestError.status === 404) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
throw new Error(`Failed to check if pull request is merged: [${requestError.status}] ${requestError.message}`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
throw requestError;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
17
|
+
const isPullRequestMerged_1 = require("./isPullRequestMerged");
|
|
51
18
|
function mergePullRequest(owner, repo, pullRequestNumber, mergeMethod, octokit) {
|
|
52
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
20
|
var _a, _b;
|
|
@@ -86,7 +53,8 @@ function mergePullRequest(owner, repo, pullRequestNumber, mergeMethod, octokit)
|
|
|
86
53
|
(0, core_1.warning)(`Failed to merge the Pull Request: [${requestError.status}] ${requestError.message}`);
|
|
87
54
|
// If it's merged by someone else in a race condition we treat it as skipped,
|
|
88
55
|
// because it's the same as someone else merged it before we try.
|
|
89
|
-
const merged = yield
|
|
56
|
+
const merged = yield (0, isPullRequestMerged_1.isPullRequestMerged)(owner, repo, pullRequestNumber, octokit);
|
|
57
|
+
(0, core_1.setOutput)('skipped', !merged);
|
|
90
58
|
if (merged) {
|
|
91
59
|
try {
|
|
92
60
|
const { data: pullRequest } = yield octokit.rest.pulls.get({
|
|
@@ -105,7 +73,6 @@ function mergePullRequest(owner, repo, pullRequestNumber, mergeMethod, octokit)
|
|
|
105
73
|
(0, core_1.error)(`This Pull Request remains unmerged.`);
|
|
106
74
|
(0, core_1.setFailed)(`Failed to merge this Pull Request when conditions are met.`);
|
|
107
75
|
}
|
|
108
|
-
(0, core_1.setOutput)('skipped', !merged);
|
|
109
76
|
}
|
|
110
77
|
else {
|
|
111
78
|
throw requestError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "accept-to-ship-action",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.js",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@actions/github": "^6.0.0",
|
|
50
50
|
"@octokit/plugin-retry": "^7.1.2",
|
|
51
51
|
"@octokit/plugin-throttling": "^9.3.0",
|
|
52
|
-
"@octokit/webhooks-
|
|
52
|
+
"@octokit/webhooks-types": "^7.6.1"
|
|
53
53
|
},
|
|
54
54
|
"lint-staged": {
|
|
55
55
|
"*.(ts,js)": "yarn lint --fix",
|