Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
20dac2ed48 | |||
8557470a68 | |||
10db75894f | |||
5a6b15373e | |||
923ad837f1 | |||
f094b77505 | |||
af7c021bb9 | |||
97872c4843 | |||
bd72e1b792 |
@ -36,6 +36,13 @@ Create Pull Request action will:
|
|||||||
|
|
||||||
You can also pin to a [specific release](https://github.com/peter-evans/create-pull-request/releases) version in the format `@v4.x.x`
|
You can also pin to a [specific release](https://github.com/peter-evans/create-pull-request/releases) version in the format `@v4.x.x`
|
||||||
|
|
||||||
|
### Workflow permissions
|
||||||
|
|
||||||
|
For this action to work you must explicitly allow GitHub Actions to create pull requests.
|
||||||
|
This setting can be found in a repository's settings under Actions > General > Workflow permissions.
|
||||||
|
|
||||||
|
For repositories belonging to an organization, this setting can be managed by admins in organization settings under Actions > General > Workflow permissions.
|
||||||
|
|
||||||
### Action inputs
|
### Action inputs
|
||||||
|
|
||||||
All inputs are **optional**. If not set, sensible defaults will be used.
|
All inputs are **optional**. If not set, sensible defaults will be used.
|
||||||
@ -106,7 +113,7 @@ How the action behaves:
|
|||||||
|
|
||||||
- If there are changes (i.e. a diff exists with the checked-out base branch), the changes will be pushed to a new `branch` and a pull request created.
|
- If there are changes (i.e. a diff exists with the checked-out base branch), the changes will be pushed to a new `branch` and a pull request created.
|
||||||
- If there are no changes (i.e. no diff exists with the checked-out base branch), no pull request will be created and the action exits silently.
|
- If there are no changes (i.e. no diff exists with the checked-out base branch), no pull request will be created and the action exits silently.
|
||||||
- If a pull request already exists and there are no further changes (i.e. no diff with the current pull request branch) then the action exits silently.
|
- If a pull request already exists it will be updated if necessary. Local changes in the Actions workspace, or changes on the base branch, can cause an update. If no update is required the action exits silently.
|
||||||
- If a pull request exists and new changes on the base branch make the pull request unnecessary (i.e. there is no longer a diff between the pull request branch and the base), the pull request is automatically closed. Additionally, if `delete-branch` is set to `true` the `branch` will be deleted.
|
- If a pull request exists and new changes on the base branch make the pull request unnecessary (i.e. there is no longer a diff between the pull request branch and the base), the pull request is automatically closed. Additionally, if `delete-branch` is set to `true` the `branch` will be deleted.
|
||||||
|
|
||||||
For further details about how the action works and usage guidelines, see [Concepts, guidelines and advanced usage](docs/concepts-guidelines.md).
|
For further details about how the action works and usage guidelines, see [Concepts, guidelines and advanced usage](docs/concepts-guidelines.md).
|
||||||
|
@ -10,7 +10,7 @@ if [[ "$(docker images -q $IMAGE 2> /dev/null)" == "" || $ARG1 == "build" ]]; th
|
|||||||
cat > Dockerfile << EOF
|
cat > Dockerfile << EOF
|
||||||
FROM node:12-alpine
|
FROM node:12-alpine
|
||||||
RUN apk --no-cache add git git-daemon
|
RUN apk --no-cache add git git-daemon
|
||||||
RUN npm install jest --global
|
RUN npm install jest jest-environment-jsdom --global
|
||||||
WORKDIR /cpr
|
WORKDIR /cpr
|
||||||
COPY __test__/entrypoint.sh /entrypoint.sh
|
COPY __test__/entrypoint.sh /entrypoint.sh
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
|
27
dist/index.js
vendored
27
dist/index.js
vendored
@ -62,7 +62,9 @@ exports.getWorkingBaseAndType = getWorkingBaseAndType;
|
|||||||
function tryFetch(git, remote, branch) {
|
function tryFetch(git, remote, branch) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
yield git.fetch([`${branch}:refs/remotes/${remote}/${branch}`], remote);
|
yield git.fetch([`${branch}:refs/remotes/${remote}/${branch}`], remote, [
|
||||||
|
'--force'
|
||||||
|
]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (_a) {
|
catch (_a) {
|
||||||
@ -950,8 +952,11 @@ class GitHubHelper {
|
|||||||
repo: repo
|
repo: repo
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
createOrUpdate(inputs, baseRepository, headBranch) {
|
createOrUpdate(inputs, baseRepository, headRepository) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const [headOwner] = headRepository.split('/');
|
||||||
|
const headBranch = `${headOwner}:${inputs.branch}`;
|
||||||
|
const headBranchFull = `${headRepository}:${inputs.branch}`;
|
||||||
// Try to create the pull request
|
// Try to create the pull request
|
||||||
try {
|
try {
|
||||||
core.info(`Attempting creation of pull request`);
|
core.info(`Attempting creation of pull request`);
|
||||||
@ -965,7 +970,7 @@ class GitHubHelper {
|
|||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
if (e.message &&
|
if (e.message &&
|
||||||
e.message.includes(`A pull request already exists for ${headBranch}`)) {
|
e.message.includes(`A pull request already exists for`)) {
|
||||||
core.info(`A pull request already exists for ${headBranch}`);
|
core.info(`A pull request already exists for ${headBranch}`);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -974,7 +979,7 @@ class GitHubHelper {
|
|||||||
}
|
}
|
||||||
// Update the pull request that exists for this branch and base
|
// Update the pull request that exists for this branch and base
|
||||||
core.info(`Fetching existing pull request`);
|
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 { data: pulls } = yield this.octokit.rest.pulls.list(Object.assign(Object.assign({}, this.parseRepository(baseRepository)), { state: 'open', head: headBranchFull, base: inputs.base }));
|
||||||
core.info(`Attempting update of pull request`);
|
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: pulls[0].number, title: inputs.title, body: inputs.body }));
|
||||||
core.info(`Updated pull request #${pull.number} (${headBranch} => ${inputs.base})`);
|
core.info(`Updated pull request #${pull.number} (${headBranch} => ${inputs.base})`);
|
||||||
@ -996,10 +1001,8 @@ class GitHubHelper {
|
|||||||
}
|
}
|
||||||
createOrUpdatePullRequest(inputs, baseRepository, headRepository) {
|
createOrUpdatePullRequest(inputs, baseRepository, headRepository) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const [headOwner] = headRepository.split('/');
|
|
||||||
const headBranch = `${headOwner}:${inputs.branch}`;
|
|
||||||
// Create or update the pull request
|
// Create or update the pull request
|
||||||
const pull = yield this.createOrUpdate(inputs, baseRepository, headBranch);
|
const pull = yield this.createOrUpdate(inputs, baseRepository, headRepository);
|
||||||
// Apply milestone
|
// Apply milestone
|
||||||
if (inputs.milestone) {
|
if (inputs.milestone) {
|
||||||
core.info(`Applying milestone '${inputs.milestone}'`);
|
core.info(`Applying milestone '${inputs.milestone}'`);
|
||||||
@ -1135,13 +1138,21 @@ const plugin_paginate_rest_1 = __nccwpck_require__(4193);
|
|||||||
const plugin_rest_endpoint_methods_1 = __nccwpck_require__(3044);
|
const plugin_rest_endpoint_methods_1 = __nccwpck_require__(3044);
|
||||||
const https_proxy_agent_1 = __nccwpck_require__(7219);
|
const https_proxy_agent_1 = __nccwpck_require__(7219);
|
||||||
exports.Octokit = core_1.Octokit.plugin(plugin_paginate_rest_1.paginateRest, plugin_rest_endpoint_methods_1.restEndpointMethods, autoProxyAgent);
|
exports.Octokit = core_1.Octokit.plugin(plugin_paginate_rest_1.paginateRest, plugin_rest_endpoint_methods_1.restEndpointMethods, autoProxyAgent);
|
||||||
// Octokit plugin to support the https_proxy environment variable
|
// Octokit plugin to support the https_proxy and no_proxy environment variable
|
||||||
function autoProxyAgent(octokit) {
|
function autoProxyAgent(octokit) {
|
||||||
const proxy = process.env.https_proxy || process.env.HTTPS_PROXY;
|
const proxy = process.env.https_proxy || process.env.HTTPS_PROXY;
|
||||||
|
const noProxy = process.env.no_proxy || process.env.NO_PROXY;
|
||||||
|
let noProxyArray = [];
|
||||||
|
if (noProxy) {
|
||||||
|
noProxyArray = noProxy.split(',');
|
||||||
|
}
|
||||||
if (!proxy)
|
if (!proxy)
|
||||||
return;
|
return;
|
||||||
const agent = new https_proxy_agent_1.HttpsProxyAgent(proxy);
|
const agent = new https_proxy_agent_1.HttpsProxyAgent(proxy);
|
||||||
octokit.hook.before('request', options => {
|
octokit.hook.before('request', options => {
|
||||||
|
if (noProxyArray.includes(options.request.hostname)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
options.request.agent = agent;
|
options.request.agent = agent;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -136,9 +136,9 @@ For further reading regarding the security of pull requests, see this GitHub blo
|
|||||||
|
|
||||||
Pull requests created by the action using the default `GITHUB_TOKEN` cannot trigger other workflows. If you have `on: pull_request` or `on: push` workflows acting as checks on pull requests, they will not run.
|
Pull requests created by the action using the default `GITHUB_TOKEN` cannot trigger other workflows. If you have `on: pull_request` or `on: push` workflows acting as checks on pull requests, they will not run.
|
||||||
|
|
||||||
> When you use the repository's GITHUB_TOKEN to perform tasks on behalf of the GitHub Actions app, events triggered by the GITHUB_TOKEN will not create a new workflow run.
|
> When you use the repository's `GITHUB_TOKEN` to perform tasks, events triggered by the `GITHUB_TOKEN` will not create a new workflow run. This prevents you from accidentally creating recursive workflow runs. For example, if a workflow run pushes code using the repository's `GITHUB_TOKEN`, a new workflow will not run even when the repository contains a workflow configured to run when `push` events occur.
|
||||||
|
|
||||||
[GitHub Actions: Events that trigger workflows](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token)
|
[GitHub Actions: Triggering a workflow from a workflow](https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow)
|
||||||
|
|
||||||
#### Workarounds to trigger further workflow runs
|
#### Workarounds to trigger further workflow runs
|
||||||
|
|
||||||
|
5608
package-lock.json
generated
5608
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
@ -38,7 +38,7 @@
|
|||||||
"uuid": "^8.3.2"
|
"uuid": "^8.3.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^27.0.3",
|
"@types/jest": "^27.5.0",
|
||||||
"@types/node": "^16.11.11",
|
"@types/node": "^16.11.11",
|
||||||
"@typescript-eslint/parser": "^5.5.0",
|
"@typescript-eslint/parser": "^5.5.0",
|
||||||
"@vercel/ncc": "^0.32.0",
|
"@vercel/ncc": "^0.32.0",
|
||||||
@ -46,12 +46,13 @@
|
|||||||
"eslint-import-resolver-typescript": "^2.5.0",
|
"eslint-import-resolver-typescript": "^2.5.0",
|
||||||
"eslint-plugin-github": "^4.3.5",
|
"eslint-plugin-github": "^4.3.5",
|
||||||
"eslint-plugin-import": "^2.25.3",
|
"eslint-plugin-import": "^2.25.3",
|
||||||
"eslint-plugin-jest": "^25.3.0",
|
"eslint-plugin-jest": "^26.1.5",
|
||||||
"jest": "^27.4.3",
|
"jest": "^28.1.0",
|
||||||
"jest-circus": "^27.4.2",
|
"jest-circus": "^28.1.0",
|
||||||
|
"jest-environment-jsdom": "^28.1.0",
|
||||||
"js-yaml": "^4.1.0",
|
"js-yaml": "^4.1.0",
|
||||||
"prettier": "^2.5.0",
|
"prettier": "^2.5.0",
|
||||||
"ts-jest": "^27.0.7",
|
"ts-jest": "^28.0.2",
|
||||||
"typescript": "^4.5.2"
|
"typescript": "^4.5.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,9 @@ export async function tryFetch(
|
|||||||
branch: string
|
branch: string
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
await git.fetch([`${branch}:refs/remotes/${remote}/${branch}`], remote)
|
await git.fetch([`${branch}:refs/remotes/${remote}/${branch}`], remote, [
|
||||||
|
'--force'
|
||||||
|
])
|
||||||
return true
|
return true
|
||||||
} catch {
|
} catch {
|
||||||
return false
|
return false
|
||||||
|
@ -39,8 +39,12 @@ export class GitHubHelper {
|
|||||||
private async createOrUpdate(
|
private async createOrUpdate(
|
||||||
inputs: Inputs,
|
inputs: Inputs,
|
||||||
baseRepository: string,
|
baseRepository: string,
|
||||||
headBranch: string
|
headRepository: string
|
||||||
): Promise<Pull> {
|
): Promise<Pull> {
|
||||||
|
const [headOwner] = headRepository.split('/')
|
||||||
|
const headBranch = `${headOwner}:${inputs.branch}`
|
||||||
|
const headBranchFull = `${headRepository}:${inputs.branch}`
|
||||||
|
|
||||||
// Try to create the pull request
|
// Try to create the pull request
|
||||||
try {
|
try {
|
||||||
core.info(`Attempting creation of pull request`)
|
core.info(`Attempting creation of pull request`)
|
||||||
@ -63,7 +67,7 @@ export class GitHubHelper {
|
|||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
if (
|
if (
|
||||||
e.message &&
|
e.message &&
|
||||||
e.message.includes(`A pull request already exists for ${headBranch}`)
|
e.message.includes(`A pull request already exists for`)
|
||||||
) {
|
) {
|
||||||
core.info(`A pull request already exists for ${headBranch}`)
|
core.info(`A pull request already exists for ${headBranch}`)
|
||||||
} else {
|
} else {
|
||||||
@ -76,7 +80,7 @@ export class GitHubHelper {
|
|||||||
const {data: pulls} = await this.octokit.rest.pulls.list({
|
const {data: pulls} = await this.octokit.rest.pulls.list({
|
||||||
...this.parseRepository(baseRepository),
|
...this.parseRepository(baseRepository),
|
||||||
state: 'open',
|
state: 'open',
|
||||||
head: headBranch,
|
head: headBranchFull,
|
||||||
base: inputs.base
|
base: inputs.base
|
||||||
})
|
})
|
||||||
core.info(`Attempting update of pull request`)
|
core.info(`Attempting update of pull request`)
|
||||||
@ -113,11 +117,12 @@ export class GitHubHelper {
|
|||||||
baseRepository: string,
|
baseRepository: string,
|
||||||
headRepository: string
|
headRepository: string
|
||||||
): Promise<Pull> {
|
): Promise<Pull> {
|
||||||
const [headOwner] = headRepository.split('/')
|
|
||||||
const headBranch = `${headOwner}:${inputs.branch}`
|
|
||||||
|
|
||||||
// Create or update the pull request
|
// Create or update the pull request
|
||||||
const pull = await this.createOrUpdate(inputs, baseRepository, headBranch)
|
const pull = await this.createOrUpdate(
|
||||||
|
inputs,
|
||||||
|
baseRepository,
|
||||||
|
headRepository
|
||||||
|
)
|
||||||
|
|
||||||
// Apply milestone
|
// Apply milestone
|
||||||
if (inputs.milestone) {
|
if (inputs.milestone) {
|
||||||
|
@ -11,13 +11,23 @@ export const Octokit = Core.plugin(
|
|||||||
autoProxyAgent
|
autoProxyAgent
|
||||||
)
|
)
|
||||||
|
|
||||||
// Octokit plugin to support the https_proxy environment variable
|
// Octokit plugin to support the https_proxy and no_proxy environment variable
|
||||||
function autoProxyAgent(octokit: Core) {
|
function autoProxyAgent(octokit: Core) {
|
||||||
const proxy = process.env.https_proxy || process.env.HTTPS_PROXY
|
const proxy = process.env.https_proxy || process.env.HTTPS_PROXY
|
||||||
|
|
||||||
|
const noProxy = process.env.no_proxy || process.env.NO_PROXY
|
||||||
|
let noProxyArray: string[] = []
|
||||||
|
if (noProxy) {
|
||||||
|
noProxyArray = noProxy.split(',')
|
||||||
|
}
|
||||||
|
|
||||||
if (!proxy) return
|
if (!proxy) return
|
||||||
|
|
||||||
const agent = new HttpsProxyAgent(proxy)
|
const agent = new HttpsProxyAgent(proxy)
|
||||||
octokit.hook.before('request', options => {
|
octokit.hook.before('request', options => {
|
||||||
|
if (noProxyArray.includes(options.request.hostname)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
options.request.agent = agent
|
options.request.agent = agent
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user