Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
923ad837f1 | |||
f094b77505 | |||
af7c021bb9 | |||
97872c4843 | |||
bd72e1b792 | |||
f1a7646cea | |||
15b68d176d | |||
0dfc93c104 | |||
252fb19db2 | |||
4b867c4939 | |||
4fb3835236 | |||
19ace475b4 | |||
84d431ad62 |
10
.github/workflows/ci.yml
vendored
10
.github/workflows/ci.yml
vendored
@ -15,7 +15,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-node@v2
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: 16.x
|
node-version: 16.x
|
||||||
cache: npm
|
cache: npm
|
||||||
@ -75,7 +75,7 @@ jobs:
|
|||||||
branch: ci-test-${{ matrix.target }}
|
branch: ci-test-${{ matrix.target }}
|
||||||
|
|
||||||
- name: Close Pull
|
- name: Close Pull
|
||||||
uses: peter-evans/close-pull@v1
|
uses: peter-evans/close-pull@v2
|
||||||
with:
|
with:
|
||||||
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
|
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
|
||||||
comment: '[CI] test ${{ matrix.target }}'
|
comment: '[CI] test ${{ matrix.target }}'
|
||||||
@ -87,7 +87,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Find Comment
|
- name: Find Comment
|
||||||
uses: peter-evans/find-comment@v1
|
uses: peter-evans/find-comment@v2
|
||||||
id: fc
|
id: fc
|
||||||
with:
|
with:
|
||||||
issue-number: ${{ github.event.number }}
|
issue-number: ${{ github.event.number }}
|
||||||
@ -96,7 +96,7 @@ jobs:
|
|||||||
|
|
||||||
- if: steps.fc.outputs.comment-id == ''
|
- if: steps.fc.outputs.comment-id == ''
|
||||||
name: Create comment
|
name: Create comment
|
||||||
uses: peter-evans/create-or-update-comment@v1
|
uses: peter-evans/create-or-update-comment@v2
|
||||||
with:
|
with:
|
||||||
issue-number: ${{ github.event.number }}
|
issue-number: ${{ github.event.number }}
|
||||||
body: |
|
body: |
|
||||||
@ -116,7 +116,7 @@ jobs:
|
|||||||
name: dist
|
name: dist
|
||||||
path: dist
|
path: dist
|
||||||
- name: Create Pull Request
|
- name: Create Pull Request
|
||||||
uses: peter-evans/create-pull-request@v3
|
uses: peter-evans/create-pull-request@v4
|
||||||
with:
|
with:
|
||||||
commit-message: 'build: update distribution'
|
commit-message: 'build: update distribution'
|
||||||
title: Update distribution
|
title: Update distribution
|
||||||
|
2
.github/workflows/cpr-example-command.yml
vendored
2
.github/workflows/cpr-example-command.yml
vendored
@ -42,7 +42,7 @@ jobs:
|
|||||||
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
|
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
|
||||||
|
|
||||||
- name: Add reaction
|
- name: Add reaction
|
||||||
uses: peter-evans/create-or-update-comment@v1
|
uses: peter-evans/create-or-update-comment@v2
|
||||||
with:
|
with:
|
||||||
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
|
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
|
||||||
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
|
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
|
||||||
|
2
.github/workflows/slash-command-dispatch.yml
vendored
2
.github/workflows/slash-command-dispatch.yml
vendored
@ -7,7 +7,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Slash Command Dispatch
|
- name: Slash Command Dispatch
|
||||||
uses: peter-evans/slash-command-dispatch@v2
|
uses: peter-evans/slash-command-dispatch@v3
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
|
||||||
config: >
|
config: >
|
||||||
|
@ -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"]
|
||||||
|
@ -50,6 +50,12 @@ describe('utils tests', () => {
|
|||||||
)
|
)
|
||||||
expect(remote3.protocol).toEqual('SSH')
|
expect(remote3.protocol).toEqual('SSH')
|
||||||
expect(remote3.repository).toEqual('peter-evans/create-pull-request')
|
expect(remote3.repository).toEqual('peter-evans/create-pull-request')
|
||||||
|
|
||||||
|
const remote4 = utils.getRemoteDetail(
|
||||||
|
'https://github.com/peter-evans/create-pull-request.git'
|
||||||
|
)
|
||||||
|
expect(remote4.protocol).toEqual('HTTPS')
|
||||||
|
expect(remote4.repository).toEqual('peter-evans/create-pull-request')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('getRemoteDetail fails to parse a remote URL', async () => {
|
test('getRemoteDetail fails to parse a remote URL', async () => {
|
||||||
|
19
dist/index.js
vendored
19
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}'`);
|
||||||
@ -1211,7 +1214,7 @@ function getRemoteDetail(remoteUrl) {
|
|||||||
if (!githubServerMatch) {
|
if (!githubServerMatch) {
|
||||||
throw new Error('Could not parse GitHub Server name');
|
throw new Error('Could not parse GitHub Server name');
|
||||||
}
|
}
|
||||||
const httpsUrlPattern = new RegExp('^https?://.*@?' + githubServerMatch[1] + '/(.+/.+)$', 'i');
|
const httpsUrlPattern = new RegExp('^https?://.*@?' + githubServerMatch[1] + '/(.+/.+?)(.git)?$', 'i');
|
||||||
const sshUrlPattern = new RegExp('^git@' + githubServerMatch[1] + ':(.+/.+).git$', 'i');
|
const sshUrlPattern = new RegExp('^git@' + githubServerMatch[1] + ':(.+/.+).git$', 'i');
|
||||||
const httpsMatch = remoteUrl.match(httpsUrlPattern);
|
const httpsMatch = remoteUrl.match(httpsUrlPattern);
|
||||||
if (httpsMatch) {
|
if (httpsMatch) {
|
||||||
|
@ -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) {
|
||||||
|
@ -47,7 +47,7 @@ export function getRemoteDetail(remoteUrl: string): RemoteDetail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const httpsUrlPattern = new RegExp(
|
const httpsUrlPattern = new RegExp(
|
||||||
'^https?://.*@?' + githubServerMatch[1] + '/(.+/.+)$',
|
'^https?://.*@?' + githubServerMatch[1] + '/(.+/.+?)(.git)?$',
|
||||||
'i'
|
'i'
|
||||||
)
|
)
|
||||||
const sshUrlPattern = new RegExp(
|
const sshUrlPattern = new RegExp(
|
||||||
|
Reference in New Issue
Block a user