mirror of
https://github.com/peter-evans/create-pull-request.git
synced 2026-05-15 02:54:48 +00:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5f6978faf0 | |||
| d32e88dac7 | |||
| 8170bccad1 | |||
| 00418193b4 | |||
| b993918c85 | |||
| 36d7c8468b | |||
| a45d1fb447 | |||
| 3499eb6183 | |||
| 3f3b473b8c | |||
| 6699836a21 | |||
| c0f553fe54 | |||
| 70001242bf | |||
| 34aa40e9cf | |||
| 641099ddca | |||
| 2271f1ddcf | |||
| 437c31a11d | |||
| 0979079bc2 | |||
| 5b751cdf40 |
@@ -29,11 +29,11 @@ jobs:
|
||||
- run: npm run format-check
|
||||
- run: npm run lint
|
||||
- run: npm run test
|
||||
- uses: actions/upload-artifact@v5
|
||||
- uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: dist
|
||||
path: dist
|
||||
- uses: actions/upload-artifact@v5
|
||||
- uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: action.yml
|
||||
path: action.yml
|
||||
@@ -50,12 +50,12 @@ jobs:
|
||||
with:
|
||||
ref: main
|
||||
- if: matrix.target == 'built' || github.event_name == 'pull_request'
|
||||
uses: actions/download-artifact@v6
|
||||
uses: actions/download-artifact@v8
|
||||
with:
|
||||
name: dist
|
||||
path: dist
|
||||
- if: matrix.target == 'built' || github.event_name == 'pull_request'
|
||||
uses: actions/download-artifact@v6
|
||||
uses: actions/download-artifact@v8
|
||||
with:
|
||||
name: action.yml
|
||||
path: .
|
||||
@@ -119,12 +119,12 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/download-artifact@v6
|
||||
- uses: actions/download-artifact@v8
|
||||
with:
|
||||
name: dist
|
||||
path: dist
|
||||
- name: Create Pull Request
|
||||
uses: peter-evans/create-pull-request@v7
|
||||
uses: peter-evans/create-pull-request@v8
|
||||
with:
|
||||
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||
commit-message: 'build: update distribution'
|
||||
|
||||
@@ -32,10 +32,10 @@ Create Pull Request action will:
|
||||
# Make changes to pull request here
|
||||
|
||||
- name: Create Pull Request
|
||||
uses: peter-evans/create-pull-request@v7
|
||||
uses: peter-evans/create-pull-request@v8
|
||||
```
|
||||
|
||||
You can also pin to a [specific release](https://github.com/peter-evans/create-pull-request/releases) version in the format `@v7.x.x`
|
||||
You can also pin to a [specific release](https://github.com/peter-evans/create-pull-request/releases) version in the format `@v8.x.x`
|
||||
|
||||
### Workflow permissions
|
||||
|
||||
@@ -131,7 +131,7 @@ If you want branches to be deleted immediately on merge then you should use GitH
|
||||
For self-hosted runners behind a corporate proxy set the `https_proxy` environment variable.
|
||||
```yml
|
||||
- name: Create Pull Request
|
||||
uses: peter-evans/create-pull-request@v7
|
||||
uses: peter-evans/create-pull-request@v8
|
||||
env:
|
||||
https_proxy: http://<proxy_address>:<port>
|
||||
```
|
||||
@@ -153,7 +153,7 @@ Note that in order to read the step outputs the action step must have an id.
|
||||
```yml
|
||||
- name: Create Pull Request
|
||||
id: cpr
|
||||
uses: peter-evans/create-pull-request@v7
|
||||
uses: peter-evans/create-pull-request@v8
|
||||
- name: Check outputs
|
||||
if: ${{ steps.cpr.outputs.pull-request-number }}
|
||||
run: |
|
||||
@@ -216,7 +216,7 @@ File changes that do not match one of the paths will be stashed and restored aft
|
||||
|
||||
```yml
|
||||
- name: Create Pull Request
|
||||
uses: peter-evans/create-pull-request@v7
|
||||
uses: peter-evans/create-pull-request@v8
|
||||
with:
|
||||
add-paths: |
|
||||
*.java
|
||||
@@ -230,7 +230,7 @@ Note that the repository must be checked out on a branch with a remote, it won't
|
||||
|
||||
```yml
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v6
|
||||
- name: Create commits
|
||||
run: |
|
||||
git config user.name 'Peter Evans'
|
||||
@@ -243,7 +243,7 @@ Note that the repository must be checked out on a branch with a remote, it won't
|
||||
- name: Uncommitted change
|
||||
run: date +%s > report.txt
|
||||
- name: Create Pull Request
|
||||
uses: peter-evans/create-pull-request@v7
|
||||
uses: peter-evans/create-pull-request@v8
|
||||
```
|
||||
|
||||
### Auto-merge
|
||||
@@ -263,14 +263,14 @@ jobs:
|
||||
createPullRequest:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Make changes to pull request
|
||||
run: date +%s > report.txt
|
||||
|
||||
- name: Create Pull Request
|
||||
id: cpr
|
||||
uses: peter-evans/create-pull-request@v7
|
||||
uses: peter-evans/create-pull-request@v8
|
||||
with:
|
||||
token: ${{ secrets.PAT }}
|
||||
commit-message: Update report
|
||||
|
||||
@@ -118,3 +118,71 @@ describe('utils tests', () => {
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('retryWithBackoff', () => {
|
||||
const makeConsistencyError = () => {
|
||||
const error = new Error(
|
||||
'Validation Failed: "Could not resolve to a node with the global id of \'PR_abc123\'."'
|
||||
)
|
||||
;(error as any).status = 422
|
||||
return error
|
||||
}
|
||||
|
||||
const shouldRetry = (e: unknown): boolean =>
|
||||
e instanceof Error &&
|
||||
(e as any).status === 422 &&
|
||||
e.message.includes('Could not resolve to a node')
|
||||
|
||||
test('succeeds on first attempt without retrying', async () => {
|
||||
const fn = jest.fn().mockResolvedValue('success')
|
||||
const result = await utils.retryWithBackoff(fn, shouldRetry, 2, 1)
|
||||
expect(result).toBe('success')
|
||||
expect(fn).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
test('retries on eventual consistency 422 and succeeds', async () => {
|
||||
const fn = jest
|
||||
.fn()
|
||||
.mockRejectedValueOnce(makeConsistencyError())
|
||||
.mockResolvedValue('success')
|
||||
const result = await utils.retryWithBackoff(fn, shouldRetry, 2, 1)
|
||||
expect(result).toBe('success')
|
||||
expect(fn).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
|
||||
test('exhausts retries on persistent 422 and throws', async () => {
|
||||
const fn = jest.fn().mockRejectedValue(makeConsistencyError())
|
||||
await expect(utils.retryWithBackoff(fn, shouldRetry, 2, 1)).rejects.toThrow(
|
||||
'Could not resolve to a node'
|
||||
)
|
||||
expect(fn).toHaveBeenCalledTimes(3) // 1 initial + 2 retries
|
||||
})
|
||||
|
||||
test('does not retry on non-422 errors', async () => {
|
||||
const error = new Error('Forbidden')
|
||||
;(error as any).status = 403
|
||||
const fn = jest.fn().mockRejectedValue(error)
|
||||
await expect(utils.retryWithBackoff(fn, shouldRetry, 2, 1)).rejects.toThrow(
|
||||
'Forbidden'
|
||||
)
|
||||
expect(fn).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
test('does not retry on 422 without the consistency error message', async () => {
|
||||
const error = new Error('Validation Failed: invalid label')
|
||||
;(error as any).status = 422
|
||||
const fn = jest.fn().mockRejectedValue(error)
|
||||
await expect(utils.retryWithBackoff(fn, shouldRetry, 2, 1)).rejects.toThrow(
|
||||
'Validation Failed: invalid label'
|
||||
)
|
||||
expect(fn).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
test('does not retry on plain Error objects', async () => {
|
||||
const fn = jest.fn().mockRejectedValue(new Error('Something broke'))
|
||||
await expect(utils.retryWithBackoff(fn, shouldRetry, 2, 1)).rejects.toThrow(
|
||||
'Something broke'
|
||||
)
|
||||
expect(fn).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
|
||||
Vendored
+223
-56
@@ -458,7 +458,12 @@ function createPullRequest(inputs) {
|
||||
// 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]);
|
||||
try {
|
||||
yield git.exec(['remote', 'prune', branchRemoteName]);
|
||||
}
|
||||
catch (error) {
|
||||
core.warning(`Failed to prune remote '${branchRemoteName}': ${error.message}`);
|
||||
}
|
||||
}
|
||||
core.endGroup();
|
||||
// Apply the branch suffix if set
|
||||
@@ -1370,6 +1375,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.GitHubHelper = void 0;
|
||||
const core = __importStar(__nccwpck_require__(7484));
|
||||
const request_error_1 = __nccwpck_require__(1015);
|
||||
const octokit_client_1 = __nccwpck_require__(3489);
|
||||
const p_limit_1 = __importDefault(__nccwpck_require__(7989));
|
||||
const utils = __importStar(__nccwpck_require__(9277));
|
||||
@@ -1390,6 +1396,7 @@ class GitHubHelper {
|
||||
options.baseUrl = 'https://api.github.com';
|
||||
}
|
||||
options.throttle = octokit_client_1.throttleOptions;
|
||||
options.retry = octokit_client_1.retryOptions;
|
||||
this.octokit = new octokit_client_1.Octokit(options);
|
||||
}
|
||||
parseRepository(repository) {
|
||||
@@ -1495,20 +1502,28 @@ class GitHubHelper {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
// Create or update the pull request
|
||||
const pull = yield this.createOrUpdate(inputs, baseRepository, headRepository);
|
||||
// After creating a new PR, follow-up API calls can fail with a 422
|
||||
// "Could not resolve to a node" error due to GitHub API eventual
|
||||
// consistency. Wrap post-creation calls with targeted retry logic.
|
||||
// See: https://github.com/peter-evans/create-pull-request/issues/4321
|
||||
const isEventualConsistencyError = (e) => e instanceof request_error_1.RequestError &&
|
||||
e.status === 422 &&
|
||||
e.message.includes('Could not resolve to a node');
|
||||
const withRetryForNewPr = (fn) => pull.created ? utils.retryWithBackoff(fn, isEventualConsistencyError) : fn();
|
||||
// Apply milestone
|
||||
if (inputs.milestone) {
|
||||
core.info(`Applying milestone '${inputs.milestone}'`);
|
||||
yield this.octokit.rest.issues.update(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { issue_number: pull.number, milestone: inputs.milestone }));
|
||||
yield withRetryForNewPr(() => this.octokit.rest.issues.update(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { issue_number: pull.number, milestone: inputs.milestone })));
|
||||
}
|
||||
// Apply labels
|
||||
if (inputs.labels.length > 0) {
|
||||
core.info(`Applying labels '${inputs.labels}'`);
|
||||
yield this.octokit.rest.issues.addLabels(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { issue_number: pull.number, labels: inputs.labels }));
|
||||
yield withRetryForNewPr(() => this.octokit.rest.issues.addLabels(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { issue_number: pull.number, labels: inputs.labels })));
|
||||
}
|
||||
// Apply assignees
|
||||
if (inputs.assignees.length > 0) {
|
||||
core.info(`Applying assignees '${inputs.assignees}'`);
|
||||
yield this.octokit.rest.issues.addAssignees(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { issue_number: pull.number, assignees: inputs.assignees }));
|
||||
yield withRetryForNewPr(() => this.octokit.rest.issues.addAssignees(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { issue_number: pull.number, assignees: inputs.assignees })));
|
||||
}
|
||||
// Request reviewers and team reviewers
|
||||
const requestReviewersParams = {};
|
||||
@@ -1523,7 +1538,7 @@ class GitHubHelper {
|
||||
}
|
||||
if (Object.keys(requestReviewersParams).length > 0) {
|
||||
try {
|
||||
yield this.octokit.rest.pulls.requestReviewers(Object.assign(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { pull_number: pull.number }), requestReviewersParams));
|
||||
yield withRetryForNewPr(() => this.octokit.rest.pulls.requestReviewers(Object.assign(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { pull_number: pull.number }), requestReviewersParams)));
|
||||
}
|
||||
catch (e) {
|
||||
if (utils.getErrorMessage(e).includes(ERROR_PR_REVIEW_TOKEN_SCOPE)) {
|
||||
@@ -1819,14 +1834,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.throttleOptions = exports.Octokit = void 0;
|
||||
exports.retryOptions = exports.throttleOptions = exports.Octokit = void 0;
|
||||
const core = __importStar(__nccwpck_require__(7484));
|
||||
const core_1 = __nccwpck_require__(767);
|
||||
const core_1 = __nccwpck_require__(708);
|
||||
const plugin_paginate_rest_1 = __nccwpck_require__(3779);
|
||||
const plugin_rest_endpoint_methods_1 = __nccwpck_require__(9210);
|
||||
const plugin_retry_1 = __nccwpck_require__(9735);
|
||||
const plugin_throttling_1 = __nccwpck_require__(6856);
|
||||
const proxy_1 = __nccwpck_require__(3459);
|
||||
exports.Octokit = core_1.Octokit.plugin(plugin_paginate_rest_1.paginateRest, plugin_rest_endpoint_methods_1.restEndpointMethods, plugin_throttling_1.throttling, autoProxyAgent);
|
||||
exports.Octokit = core_1.Octokit.plugin(plugin_paginate_rest_1.paginateRest, plugin_rest_endpoint_methods_1.restEndpointMethods, plugin_retry_1.retry, plugin_throttling_1.throttling, autoProxyAgent);
|
||||
exports.throttleOptions = {
|
||||
onRateLimit: (retryAfter, options, _, retryCount) => {
|
||||
core.debug(`Hit rate limit for request ${options.method} ${options.url}`);
|
||||
@@ -1841,6 +1857,10 @@ exports.throttleOptions = {
|
||||
core.warning(`Requests may be retried after ${retryAfter} seconds.`);
|
||||
}
|
||||
};
|
||||
exports.retryOptions = {
|
||||
// 429 is handled by the throttling plugin, so we exclude it from retry
|
||||
doNotRetry: [400, 401, 403, 404, 410, 422, 429, 451]
|
||||
};
|
||||
// Octokit plugin to support the standard environment variables http_proxy, https_proxy and no_proxy
|
||||
function autoProxyAgent(octokit) {
|
||||
octokit.hook.before('request', options => {
|
||||
@@ -1889,6 +1909,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.isSelfHosted = void 0;
|
||||
exports.getInputAsArray = getInputAsArray;
|
||||
@@ -1902,6 +1931,7 @@ exports.parseDisplayNameEmail = parseDisplayNameEmail;
|
||||
exports.fileExistsSync = fileExistsSync;
|
||||
exports.readFile = readFile;
|
||||
exports.getErrorMessage = getErrorMessage;
|
||||
exports.retryWithBackoff = retryWithBackoff;
|
||||
const core = __importStar(__nccwpck_require__(7484));
|
||||
const fs = __importStar(__nccwpck_require__(9896));
|
||||
const path = __importStar(__nccwpck_require__(6928));
|
||||
@@ -2003,6 +2033,26 @@ const isSelfHosted = () => process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted'
|
||||
(process.env['AGENT_ISSELFHOSTED'] === '1' ||
|
||||
process.env['AGENT_ISSELFHOSTED'] === undefined);
|
||||
exports.isSelfHosted = isSelfHosted;
|
||||
function retryWithBackoff(fn_1, shouldRetry_1) {
|
||||
return __awaiter(this, arguments, void 0, function* (fn, shouldRetry, maxRetries = 2, delayMs = 1000) {
|
||||
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
||||
try {
|
||||
return yield fn();
|
||||
}
|
||||
catch (e) {
|
||||
if (attempt < maxRetries && shouldRetry(e)) {
|
||||
const delay = delayMs * Math.pow(2, attempt);
|
||||
core.info(`Request failed (attempt ${attempt + 1}/${maxRetries + 1}), retrying in ${delay}ms...`);
|
||||
yield new Promise(resolve => setTimeout(resolve, delay));
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Error('Unexpected: retry loop exited without return or throw');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
@@ -4511,7 +4561,7 @@ class HttpClient {
|
||||
}
|
||||
const usingSsl = parsedUrl.protocol === 'https:';
|
||||
proxyAgent = new undici_1.ProxyAgent(Object.assign({ uri: proxyUrl.href, pipelining: !this._keepAlive ? 0 : 1 }, ((proxyUrl.username || proxyUrl.password) && {
|
||||
token: `${proxyUrl.username}:${proxyUrl.password}`
|
||||
token: `Basic ${Buffer.from(`${proxyUrl.username}:${proxyUrl.password}`).toString('base64')}`
|
||||
})));
|
||||
this._proxyAgentDispatcher = proxyAgent;
|
||||
if (usingSsl && this._ignoreSslError) {
|
||||
@@ -4625,11 +4675,11 @@ function getProxyUrl(reqUrl) {
|
||||
})();
|
||||
if (proxyVar) {
|
||||
try {
|
||||
return new URL(proxyVar);
|
||||
return new DecodedURL(proxyVar);
|
||||
}
|
||||
catch (_a) {
|
||||
if (!proxyVar.startsWith('http://') && !proxyVar.startsWith('https://'))
|
||||
return new URL(`http://${proxyVar}`);
|
||||
return new DecodedURL(`http://${proxyVar}`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -4688,6 +4738,19 @@ function isLoopbackAddress(host) {
|
||||
hostLower.startsWith('[::1]') ||
|
||||
hostLower.startsWith('[0:0:0:0:0:0:0:1]'));
|
||||
}
|
||||
class DecodedURL extends URL {
|
||||
constructor(url, base) {
|
||||
super(url, base);
|
||||
this._decodedUsername = decodeURIComponent(super.username);
|
||||
this._decodedPassword = decodeURIComponent(super.password);
|
||||
}
|
||||
get username() {
|
||||
return this._decodedUsername;
|
||||
}
|
||||
get password() {
|
||||
return this._decodedPassword;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=proxy.js.map
|
||||
|
||||
/***/ }),
|
||||
@@ -32203,7 +32266,7 @@ module.exports = fetch;
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 767:
|
||||
/***/ 708:
|
||||
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __nccwpck_require__) => {
|
||||
|
||||
"use strict";
|
||||
@@ -32723,46 +32786,8 @@ var endpoint = withDefaults(null, DEFAULTS);
|
||||
|
||||
// EXTERNAL MODULE: ./node_modules/fast-content-type-parse/index.js
|
||||
var fast_content_type_parse = __nccwpck_require__(8739);
|
||||
;// CONCATENATED MODULE: ./node_modules/@octokit/request-error/dist-src/index.js
|
||||
class RequestError extends Error {
|
||||
name;
|
||||
/**
|
||||
* http status code
|
||||
*/
|
||||
status;
|
||||
/**
|
||||
* Request options that lead to the error.
|
||||
*/
|
||||
request;
|
||||
/**
|
||||
* Response object if a response was received
|
||||
*/
|
||||
response;
|
||||
constructor(message, statusCode, options) {
|
||||
super(message);
|
||||
this.name = "HttpError";
|
||||
this.status = Number.parseInt(statusCode);
|
||||
if (Number.isNaN(this.status)) {
|
||||
this.status = 0;
|
||||
}
|
||||
if ("response" in options) {
|
||||
this.response = options.response;
|
||||
}
|
||||
const requestCopy = Object.assign({}, options.request);
|
||||
if (options.request.headers.authorization) {
|
||||
requestCopy.headers = Object.assign({}, options.request.headers, {
|
||||
authorization: options.request.headers.authorization.replace(
|
||||
/(?<! ) .*$/,
|
||||
" [REDACTED]"
|
||||
)
|
||||
});
|
||||
}
|
||||
requestCopy.url = requestCopy.url.replace(/\bclient_secret=\w+/g, "client_secret=[REDACTED]").replace(/\baccess_token=\w+/g, "access_token=[REDACTED]");
|
||||
this.request = requestCopy;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// EXTERNAL MODULE: ./node_modules/@octokit/request-error/dist-src/index.js
|
||||
var dist_src = __nccwpck_require__(1015);
|
||||
;// CONCATENATED MODULE: ./node_modules/@octokit/request/dist-bundle/index.js
|
||||
// pkg/dist-src/index.js
|
||||
|
||||
@@ -32839,7 +32864,7 @@ async function fetchWrapper(requestOptions) {
|
||||
}
|
||||
}
|
||||
}
|
||||
const requestError = new RequestError(message, 500, {
|
||||
const requestError = new dist_src.RequestError(message, 500, {
|
||||
request: requestOptions
|
||||
});
|
||||
requestError.cause = error;
|
||||
@@ -32871,21 +32896,21 @@ async function fetchWrapper(requestOptions) {
|
||||
if (status < 400) {
|
||||
return octokitResponse;
|
||||
}
|
||||
throw new RequestError(fetchResponse.statusText, status, {
|
||||
throw new dist_src.RequestError(fetchResponse.statusText, status, {
|
||||
response: octokitResponse,
|
||||
request: requestOptions
|
||||
});
|
||||
}
|
||||
if (status === 304) {
|
||||
octokitResponse.data = await getResponseData(fetchResponse);
|
||||
throw new RequestError("Not modified", status, {
|
||||
throw new dist_src.RequestError("Not modified", status, {
|
||||
response: octokitResponse,
|
||||
request: requestOptions
|
||||
});
|
||||
}
|
||||
if (status >= 400) {
|
||||
octokitResponse.data = await getResponseData(fetchResponse);
|
||||
throw new RequestError(toErrorMessage(octokitResponse.data), status, {
|
||||
throw new dist_src.RequestError(toErrorMessage(octokitResponse.data), status, {
|
||||
response: octokitResponse,
|
||||
request: requestOptions
|
||||
});
|
||||
@@ -36182,6 +36207,98 @@ legacyRestEndpointMethods.VERSION = VERSION;
|
||||
//# sourceMappingURL=index.js.map
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 9735:
|
||||
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __nccwpck_require__) => {
|
||||
|
||||
"use strict";
|
||||
__nccwpck_require__.r(__webpack_exports__);
|
||||
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
|
||||
/* harmony export */ VERSION: () => (/* binding */ VERSION),
|
||||
/* harmony export */ retry: () => (/* binding */ retry)
|
||||
/* harmony export */ });
|
||||
/* harmony import */ var bottleneck_light_js__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(3251);
|
||||
/* harmony import */ var _octokit_request_error__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(1015);
|
||||
// pkg/dist-src/version.js
|
||||
var VERSION = "0.0.0-development";
|
||||
|
||||
// pkg/dist-src/error-request.js
|
||||
async function errorRequest(state, octokit, error, options) {
|
||||
if (!error.request || !error.request.request) {
|
||||
throw error;
|
||||
}
|
||||
if (error.status >= 400 && !state.doNotRetry.includes(error.status)) {
|
||||
const retries = options.request.retries != null ? options.request.retries : state.retries;
|
||||
const retryAfter = Math.pow((options.request.retryCount || 0) + 1, 2);
|
||||
throw octokit.retry.retryRequest(error, retries, retryAfter);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
// pkg/dist-src/wrap-request.js
|
||||
|
||||
|
||||
async function wrapRequest(state, octokit, request, options) {
|
||||
const limiter = new bottleneck_light_js__WEBPACK_IMPORTED_MODULE_0__();
|
||||
limiter.on("failed", function(error, info) {
|
||||
const maxRetries = ~~error.request.request.retries;
|
||||
const after = ~~error.request.request.retryAfter;
|
||||
options.request.retryCount = info.retryCount + 1;
|
||||
if (maxRetries > info.retryCount) {
|
||||
return after * state.retryAfterBaseValue;
|
||||
}
|
||||
});
|
||||
return limiter.schedule(
|
||||
requestWithGraphqlErrorHandling.bind(null, state, octokit, request),
|
||||
options
|
||||
);
|
||||
}
|
||||
async function requestWithGraphqlErrorHandling(state, octokit, request, options) {
|
||||
const response = await request(request, options);
|
||||
if (response.data && response.data.errors && response.data.errors.length > 0 && /Something went wrong while executing your query/.test(
|
||||
response.data.errors[0].message
|
||||
)) {
|
||||
const error = new _octokit_request_error__WEBPACK_IMPORTED_MODULE_1__.RequestError(response.data.errors[0].message, 500, {
|
||||
request: options,
|
||||
response
|
||||
});
|
||||
return errorRequest(state, octokit, error, options);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
// pkg/dist-src/index.js
|
||||
function retry(octokit, octokitOptions) {
|
||||
const state = Object.assign(
|
||||
{
|
||||
enabled: true,
|
||||
retryAfterBaseValue: 1e3,
|
||||
doNotRetry: [400, 401, 403, 404, 410, 422, 451],
|
||||
retries: 3
|
||||
},
|
||||
octokitOptions.retry
|
||||
);
|
||||
if (state.enabled) {
|
||||
octokit.hook.error("request", errorRequest.bind(null, state, octokit));
|
||||
octokit.hook.wrap("request", wrapRequest.bind(null, state, octokit));
|
||||
}
|
||||
return {
|
||||
retry: {
|
||||
retryRequest: (error, retries, retryAfter) => {
|
||||
error.request.request = Object.assign({}, error.request.request, {
|
||||
retries,
|
||||
retryAfter
|
||||
});
|
||||
return error;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
retry.VERSION = VERSION;
|
||||
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6856:
|
||||
@@ -36421,6 +36538,56 @@ throttling.triggersNotification = triggersNotification;
|
||||
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1015:
|
||||
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __nccwpck_require__) => {
|
||||
|
||||
"use strict";
|
||||
__nccwpck_require__.r(__webpack_exports__);
|
||||
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
|
||||
/* harmony export */ RequestError: () => (/* binding */ RequestError)
|
||||
/* harmony export */ });
|
||||
class RequestError extends Error {
|
||||
name;
|
||||
/**
|
||||
* http status code
|
||||
*/
|
||||
status;
|
||||
/**
|
||||
* Request options that lead to the error.
|
||||
*/
|
||||
request;
|
||||
/**
|
||||
* Response object if a response was received
|
||||
*/
|
||||
response;
|
||||
constructor(message, statusCode, options) {
|
||||
super(message);
|
||||
this.name = "HttpError";
|
||||
this.status = Number.parseInt(statusCode);
|
||||
if (Number.isNaN(this.status)) {
|
||||
this.status = 0;
|
||||
}
|
||||
if ("response" in options) {
|
||||
this.response = options.response;
|
||||
}
|
||||
const requestCopy = Object.assign({}, options.request);
|
||||
if (options.request.headers.authorization) {
|
||||
requestCopy.headers = Object.assign({}, options.request.headers, {
|
||||
authorization: options.request.headers.authorization.replace(
|
||||
/(?<! ) .*$/,
|
||||
" [REDACTED]"
|
||||
)
|
||||
});
|
||||
}
|
||||
requestCopy.url = requestCopy.url.replace(/\bclient_secret=\w+/g, "client_secret=[REDACTED]").replace(/\baccess_token=\w+/g, "access_token=[REDACTED]");
|
||||
this.request = requestCopy;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7989:
|
||||
|
||||
Generated
+869
-393
File diff suppressed because it is too large
Load Diff
+7
-5
@@ -37,7 +37,9 @@
|
||||
"@octokit/core": "^6.1.6",
|
||||
"@octokit/plugin-paginate-rest": "^11.6.0",
|
||||
"@octokit/plugin-rest-endpoint-methods": "^13.5.0",
|
||||
"@octokit/plugin-retry": "^7.2.1",
|
||||
"@octokit/plugin-throttling": "^9.6.1",
|
||||
"@octokit/request-error": "^6.1.8",
|
||||
"node-fetch-native": "^1.6.7",
|
||||
"p-limit": "^6.2.0",
|
||||
"uuid": "^9.0.1"
|
||||
@@ -53,14 +55,14 @@
|
||||
"eslint-plugin-github": "^4.10.2",
|
||||
"eslint-plugin-import": "^2.32.0",
|
||||
"eslint-plugin-jest": "^27.9.0",
|
||||
"eslint-plugin-prettier": "^5.5.4",
|
||||
"eslint-plugin-prettier": "^5.5.5",
|
||||
"jest": "^29.7.0",
|
||||
"jest-circus": "^29.7.0",
|
||||
"jest-environment-jsdom": "^29.7.0",
|
||||
"jest-environment-jsdom": "^30.3.0",
|
||||
"js-yaml": "^4.1.1",
|
||||
"prettier": "^3.7.3",
|
||||
"ts-jest": "^29.4.5",
|
||||
"prettier": "^3.8.1",
|
||||
"ts-jest": "^29.4.9",
|
||||
"typescript": "^5.9.3",
|
||||
"undici": "^6.22.0"
|
||||
"undici": "^6.24.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,13 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
|
||||
// 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])
|
||||
try {
|
||||
await git.exec(['remote', 'prune', branchRemoteName])
|
||||
} catch (error) {
|
||||
core.warning(
|
||||
`Failed to prune remote '${branchRemoteName}': ${(error as Error).message}`
|
||||
)
|
||||
}
|
||||
}
|
||||
core.endGroup()
|
||||
|
||||
|
||||
+49
-21
@@ -1,7 +1,13 @@
|
||||
import * as core from '@actions/core'
|
||||
import {RequestError} from '@octokit/request-error'
|
||||
import {Inputs} from './create-pull-request'
|
||||
import {Commit, GitCommandManager} from './git-command-manager'
|
||||
import {Octokit, OctokitOptions, throttleOptions} from './octokit-client'
|
||||
import {
|
||||
Octokit,
|
||||
OctokitOptions,
|
||||
retryOptions,
|
||||
throttleOptions
|
||||
} from './octokit-client'
|
||||
import pLimit from 'p-limit'
|
||||
import * as utils from './utils'
|
||||
|
||||
@@ -52,6 +58,7 @@ export class GitHubHelper {
|
||||
options.baseUrl = 'https://api.github.com'
|
||||
}
|
||||
options.throttle = throttleOptions
|
||||
options.retry = retryOptions
|
||||
this.octokit = new Octokit(options)
|
||||
}
|
||||
|
||||
@@ -203,32 +210,51 @@ export class GitHubHelper {
|
||||
headRepository
|
||||
)
|
||||
|
||||
// After creating a new PR, follow-up API calls can fail with a 422
|
||||
// "Could not resolve to a node" error due to GitHub API eventual
|
||||
// consistency. Wrap post-creation calls with targeted retry logic.
|
||||
// See: https://github.com/peter-evans/create-pull-request/issues/4321
|
||||
const isEventualConsistencyError = (e: unknown): boolean =>
|
||||
e instanceof RequestError &&
|
||||
e.status === 422 &&
|
||||
e.message.includes('Could not resolve to a node')
|
||||
const withRetryForNewPr = <T>(fn: () => Promise<T>): Promise<T> =>
|
||||
pull.created
|
||||
? utils.retryWithBackoff(fn, isEventualConsistencyError)
|
||||
: fn()
|
||||
|
||||
// Apply milestone
|
||||
if (inputs.milestone) {
|
||||
core.info(`Applying milestone '${inputs.milestone}'`)
|
||||
await this.octokit.rest.issues.update({
|
||||
...this.parseRepository(baseRepository),
|
||||
issue_number: pull.number,
|
||||
milestone: inputs.milestone
|
||||
})
|
||||
await withRetryForNewPr(() =>
|
||||
this.octokit.rest.issues.update({
|
||||
...this.parseRepository(baseRepository),
|
||||
issue_number: pull.number,
|
||||
milestone: inputs.milestone
|
||||
})
|
||||
)
|
||||
}
|
||||
// Apply labels
|
||||
if (inputs.labels.length > 0) {
|
||||
core.info(`Applying labels '${inputs.labels}'`)
|
||||
await this.octokit.rest.issues.addLabels({
|
||||
...this.parseRepository(baseRepository),
|
||||
issue_number: pull.number,
|
||||
labels: inputs.labels
|
||||
})
|
||||
await withRetryForNewPr(() =>
|
||||
this.octokit.rest.issues.addLabels({
|
||||
...this.parseRepository(baseRepository),
|
||||
issue_number: pull.number,
|
||||
labels: inputs.labels
|
||||
})
|
||||
)
|
||||
}
|
||||
// Apply assignees
|
||||
if (inputs.assignees.length > 0) {
|
||||
core.info(`Applying assignees '${inputs.assignees}'`)
|
||||
await this.octokit.rest.issues.addAssignees({
|
||||
...this.parseRepository(baseRepository),
|
||||
issue_number: pull.number,
|
||||
assignees: inputs.assignees
|
||||
})
|
||||
await withRetryForNewPr(() =>
|
||||
this.octokit.rest.issues.addAssignees({
|
||||
...this.parseRepository(baseRepository),
|
||||
issue_number: pull.number,
|
||||
assignees: inputs.assignees
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
// Request reviewers and team reviewers
|
||||
@@ -244,11 +270,13 @@ export class GitHubHelper {
|
||||
}
|
||||
if (Object.keys(requestReviewersParams).length > 0) {
|
||||
try {
|
||||
await this.octokit.rest.pulls.requestReviewers({
|
||||
...this.parseRepository(baseRepository),
|
||||
pull_number: pull.number,
|
||||
...requestReviewersParams
|
||||
})
|
||||
await withRetryForNewPr(() =>
|
||||
this.octokit.rest.pulls.requestReviewers({
|
||||
...this.parseRepository(baseRepository),
|
||||
pull_number: pull.number,
|
||||
...requestReviewersParams
|
||||
})
|
||||
)
|
||||
} catch (e) {
|
||||
if (utils.getErrorMessage(e).includes(ERROR_PR_REVIEW_TOKEN_SCOPE)) {
|
||||
core.error(
|
||||
|
||||
@@ -2,6 +2,7 @@ import * as core from '@actions/core'
|
||||
import {Octokit as OctokitCore} from '@octokit/core'
|
||||
import {paginateRest} from '@octokit/plugin-paginate-rest'
|
||||
import {restEndpointMethods} from '@octokit/plugin-rest-endpoint-methods'
|
||||
import {retry} from '@octokit/plugin-retry'
|
||||
import {throttling} from '@octokit/plugin-throttling'
|
||||
import {fetch} from 'node-fetch-native/proxy'
|
||||
export {RestEndpointMethodTypes} from '@octokit/plugin-rest-endpoint-methods'
|
||||
@@ -11,6 +12,7 @@ export {OctokitOptions} from '@octokit/core/dist-types/types'
|
||||
export const Octokit = OctokitCore.plugin(
|
||||
paginateRest,
|
||||
restEndpointMethods,
|
||||
retry,
|
||||
throttling,
|
||||
autoProxyAgent
|
||||
)
|
||||
@@ -32,6 +34,11 @@ export const throttleOptions = {
|
||||
}
|
||||
}
|
||||
|
||||
export const retryOptions = {
|
||||
// 429 is handled by the throttling plugin, so we exclude it from retry
|
||||
doNotRetry: [400, 401, 403, 404, 410, 422, 429, 451]
|
||||
}
|
||||
|
||||
// Octokit plugin to support the standard environment variables http_proxy, https_proxy and no_proxy
|
||||
function autoProxyAgent(octokit: OctokitCore) {
|
||||
octokit.hook.before('request', options => {
|
||||
|
||||
@@ -140,3 +140,27 @@ export const isSelfHosted = (): boolean =>
|
||||
process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' &&
|
||||
(process.env['AGENT_ISSELFHOSTED'] === '1' ||
|
||||
process.env['AGENT_ISSELFHOSTED'] === undefined)
|
||||
|
||||
export async function retryWithBackoff<T>(
|
||||
fn: () => Promise<T>,
|
||||
shouldRetry: (error: unknown) => boolean,
|
||||
maxRetries = 2,
|
||||
delayMs = 1000
|
||||
): Promise<T> {
|
||||
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
||||
try {
|
||||
return await fn()
|
||||
} catch (e) {
|
||||
if (attempt < maxRetries && shouldRetry(e)) {
|
||||
const delay = delayMs * Math.pow(2, attempt)
|
||||
core.info(
|
||||
`Request failed (attempt ${attempt + 1}/${maxRetries + 1}), retrying in ${delay}ms...`
|
||||
)
|
||||
await new Promise(resolve => setTimeout(resolve, delay))
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Error('Unexpected: retry loop exited without return or throw')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user