mirror of
https://github.com/peter-evans/create-pull-request.git
synced 2026-09-30 09:32:53 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22a9089034 | ||
|
|
d4f3be6ce6 | ||
|
|
bc8a47f565 | ||
|
|
a67ef28ca5 |
@@ -19,7 +19,7 @@ jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: 20.x
|
||||
@@ -46,7 +46,7 @@ jobs:
|
||||
matrix:
|
||||
target: [built, committed]
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
ref: main
|
||||
- if: matrix.target == 'built' || github.event_name == 'pull_request'
|
||||
@@ -118,7 +118,7 @@ jobs:
|
||||
needs: [test]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/download-artifact@v6
|
||||
with:
|
||||
name: dist
|
||||
|
||||
@@ -6,7 +6,7 @@ jobs:
|
||||
createPullRequest:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Make changes to pull request
|
||||
run: date +%s > report.txt
|
||||
|
||||
@@ -7,7 +7,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Slash Command Dispatch
|
||||
uses: peter-evans/slash-command-dispatch@v4
|
||||
uses: peter-evans/slash-command-dispatch@v5
|
||||
with:
|
||||
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||
config: >
|
||||
|
||||
@@ -18,7 +18,7 @@ jobs:
|
||||
tag:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||
fetch-depth: 0
|
||||
|
||||
Vendored
+59
-8
@@ -452,12 +452,14 @@ function createPullRequest(inputs) {
|
||||
if (branchRemoteName == 'origin' && base == inputs.branch) {
|
||||
throw new Error(`The 'base' and 'branch' for a pull request must be different branches. Unable to continue.`);
|
||||
}
|
||||
// For self-hosted runners the repository state persists between runs.
|
||||
// This command prunes the stale remote ref when the pull request branch was
|
||||
// deleted after being merged or closed. Without this the push using
|
||||
// '--force-with-lease' fails due to "stale info."
|
||||
// https://github.com/peter-evans/create-pull-request/issues/633
|
||||
yield git.exec(['remote', 'prune', branchRemoteName]);
|
||||
if (utils.isSelfHosted()) {
|
||||
// For self-hosted runners the repository state persists between runs.
|
||||
// This command prunes the stale remote ref when the pull request branch was
|
||||
// deleted after being merged or closed. Without this the push using
|
||||
// '--force-with-lease' fails due to "stale info."
|
||||
// https://github.com/peter-evans/create-pull-request/issues/633
|
||||
yield git.exec(['remote', 'prune', branchRemoteName]);
|
||||
}
|
||||
core.endGroup();
|
||||
// Apply the branch suffix if set
|
||||
if (inputs.branchSuffix) {
|
||||
@@ -1355,6 +1357,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
||||
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
||||
var m = o[Symbol.asyncIterator], i;
|
||||
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
||||
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
||||
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
@@ -1390,6 +1399,43 @@ class GitHubHelper {
|
||||
repo: repo
|
||||
};
|
||||
}
|
||||
getPullNumber(baseRepository, headBranch, baseBranch) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
var _a, e_1, _b, _c;
|
||||
const { data: pulls } = yield this.octokit.rest.pulls.list(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { state: 'open', head: headBranch, base: baseBranch }));
|
||||
let pullNumber = undefined;
|
||||
if ((pulls === null || pulls === void 0 ? void 0 : pulls.length) === 0 || pulls === null || pulls === undefined) {
|
||||
// This is a fallback due to a bug that affects the list endpoint when called on forks with the same owner as the repository parent.
|
||||
core.info(`Pull request not found via list endpoint; attempting fallback mechanism`);
|
||||
try {
|
||||
for (var _d = true, _e = __asyncValues(this.octokit.paginate.iterator(this.octokit.rest.pulls.list, Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { state: 'open', base: baseBranch }))), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
|
||||
_c = _f.value;
|
||||
_d = false;
|
||||
const response = _c;
|
||||
const existingPull = response.data.find(pull => pull.head.label === headBranch);
|
||||
if (existingPull !== undefined) {
|
||||
pullNumber = existingPull.number;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
||||
finally {
|
||||
try {
|
||||
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
|
||||
}
|
||||
finally { if (e_1) throw e_1.error; }
|
||||
}
|
||||
}
|
||||
else {
|
||||
pullNumber = pulls[0].number;
|
||||
}
|
||||
if (pullNumber === undefined) {
|
||||
throw new Error(`Failed to find pull request number for branch ${headBranch}`);
|
||||
}
|
||||
return pullNumber;
|
||||
});
|
||||
}
|
||||
createOrUpdate(inputs, baseRepository, headRepository) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const [headOwner] = headRepository.split('/');
|
||||
@@ -1423,9 +1469,9 @@ class GitHubHelper {
|
||||
}
|
||||
// Update the pull request that exists for this branch and base
|
||||
core.info(`Fetching existing pull request`);
|
||||
const { data: pulls } = yield this.octokit.rest.pulls.list(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { state: 'open', head: headBranch, base: inputs.base }));
|
||||
const pullNumber = yield this.getPullNumber(baseRepository, headBranch, inputs.base);
|
||||
core.info(`Attempting update of pull request`);
|
||||
const { data: pull } = yield this.octokit.rest.pulls.update(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { pull_number: pulls[0].number, title: inputs.title, body: inputs.body }));
|
||||
const { data: pull } = yield this.octokit.rest.pulls.update(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { pull_number: pullNumber, title: inputs.title, body: inputs.body }));
|
||||
core.info(`Updated pull request #${pull.number} (${headBranch} => ${inputs.base})`);
|
||||
return {
|
||||
number: pull.number,
|
||||
@@ -1844,6 +1890,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.isSelfHosted = void 0;
|
||||
exports.getInputAsArray = getInputAsArray;
|
||||
exports.getStringAsArray = getStringAsArray;
|
||||
exports.stripOrgPrefixFromTeams = stripOrgPrefixFromTeams;
|
||||
@@ -1952,6 +1999,10 @@ function getErrorMessage(error) {
|
||||
return error.message;
|
||||
return String(error);
|
||||
}
|
||||
const isSelfHosted = () => process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' &&
|
||||
(process.env['AGENT_ISSELFHOSTED'] === '1' ||
|
||||
process.env['AGENT_ISSELFHOSTED'] === undefined);
|
||||
exports.isSelfHosted = isSelfHosted;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
Generated
+15
-4
@@ -35,7 +35,7 @@
|
||||
"jest-circus": "^29.7.0",
|
||||
"jest-environment-jsdom": "^29.7.0",
|
||||
"js-yaml": "^4.1.1",
|
||||
"prettier": "^3.6.2",
|
||||
"prettier": "^3.7.3",
|
||||
"ts-jest": "^29.4.5",
|
||||
"typescript": "^5.9.3",
|
||||
"undici": "^6.22.0"
|
||||
@@ -123,6 +123,7 @@
|
||||
"resolved": "https://registry.npmjs.org/@babel/core/-/core-7.24.9.tgz",
|
||||
"integrity": "sha512-5e3FI4Q3M3Pbr21+5xJwCv6ZT6KmGkI0vw3Tozy5ODAQFTIWe37iT8Cr7Ice2Ntb+M3iSKCEWMB1MBgKrW3whg==",
|
||||
"dev": true,
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@ampproject/remapping": "^2.2.0",
|
||||
"@babel/code-frame": "^7.24.7",
|
||||
@@ -1322,6 +1323,7 @@
|
||||
"resolved": "https://registry.npmjs.org/@octokit/core/-/core-6.1.6.tgz",
|
||||
"integrity": "sha512-kIU8SLQkYWGp3pVKiYzA5OSaNF5EE03P/R8zEmmrG6XwOg5oBjXyQVVIauQ0dgau4zYhpZEhJrvIYt6oM+zZZA==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@octokit/auth-token": "^5.0.0",
|
||||
"@octokit/graphql": "^8.2.2",
|
||||
@@ -2545,6 +2547,7 @@
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz",
|
||||
"integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==",
|
||||
"dev": true,
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"acorn": "bin/acorn"
|
||||
},
|
||||
@@ -3049,6 +3052,7 @@
|
||||
"url": "https://github.com/sponsors/ai"
|
||||
}
|
||||
],
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"caniuse-lite": "^1.0.30001640",
|
||||
"electron-to-chromium": "^1.4.820",
|
||||
@@ -3919,6 +3923,7 @@
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.57.1.tgz",
|
||||
"integrity": "sha512-ypowyDxpVSYpkXr9WPv2PAZCtNip1Mv5KTW0SCurXv/9iOpcrH9PaqUElksqEB6pChqHGDRCFTyrZlGhnLNGiA==",
|
||||
"dev": true,
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@eslint-community/eslint-utils": "^4.2.0",
|
||||
"@eslint-community/regexpp": "^4.6.1",
|
||||
@@ -4165,6 +4170,7 @@
|
||||
"integrity": "sha512-whOE1HFo/qJDyX4SnXzP4N6zOWn79WhnCUY/iDR0mPfQZO8wcYE4JClzI2oZrhBnnMUCBCHZhO6VQyoBU95mZA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@rtsao/scc": "^1.1.0",
|
||||
"array-includes": "^3.1.9",
|
||||
@@ -5754,6 +5760,7 @@
|
||||
"resolved": "https://registry.npmjs.org/jest/-/jest-29.7.0.tgz",
|
||||
"integrity": "sha512-NIy3oAFp9shda19hy4HK0HRTWKtPJmGdnvywu01nOqNC2vZg+Z+fvJDxpMQA88eb2I9EcafcdjYgsDthnYTvGw==",
|
||||
"dev": true,
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@jest/core": "^29.7.0",
|
||||
"@jest/types": "^29.6.3",
|
||||
@@ -7290,10 +7297,12 @@
|
||||
}
|
||||
},
|
||||
"node_modules/prettier": {
|
||||
"version": "3.6.2",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.6.2.tgz",
|
||||
"integrity": "sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==",
|
||||
"version": "3.7.3",
|
||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.7.3.tgz",
|
||||
"integrity": "sha512-QgODejq9K3OzoBbuyobZlUhznP5SKwPqp+6Q6xw6o8gnhr4O85L2U915iM2IDcfF2NPXVaM9zlo9tdwipnYwzg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"prettier": "bin/prettier.cjs"
|
||||
},
|
||||
@@ -8167,6 +8176,7 @@
|
||||
"integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
@@ -8493,6 +8503,7 @@
|
||||
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@
|
||||
"jest-circus": "^29.7.0",
|
||||
"jest-environment-jsdom": "^29.7.0",
|
||||
"js-yaml": "^4.1.1",
|
||||
"prettier": "^3.6.2",
|
||||
"prettier": "^3.7.3",
|
||||
"ts-jest": "^29.4.5",
|
||||
"typescript": "^5.9.3",
|
||||
"undici": "^6.22.0"
|
||||
|
||||
@@ -121,12 +121,14 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
|
||||
`The 'base' and 'branch' for a pull request must be different branches. Unable to continue.`
|
||||
)
|
||||
}
|
||||
// For self-hosted runners the repository state persists between runs.
|
||||
// This command prunes the stale remote ref when the pull request branch was
|
||||
// deleted after being merged or closed. Without this the push using
|
||||
// '--force-with-lease' fails due to "stale info."
|
||||
// https://github.com/peter-evans/create-pull-request/issues/633
|
||||
await git.exec(['remote', 'prune', branchRemoteName])
|
||||
if (utils.isSelfHosted()) {
|
||||
// For self-hosted runners the repository state persists between runs.
|
||||
// This command prunes the stale remote ref when the pull request branch was
|
||||
// deleted after being merged or closed. Without this the push using
|
||||
// '--force-with-lease' fails due to "stale info."
|
||||
// https://github.com/peter-evans/create-pull-request/issues/633
|
||||
await git.exec(['remote', 'prune', branchRemoteName])
|
||||
}
|
||||
core.endGroup()
|
||||
|
||||
// Apply the branch suffix if set
|
||||
|
||||
+50
-7
@@ -63,6 +63,50 @@ export class GitHubHelper {
|
||||
}
|
||||
}
|
||||
|
||||
private async getPullNumber(
|
||||
baseRepository: string,
|
||||
headBranch: string,
|
||||
baseBranch: string
|
||||
): Promise<number> {
|
||||
const {data: pulls} = await this.octokit.rest.pulls.list({
|
||||
...this.parseRepository(baseRepository),
|
||||
state: 'open',
|
||||
head: headBranch,
|
||||
base: baseBranch
|
||||
})
|
||||
let pullNumber: number | undefined = undefined
|
||||
if (pulls?.length === 0 || pulls === null || pulls === undefined) {
|
||||
// This is a fallback due to a bug that affects the list endpoint when called on forks with the same owner as the repository parent.
|
||||
core.info(
|
||||
`Pull request not found via list endpoint; attempting fallback mechanism`
|
||||
)
|
||||
for await (const response of this.octokit.paginate.iterator(
|
||||
this.octokit.rest.pulls.list,
|
||||
{
|
||||
...this.parseRepository(baseRepository),
|
||||
state: 'open',
|
||||
base: baseBranch
|
||||
}
|
||||
)) {
|
||||
const existingPull = response.data.find(
|
||||
pull => pull.head.label === headBranch
|
||||
)
|
||||
if (existingPull !== undefined) {
|
||||
pullNumber = existingPull.number
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pullNumber = pulls[0].number
|
||||
}
|
||||
if (pullNumber === undefined) {
|
||||
throw new Error(
|
||||
`Failed to find pull request number for branch ${headBranch}`
|
||||
)
|
||||
}
|
||||
return pullNumber
|
||||
}
|
||||
|
||||
private async createOrUpdate(
|
||||
inputs: Inputs,
|
||||
baseRepository: string,
|
||||
@@ -113,16 +157,15 @@ export class GitHubHelper {
|
||||
|
||||
// Update the pull request that exists for this branch and base
|
||||
core.info(`Fetching existing pull request`)
|
||||
const {data: pulls} = await this.octokit.rest.pulls.list({
|
||||
...this.parseRepository(baseRepository),
|
||||
state: 'open',
|
||||
head: headBranch,
|
||||
base: inputs.base
|
||||
})
|
||||
const pullNumber = await this.getPullNumber(
|
||||
baseRepository,
|
||||
headBranch,
|
||||
inputs.base
|
||||
)
|
||||
core.info(`Attempting update of pull request`)
|
||||
const {data: pull} = await this.octokit.rest.pulls.update({
|
||||
...this.parseRepository(baseRepository),
|
||||
pull_number: pulls[0].number,
|
||||
pull_number: pullNumber,
|
||||
title: inputs.title,
|
||||
body: inputs.body
|
||||
})
|
||||
|
||||
@@ -135,3 +135,8 @@ export function getErrorMessage(error: unknown) {
|
||||
if (error instanceof Error) return error.message
|
||||
return String(error)
|
||||
}
|
||||
|
||||
export const isSelfHosted = (): boolean =>
|
||||
process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' &&
|
||||
(process.env['AGENT_ISSELFHOSTED'] === '1' ||
|
||||
process.env['AGENT_ISSELFHOSTED'] === undefined)
|
||||
|
||||
Reference in New Issue
Block a user