Compare commits

...

34 Commits

Author SHA1 Message Date
671dc9c9e0 build: update distribution (#1260)
Co-authored-by: peter-evans <peter-evans@users.noreply.github.com>
2022-09-28 12:39:00 +09:00
ddab646771 fix: only strip optional '.git' suffix from https server remote name and not 'Xgit' (#1257) 2022-09-28 12:35:31 +09:00
3f9dbd5a76 fix: replace use of any type (#1251) 2022-09-21 15:42:50 +09:00
171dd555b9 fix: improve logging when checking fork (#1246) 2022-09-21 10:40:38 +09:00
6e59b075e0 test: update the test execution env (#1235) 2022-08-26 11:07:49 +09:00
9c5916f06d docs: add funding 2022-08-26 10:32:19 +09:00
33434f1c62 build: update distribution (#1229)
Co-authored-by: peter-evans <peter-evans@users.noreply.github.com>
2022-08-19 11:21:51 +09:00
9ca978d38e build(deps): bump @actions/core from 1.6.0 to 1.9.1 (#1219)
Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.6.0 to 1.9.1.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

---
updated-dependencies:
- dependency-name: "@actions/core"
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-08-19 11:17:02 +09:00
8e154b2a92 ci: add workflow permissions (#1220) 2022-08-19 11:00:29 +09:00
18f90432be build: update distribution (#1216)
Co-authored-by: peter-evans <peter-evans@users.noreply.github.com>
2022-08-18 17:29:42 +09:00
2721abb4d0 fix: handle nothing to commit when autocrlf is set (#1211) 2022-08-18 17:20:00 +09:00
20dac2ed48 build: update distribution (#1208)
Co-authored-by: peter-evans <peter-evans@users.noreply.github.com>
2022-08-17 12:37:21 +09:00
8557470a68 feat: support no_proxy environment variable (#1205)
Co-authored-by: TGANSTE <till.ganster@mercedes-benz.com>
2022-08-17 12:25:36 +09:00
10db75894f docs: add info about workflow permissions 2022-06-08 17:57:28 +09:00
5a6b15373e docs: clearer description of update behaviour 2022-06-08 17:30:26 +09:00
923ad837f1 force tryFetch (#1189) 2022-06-03 17:30:50 +09:00
f094b77505 fix: avoid issue with case sensitivity of repo names (#1179)
* fix: avoid issue with case sensitivity in condition

* chore: upgrade jest to v28
2022-05-08 17:37:36 +09:00
af7c021bb9 docs: shorten quote 2022-04-22 14:27:14 +09:00
97872c4843 docs: update GA quote/ref in concepts-guidelines.md (#1169)
* Update GA quote/ref in concepts-guidelines.md

The current quote and reference link appear to be out of date

* Change "Triggering further workflow runs" excerpt
2022-04-14 08:39:38 +09:00
bd72e1b792 fix: use full name for head branch to allow for repo renaming (#1164) 2022-04-08 21:38:55 +09:00
f1a7646cea build: update distribution (#1157)
Co-authored-by: peter-evans <peter-evans@users.noreply.github.com>
2022-03-31 17:14:30 +09:00
15b68d176d fix: strip optional '.git' suffix from https server remote name. (#1153)
* Strip optional '.git' suffix from https server remote name.

* Revert "Strip optional '.git' suffix from https server remote name."

This reverts commit c2e9041213.

* Strip optional '.git' suffix from https server remote name.
2022-03-31 17:10:39 +09:00
0dfc93c104 build(deps): bump peter-evans/create-pull-request from 3 to 4 (#1150) 2022-03-28 21:33:19 +09:00
252fb19db2 build(deps): bump peter-evans/slash-command-dispatch from 2 to 3 (#1122)
Bumps [peter-evans/slash-command-dispatch](https://github.com/peter-evans/slash-command-dispatch) from 2 to 3.
- [Release notes](https://github.com/peter-evans/slash-command-dispatch/releases)
- [Commits](https://github.com/peter-evans/slash-command-dispatch/compare/v2...v3)

---
updated-dependencies:
- dependency-name: peter-evans/slash-command-dispatch
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-23 14:31:35 +09:00
4b867c4939 build(deps): bump actions/setup-node from 2 to 3 (#1123)
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 2 to 3.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-23 14:31:11 +09:00
4fb3835236 build(deps): bump peter-evans/close-pull from 1 to 2 (#1121)
Bumps [peter-evans/close-pull](https://github.com/peter-evans/close-pull) from 1 to 2.
- [Release notes](https://github.com/peter-evans/close-pull/releases)
- [Commits](https://github.com/peter-evans/close-pull/compare/v1...v2)

---
updated-dependencies:
- dependency-name: peter-evans/close-pull
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-23 14:29:36 +09:00
19ace475b4 build(deps): bump peter-evans/create-or-update-comment from 1 to 2 (#1120)
Bumps [peter-evans/create-or-update-comment](https://github.com/peter-evans/create-or-update-comment) from 1 to 2.
- [Release notes](https://github.com/peter-evans/create-or-update-comment/releases)
- [Commits](https://github.com/peter-evans/create-or-update-comment/compare/v1...v2)

---
updated-dependencies:
- dependency-name: peter-evans/create-or-update-comment
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-23 14:29:17 +09:00
84d431ad62 build(deps): bump peter-evans/find-comment from 1 to 2 (#1119)
Bumps [peter-evans/find-comment](https://github.com/peter-evans/find-comment) from 1 to 2.
- [Release notes](https://github.com/peter-evans/find-comment/releases)
- [Commits](https://github.com/peter-evans/find-comment/compare/v1...v2)

---
updated-dependencies:
- dependency-name: peter-evans/find-comment
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-23 14:28:50 +09:00
d6d5519d05 v4 (#1099)
* feat: update action runtime to node 16

* feat: allow add-paths to resolve to no changes

* docs: update readme

* chore: update package lock

* chore: bump dependency

* ci: add dependabot workflow

* docs: update action versions
2022-03-23 14:22:01 +09:00
0e8dfbd57d docs: update guidelines 2022-03-11 13:46:10 +09:00
ffa8cc2261 docs: Skip follow-up steps if there is no pull request (#1083) 2022-03-09 12:40:44 +09:00
00fb6900cb docs: Document how to improve close-and-reopen user experience (#1084) 2022-03-09 12:38:41 +09:00
2fe7e77753 docs: Add word "permissions" (#1082) 2022-03-09 10:46:31 +09:00
18f7dc018c feat: revert update action runtime to node 16 2022-02-28 21:17:05 +09:00
24 changed files with 5122 additions and 2204 deletions

1
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1 @@
github: peter-evans

8
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
labels:
- "dependencies"

View File

@ -10,28 +10,30 @@ on:
paths-ignore: paths-ignore:
- 'README.md' - 'README.md'
- 'docs/**' - 'docs/**'
permissions:
pull-requests: write
contents: write
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - 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
- uses: actions/setup-python@v2
with:
python-version: '3.x'
- run: npm ci - run: npm ci
- run: npm run build - run: npm run build
- run: npm run format-check - run: npm run format-check
- run: npm run lint - run: npm run lint
- run: npm run test - run: npm run test
- uses: actions/upload-artifact@v2 - uses: actions/upload-artifact@v3
with: with:
name: dist name: dist
path: dist path: dist
- uses: actions/upload-artifact@v2 - uses: actions/upload-artifact@v3
with: with:
name: action.yml name: action.yml
path: action.yml path: action.yml
@ -44,16 +46,16 @@ jobs:
matrix: matrix:
target: [built, committed] target: [built, committed]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
with: with:
ref: main ref: main
- if: matrix.target == 'built' || github.event_name == 'pull_request' - if: matrix.target == 'built' || github.event_name == 'pull_request'
uses: actions/download-artifact@v2 uses: actions/download-artifact@v3
with: with:
name: dist name: dist
path: dist path: dist
- if: matrix.target == 'built' || github.event_name == 'pull_request' - if: matrix.target == 'built' || github.event_name == 'pull_request'
uses: actions/download-artifact@v2 uses: actions/download-artifact@v3
with: with:
name: action.yml name: action.yml
path: . path: .
@ -78,7 +80,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 }}'
@ -90,7 +92,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 }}
@ -99,7 +101,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: |
@ -113,13 +115,13 @@ jobs:
needs: [test] needs: [test]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- uses: actions/download-artifact@v2 - uses: actions/download-artifact@v3
with: with:
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

View File

@ -6,7 +6,7 @@ jobs:
createPullRequest: createPullRequest:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Make changes to pull request - name: Make changes to pull request
run: date +%s > report.txt run: date +%s > report.txt
@ -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 }}

View File

@ -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: >

View File

@ -21,20 +21,27 @@ Create Pull Request action will:
- [Concepts, guidelines and advanced usage](docs/concepts-guidelines.md) - [Concepts, guidelines and advanced usage](docs/concepts-guidelines.md)
- [Examples](docs/examples.md) - [Examples](docs/examples.md)
- [Updating to v3](docs/updating.md) - [Updating to v4](docs/updating.md)
## Usage ## Usage
```yml ```yml
- uses: actions/checkout@v2 - uses: actions/checkout@v3
# Make changes to pull request here # Make changes to pull request here
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v3 uses: peter-evans/create-pull-request@v4
``` ```
You can also pin to a [specific release](https://github.com/peter-evans/create-pull-request/releases) version in the format `@v3.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
@ -44,9 +51,9 @@ All inputs are **optional**. If not set, sensible defaults will be used.
| Name | Description | Default | | Name | Description | Default |
| --- | --- | --- | | --- | --- | --- |
| `token` | `GITHUB_TOKEN` (`contents: write`, `pull-requests: write`) or a `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token). | `GITHUB_TOKEN` | | `token` | `GITHUB_TOKEN` (permissions `contents: write` and `pull-requests: write`) or a `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token). | `GITHUB_TOKEN` |
| `path` | Relative path under `GITHUB_WORKSPACE` to the repository. | `GITHUB_WORKSPACE` | | `path` | Relative path under `GITHUB_WORKSPACE` to the repository. | `GITHUB_WORKSPACE` |
| `add-paths` | A comma or newline-separated list of file paths to commit. Paths should follow git's [pathspec](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec) syntax. Defaults to adding all new and modified files. See [Add specific paths](#add-specific-paths). | `-A` | | `add-paths` | A comma or newline-separated list of file paths to commit. Paths should follow git's [pathspec](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec) syntax. If no paths are specified, all new and modified files are added. See [Add specific paths](#add-specific-paths). | |
| `commit-message` | The message to use when committing changes. | `[create-pull-request] automated change` | | `commit-message` | The message to use when committing changes. | `[create-pull-request] automated change` |
| `committer` | The committer name and email address in the format `Display Name <email@address.com>`. Defaults to the GitHub Actions bot user. | `GitHub <noreply@github.com>` | | `committer` | The committer name and email address in the format `Display Name <email@address.com>`. Defaults to the GitHub Actions bot user. | `GitHub <noreply@github.com>` |
| `author` | The author name and email address in the format `Display Name <email@address.com>`. Defaults to the user who triggered the workflow run. | `${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>` | | `author` | The author name and email address in the format `Display Name <email@address.com>`. Defaults to the user who triggered the workflow run. | `${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>` |
@ -68,7 +75,7 @@ All inputs are **optional**. If not set, sensible defaults will be used.
For self-hosted runners behind a corporate proxy set the `https_proxy` environment variable. For self-hosted runners behind a corporate proxy set the `https_proxy` environment variable.
```yml ```yml
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v3 uses: peter-evans/create-pull-request@v4
env: env:
https_proxy: http://<proxy_address>:<port> https_proxy: http://<proxy_address>:<port>
``` ```
@ -88,8 +95,9 @@ Note that in order to read the step outputs the action step must have an id.
```yml ```yml
- name: Create Pull Request - name: Create Pull Request
id: cpr id: cpr
uses: peter-evans/create-pull-request@v3 uses: peter-evans/create-pull-request@v4
- name: Check outputs - name: Check outputs
if: ${{ steps.cpr.outputs.pull-request-number }}
run: | run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
@ -105,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).
@ -146,12 +154,11 @@ If there are files or directories you want to ignore you can simply add them to
You can control which files are committed with the `add-paths` input. You can control which files are committed with the `add-paths` input.
Paths should follow git's [pathspec](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec) syntax. Paths should follow git's [pathspec](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefpathspecapathspec) syntax.
Each path must resolve to a least one new or modified file to add.
All file changes that do not match one of the paths will be discarded. All file changes that do not match one of the paths will be discarded.
```yml ```yml
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v3 uses: peter-evans/create-pull-request@v4
with: with:
add-paths: | add-paths: |
*.java *.java
@ -165,7 +172,7 @@ Note that the repository must be checked out on a branch with a remote, it won't
```yml ```yml
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Create commits - name: Create commits
run: | run: |
git config user.name 'Peter Evans' git config user.name 'Peter Evans'
@ -178,7 +185,7 @@ Note that the repository must be checked out on a branch with a remote, it won't
- name: Uncommitted change - name: Uncommitted change
run: date +%s > report.txt run: date +%s > report.txt
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v3 uses: peter-evans/create-pull-request@v4
``` ```
### Create a project card ### Create a project card
@ -188,10 +195,11 @@ To create a project card for the pull request, pass the `pull-request-number` st
```yml ```yml
- name: Create Pull Request - name: Create Pull Request
id: cpr id: cpr
uses: peter-evans/create-pull-request@v3 uses: peter-evans/create-pull-request@v4
- name: Create or Update Project Card - name: Create or Update Project Card
uses: peter-evans/create-or-update-project-card@v1 if: ${{ steps.cpr.outputs.pull-request-number }}
uses: peter-evans/create-or-update-project-card@v2
with: with:
project-name: My project project-name: My project
column-name: My column column-name: My column
@ -215,14 +223,14 @@ jobs:
createPullRequest: createPullRequest:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Make changes to pull request - name: Make changes to pull request
run: date +%s > report.txt run: date +%s > report.txt
- name: Create Pull Request - name: Create Pull Request
id: cpr id: cpr
uses: peter-evans/create-pull-request@v3 uses: peter-evans/create-pull-request@v4
with: with:
token: ${{ secrets.PAT }} token: ${{ secrets.PAT }}
commit-message: Update report commit-message: Update report

View File

@ -11,8 +11,8 @@ import {v4 as uuidv4} from 'uuid'
const REPO_PATH = '/git/local/test-base' const REPO_PATH = '/git/local/test-base'
const REMOTE_NAME = 'origin' const REMOTE_NAME = 'origin'
const TRACKED_FILE = 'tracked-file.txt' const TRACKED_FILE = 'a/tracked-file.txt'
const UNTRACKED_FILE = 'untracked-file.txt' const UNTRACKED_FILE = 'b/untracked-file.txt'
const DEFAULT_BRANCH = 'tests/master' const DEFAULT_BRANCH = 'tests/master'
const NOT_BASE_BRANCH = 'tests/branch-that-is-not-the-base' const NOT_BASE_BRANCH = 'tests/branch-that-is-not-the-base'
@ -25,12 +25,14 @@ const BASE = DEFAULT_BRANCH
const FORK_REMOTE_URL = 'git://127.0.0.1/test-fork.git' const FORK_REMOTE_URL = 'git://127.0.0.1/test-fork.git'
const FORK_REMOTE_NAME = 'fork' const FORK_REMOTE_NAME = 'fork'
const ADD_PATHS = ['-A'] const ADD_PATHS_DEFAULT = []
const ADD_PATHS_WILDCARD = ['*.txt'] const ADD_PATHS_MULTI = ['a', 'b']
const ADD_PATHS_WILDCARD = ['a/*.txt', 'b/*.txt']
async function createFile(filename: string, content?: string): Promise<string> { async function createFile(filename: string, content?: string): Promise<string> {
const _content = content ? content : uuidv4() const _content = content ? content : uuidv4()
const filepath = path.join(REPO_PATH, filename) const filepath = path.join(REPO_PATH, filename)
await fs.promises.mkdir(path.dirname(filepath), {recursive: true})
await fs.promises.writeFile(filepath, _content, {encoding: 'utf8'}) await fs.promises.writeFile(filepath, _content, {encoding: 'utf8'})
return _content return _content
} }
@ -224,7 +226,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('none') expect(result.action).toEqual('none')
expect(await gitLogMatches([INIT_COMMIT_MESSAGE])).toBeTruthy() expect(await gitLogMatches([INIT_COMMIT_MESSAGE])).toBeTruthy()
@ -241,7 +243,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(trackedContent) expect(await getFileContent(TRACKED_FILE)).toEqual(trackedContent)
@ -269,7 +271,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('updated') expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy() expect(_result.hasDiffWithBase).toBeTruthy()
@ -290,7 +292,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(UNTRACKED_FILE)).toEqual(untrackedContent) expect(await getFileContent(UNTRACKED_FILE)).toEqual(untrackedContent)
@ -318,7 +320,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('updated') expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy() expect(_result.hasDiffWithBase).toBeTruthy()
@ -341,7 +343,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -370,7 +372,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('not-updated') expect(_result.action).toEqual('not-updated')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -391,7 +393,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -428,7 +430,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('updated') expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy() expect(_result.hasDiffWithBase).toBeTruthy()
@ -459,7 +461,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -487,7 +489,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('updated') expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeFalsy() expect(_result.hasDiffWithBase).toBeFalsy()
@ -508,7 +510,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -548,7 +550,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('updated') expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeFalsy() expect(_result.hasDiffWithBase).toBeFalsy()
@ -575,7 +577,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -618,7 +620,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('updated') expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeFalsy() expect(_result.hasDiffWithBase).toBeFalsy()
@ -640,7 +642,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(commits.changes.tracked) expect(await getFileContent(TRACKED_FILE)).toEqual(commits.changes.tracked)
@ -671,7 +673,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('updated') expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy() expect(_result.hasDiffWithBase).toBeTruthy()
@ -697,7 +699,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -732,7 +734,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('updated') expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy() expect(_result.hasDiffWithBase).toBeTruthy()
@ -760,7 +762,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -803,7 +805,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('updated') expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy() expect(_result.hasDiffWithBase).toBeTruthy()
@ -830,7 +832,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
FORK_REMOTE_NAME, FORK_REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -859,7 +861,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
FORK_REMOTE_NAME, FORK_REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('updated') expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy() expect(_result.hasDiffWithBase).toBeTruthy()
@ -881,7 +883,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
true, true,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -917,7 +919,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
true, true,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('updated') expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy() expect(_result.hasDiffWithBase).toBeTruthy()
@ -935,9 +937,58 @@ describe('create-or-update-branch tests', () => {
) )
}) })
it('tests create and update with wildcard add-paths', async () => { it('tests create and update with multiple add-paths', async () => {
// The pull request branch will not be updated // Create tracked and untracked file changes
const changes = await createChanges()
const commitMessage = uuidv4()
const result = await createOrUpdateBranch(
git,
commitMessage,
'',
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS_MULTI
)
expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
expect(await getFileContent(UNTRACKED_FILE)).toEqual(changes.untracked)
expect(
await gitLogMatches([commitMessage, INIT_COMMIT_MESSAGE])
).toBeTruthy()
// Push pull request branch to remote
await git.push([
'--force-with-lease',
REMOTE_NAME,
`HEAD:refs/heads/${BRANCH}`
])
await afterTest(false)
await beforeTest()
// Create tracked and untracked file changes
const _changes = await createChanges()
const _commitMessage = uuidv4()
const _result = await createOrUpdateBranch(
git,
_commitMessage,
'',
BRANCH,
REMOTE_NAME,
false,
ADD_PATHS_MULTI
)
expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy()
expect(await getFileContent(TRACKED_FILE)).toEqual(_changes.tracked)
expect(await getFileContent(UNTRACKED_FILE)).toEqual(_changes.untracked)
expect(
await gitLogMatches([_commitMessage, INIT_COMMIT_MESSAGE])
).toBeTruthy()
})
it('tests create and update with wildcard add-paths', async () => {
// Create tracked and untracked file changes // Create tracked and untracked file changes
const changes = await createChanges() const changes = await createChanges()
const commitMessage = uuidv4() const commitMessage = uuidv4()
@ -988,6 +1039,23 @@ describe('create-or-update-branch tests', () => {
).toBeTruthy() ).toBeTruthy()
}) })
it('tests create with add-paths resolving to no changes when other changes exist', async () => {
// Create tracked and untracked file changes
await createChanges()
const commitMessage = uuidv4()
const result = await createOrUpdateBranch(
git,
commitMessage,
'',
BRANCH,
REMOTE_NAME,
false,
['nonexistent/*']
)
expect(result.action).toEqual('none')
expect(await gitLogMatches([INIT_COMMIT_MESSAGE])).toBeTruthy()
})
// Working Base is Not Base (WBNB) // Working Base is Not Base (WBNB)
it('tests no changes resulting in no new branch being created (WBNB)', async () => { it('tests no changes resulting in no new branch being created (WBNB)', async () => {
@ -1002,7 +1070,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('none') expect(result.action).toEqual('none')
expect(await gitLogMatches([INIT_COMMIT_MESSAGE])).toBeTruthy() expect(await gitLogMatches([INIT_COMMIT_MESSAGE])).toBeTruthy()
@ -1022,7 +1090,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(trackedContent) expect(await getFileContent(TRACKED_FILE)).toEqual(trackedContent)
@ -1053,7 +1121,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('updated') expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy() expect(_result.hasDiffWithBase).toBeTruthy()
@ -1077,7 +1145,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(UNTRACKED_FILE)).toEqual(untrackedContent) expect(await getFileContent(UNTRACKED_FILE)).toEqual(untrackedContent)
@ -1108,7 +1176,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('updated') expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy() expect(_result.hasDiffWithBase).toBeTruthy()
@ -1134,7 +1202,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1166,7 +1234,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('not-updated') expect(_result.action).toEqual('not-updated')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1190,7 +1258,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1230,7 +1298,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('updated') expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy() expect(_result.hasDiffWithBase).toBeTruthy()
@ -1264,7 +1332,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1295,7 +1363,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('updated') expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeFalsy() expect(_result.hasDiffWithBase).toBeFalsy()
@ -1321,7 +1389,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1364,7 +1432,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('updated') expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeFalsy() expect(_result.hasDiffWithBase).toBeFalsy()
@ -1394,7 +1462,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1440,7 +1508,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('updated') expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeFalsy() expect(_result.hasDiffWithBase).toBeFalsy()
@ -1465,7 +1533,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(commits.changes.tracked) expect(await getFileContent(TRACKED_FILE)).toEqual(commits.changes.tracked)
@ -1499,7 +1567,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('updated') expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy() expect(_result.hasDiffWithBase).toBeTruthy()
@ -1528,7 +1596,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1566,7 +1634,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('updated') expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy() expect(_result.hasDiffWithBase).toBeTruthy()
@ -1597,7 +1665,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1643,7 +1711,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('updated') expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy() expect(_result.hasDiffWithBase).toBeTruthy()
@ -1673,7 +1741,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
FORK_REMOTE_NAME, FORK_REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1705,7 +1773,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
FORK_REMOTE_NAME, FORK_REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('updated') expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy() expect(_result.hasDiffWithBase).toBeTruthy()
@ -1734,7 +1802,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1767,7 +1835,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('updated') expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy() expect(_result.hasDiffWithBase).toBeTruthy()
@ -1793,7 +1861,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(result.action).toEqual('created') expect(result.action).toEqual('created')
expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked) expect(await getFileContent(TRACKED_FILE)).toEqual(changes.tracked)
@ -1834,7 +1902,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
expect(_result.action).toEqual('updated') expect(_result.action).toEqual('updated')
expect(_result.hasDiffWithBase).toBeTruthy() expect(_result.hasDiffWithBase).toBeTruthy()
@ -1866,7 +1934,7 @@ describe('create-or-update-branch tests', () => {
BRANCH, BRANCH,
REMOTE_NAME, REMOTE_NAME,
false, false,
ADD_PATHS ADD_PATHS_DEFAULT
) )
// The action cannot successfully create the branch // The action cannot successfully create the branch
expect(result.action).toEqual('none') expect(result.action).toEqual('none')

View File

@ -8,9 +8,9 @@ if [[ "$(docker images -q $IMAGE 2> /dev/null)" == "" || $ARG1 == "build" ]]; th
echo "Building Docker image $IMAGE ..." echo "Building Docker image $IMAGE ..."
cat > Dockerfile << EOF cat > Dockerfile << EOF
FROM node:12-alpine FROM node:16-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"]

View File

@ -50,6 +50,30 @@ 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')
const remote5 = utils.getRemoteDetail(
'https://github.com/peter-evans/ungit'
)
expect(remote5.protocol).toEqual('HTTPS')
expect(remote5.repository).toEqual('peter-evans/ungit')
const remote6 = utils.getRemoteDetail(
'https://github.com/peter-evans/ungit.git'
)
expect(remote6.protocol).toEqual('HTTPS')
expect(remote6.repository).toEqual('peter-evans/ungit')
const remote7 = utils.getRemoteDetail(
'git@github.com:peter-evans/ungit.git'
)
expect(remote7.protocol).toEqual('SSH')
expect(remote7.repository).toEqual('peter-evans/ungit')
}) })
test('getRemoteDetail fails to parse a remote URL', async () => { test('getRemoteDetail fails to parse a remote URL', async () => {

View File

@ -13,8 +13,6 @@ inputs:
A comma or newline-separated list of file paths to commit. A comma or newline-separated list of file paths to commit.
Paths should follow git's pathspec syntax. Paths should follow git's pathspec syntax.
Defaults to adding all new and modified files. Defaults to adding all new and modified files.
default: |
-A
commit-message: commit-message:
description: 'The message to use when committing changes.' description: 'The message to use when committing changes.'
default: '[create-pull-request] automated change' default: '[create-pull-request] automated change'

1085
dist/index.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -36,7 +36,7 @@ For each [event type](https://docs.github.com/en/actions/reference/events-that-t
The default can be overridden by specifying a `ref` on checkout. The default can be overridden by specifying a `ref` on checkout.
```yml ```yml
- uses: actions/checkout@v2 - uses: actions/checkout@v3
with: with:
ref: develop ref: develop
``` ```
@ -73,7 +73,7 @@ jobs:
example: example:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
``` ```
There may be use cases where it makes sense to execute the workflow on a branch that is not the base of the pull request. In these cases, the base branch can be specified with the `base` action input. The action will attempt to rebase changes made during the workflow on to the actual base. There may be use cases where it makes sense to execute the workflow on a branch that is not the base of the pull request. In these cases, the base branch can be specified with the `base` action input. The action will attempt to rebase changes made during the workflow on to the actual base.
@ -88,7 +88,7 @@ In these cases, you *must supply* the `base` input so the action can rebase chan
Workflows triggered by [`pull_request`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request) events will by default check out a merge commit. Set the `base` input as follows to base the new pull request on the current pull request's branch. Workflows triggered by [`pull_request`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request) events will by default check out a merge commit. Set the `base` input as follows to base the new pull request on the current pull request's branch.
```yml ```yml
- uses: peter-evans/create-pull-request@v3 - uses: peter-evans/create-pull-request@v4
with: with:
base: ${{ github.head_ref }} base: ${{ github.head_ref }}
``` ```
@ -96,7 +96,7 @@ Workflows triggered by [`pull_request`](https://docs.github.com/en/actions/refer
Workflows triggered by [`release`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#release) events will by default check out a tag. For most use cases, you will need to set the `base` input to the branch name of the tagged commit. Workflows triggered by [`release`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#release) events will by default check out a tag. For most use cases, you will need to set the `base` input to the branch name of the tagged commit.
```yml ```yml
- uses: peter-evans/create-pull-request@v3 - uses: peter-evans/create-pull-request@v4
with: with:
base: main base: main
``` ```
@ -136,15 +136,15 @@ 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
There are a number of workarounds with different pros and cons. There are a number of workarounds with different pros and cons.
- Use the default `GITHUB_TOKEN` and allow the action to create pull requests that have no checks enabled. Manually close pull requests and immediately reopen them. This will enable `on: pull_request` workflows to run and be added as checks. - Use the default `GITHUB_TOKEN` and allow the action to create pull requests that have no checks enabled. Manually close pull requests and immediately reopen them. This will enable `on: pull_request` workflows to run and be added as checks. To prevent merging of pull requests without checks erroneously, use [branch protection rules](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests).
- Use a `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) created on an account that has write access to the repository that pull requests are being created in. This is the standard workaround and [recommended by GitHub](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token). However, the PAT cannot be scoped to a specific repository so the token becomes a very sensitive secret. If this is a concern, the PAT can instead be created for a dedicated [machine account](https://docs.github.com/en/github/site-policy/github-terms-of-service#3-account-requirements) that has collaborator access to the repository. Also note that because the account that owns the PAT will be the creator of pull requests, that user account will be unable to perform actions such as request changes or approve the pull request. - Use a `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) created on an account that has write access to the repository that pull requests are being created in. This is the standard workaround and [recommended by GitHub](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token). However, the PAT cannot be scoped to a specific repository so the token becomes a very sensitive secret. If this is a concern, the PAT can instead be created for a dedicated [machine account](https://docs.github.com/en/github/site-policy/github-terms-of-service#3-account-requirements) that has collaborator access to the repository. Also note that because the account that owns the PAT will be the creator of pull requests, that user account will be unable to perform actions such as request changes or approve the pull request.
@ -173,14 +173,14 @@ This action uses [ncc](https://github.com/vercel/ncc) to compile the Node.js cod
Checking out a branch from a different repository from where the workflow is executing will make *that repository* the target for the created pull request. In this case, a `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) is required. Checking out a branch from a different repository from where the workflow is executing will make *that repository* the target for the created pull request. In this case, a `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) is required.
```yml ```yml
- uses: actions/checkout@v2 - uses: actions/checkout@v3
with: with:
token: ${{ secrets.PAT }} token: ${{ secrets.PAT }}
repository: owner/repo repository: owner/repo
# Make changes to pull request here # Make changes to pull request here
- uses: peter-evans/create-pull-request@v3 - uses: peter-evans/create-pull-request@v4
with: with:
token: ${{ secrets.PAT }} token: ${{ secrets.PAT }}
``` ```
@ -200,14 +200,14 @@ How to use SSH (deploy keys) with create-pull-request action:
```yml ```yml
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
with: with:
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }} ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
# Make changes to pull request here # Make changes to pull request here
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v3 uses: peter-evans/create-pull-request@v4
``` ```
### Push pull request branches to a fork ### Push pull request branches to a fork
@ -225,11 +225,11 @@ It will use their own fork to push code and create the pull request.
6. As shown in the following example workflow, set the `push-to-fork` input to the full repository name of the fork. 6. As shown in the following example workflow, set the `push-to-fork` input to the full repository name of the fork.
```yaml ```yaml
- uses: actions/checkout@v2 - uses: actions/checkout@v3
# Make changes to pull request here # Make changes to pull request here
- uses: peter-evans/create-pull-request@v3 - uses: peter-evans/create-pull-request@v4
with: with:
token: ${{ secrets.MACHINE_USER_PAT }} token: ${{ secrets.MACHINE_USER_PAT }}
push-to-fork: machine-user/fork-of-repository push-to-fork: machine-user/fork-of-repository
@ -261,7 +261,7 @@ GitHub App generated tokens are more secure than using a PAT because GitHub App
```yaml ```yaml
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- uses: tibdex/github-app-token@v1 - uses: tibdex/github-app-token@v1
id: generate-token id: generate-token
@ -272,7 +272,7 @@ GitHub App generated tokens are more secure than using a PAT because GitHub App
# Make changes to pull request here # Make changes to pull request here
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v3 uses: peter-evans/create-pull-request@v4
with: with:
token: ${{ steps.generate-token.outputs.token }} token: ${{ steps.generate-token.outputs.token }}
``` ```
@ -301,7 +301,7 @@ The action can use GPG to sign commits with a GPG key that you generate yourself
```yaml ```yaml
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- uses: crazy-max/ghaction-import-gpg@v3 - uses: crazy-max/ghaction-import-gpg@v3
with: with:
@ -313,7 +313,7 @@ The action can use GPG to sign commits with a GPG key that you generate yourself
# Make changes to pull request here # Make changes to pull request here
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v3 uses: peter-evans/create-pull-request@v4
with: with:
token: ${{ secrets.PAT }} token: ${{ secrets.PAT }}
committer: example <email@example.com> committer: example <email@example.com>
@ -338,12 +338,12 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: apk --no-cache add git run: apk --no-cache add git
- uses: actions/checkout@v2 - uses: actions/checkout@v3
# Make changes to pull request here # Make changes to pull request here
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v3 uses: peter-evans/create-pull-request@v4
``` ```
**Ubuntu container example:** **Ubuntu container example:**
@ -361,10 +361,10 @@ jobs:
add-apt-repository -y ppa:git-core/ppa add-apt-repository -y ppa:git-core/ppa
apt-get install -y git apt-get install -y git
- uses: actions/checkout@v2 - uses: actions/checkout@v3
# Make changes to pull request here # Make changes to pull request here
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v3 uses: peter-evans/create-pull-request@v4
``` ```

View File

@ -43,14 +43,14 @@ jobs:
updateAuthors: updateAuthors:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Update AUTHORS - name: Update AUTHORS
run: | run: |
git log --format='%aN <%aE>%n%cN <%cE>' | sort -u > AUTHORS git log --format='%aN <%aE>%n%cN <%cE>' | sort -u > AUTHORS
- 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: update authors commit-message: update authors
title: Update AUTHORS title: Update AUTHORS
@ -74,7 +74,7 @@ jobs:
productionPromotion: productionPromotion:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
with: with:
ref: production ref: production
- name: Reset promotion branch - name: Reset promotion branch
@ -82,7 +82,7 @@ jobs:
git fetch origin main:main git fetch origin main:main
git reset --hard main git reset --hard main
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v3 uses: peter-evans/create-pull-request@v4
with: with:
branch: production-promotion branch: production-promotion
``` ```
@ -107,7 +107,7 @@ jobs:
updateChangelog: updateChangelog:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Update Changelog - name: Update Changelog
@ -117,7 +117,7 @@ jobs:
./git-chglog -o CHANGELOG.md ./git-chglog -o CHANGELOG.md
rm git-chglog rm git-chglog
- 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: update changelog commit-message: update changelog
title: Update Changelog title: Update Changelog
@ -145,16 +145,16 @@ jobs:
update-dep: update-dep:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- uses: actions/setup-node@v1 - uses: actions/setup-node@v3
with: with:
node-version: '12.x' node-version: '16.x'
- name: Update dependencies - name: Update dependencies
run: | run: |
npx -p npm-check-updates ncu -u npx -p npm-check-updates ncu -u
npm install npm install
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v3 uses: peter-evans/create-pull-request@v4
with: with:
token: ${{ secrets.PAT }} token: ${{ secrets.PAT }}
commit-message: Update dependencies commit-message: Update dependencies
@ -181,10 +181,10 @@ jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- uses: actions/setup-node@v1 - uses: actions/setup-node@v3
with: with:
node-version: 12.x node-version: 16.x
- run: npm ci - run: npm ci
- run: npm run test - run: npm run test
- run: npm run build - run: npm run build
@ -205,16 +205,17 @@ jobs:
update-dep: update-dep:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- uses: actions/setup-java@v1 - uses: actions/setup-java@v2
with: with:
distribution: 'temurin'
java-version: 1.8 java-version: 1.8
- name: Grant execute permission for gradlew - name: Grant execute permission for gradlew
run: chmod +x gradlew run: chmod +x gradlew
- name: Perform dependency resolution and write new lockfiles - name: Perform dependency resolution and write new lockfiles
run: ./gradlew dependencies --write-locks run: ./gradlew dependencies --write-locks
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v3 uses: peter-evans/create-pull-request@v4
with: with:
token: ${{ secrets.PAT }} token: ${{ secrets.PAT }}
commit-message: Update dependencies commit-message: Update dependencies
@ -242,14 +243,14 @@ jobs:
update-dep: update-dep:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Update dependencies - name: Update dependencies
run: | run: |
cargo install cargo-edit cargo install cargo-edit
cargo update cargo update
cargo upgrade --to-lockfile cargo upgrade --to-lockfile
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v3 uses: peter-evans/create-pull-request@v4
with: with:
token: ${{ secrets.PAT }} token: ${{ secrets.PAT }}
commit-message: Update dependencies commit-message: Update dependencies
@ -277,7 +278,7 @@ jobs:
updateSwagger: updateSwagger:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Get Latest Swagger UI Release - name: Get Latest Swagger UI Release
id: swagger-ui id: swagger-ui
run: | run: |
@ -305,7 +306,7 @@ jobs:
# Update current release # Update current release
echo ${{ steps.swagger-ui.outputs.release_tag }} > swagger-ui.version echo ${{ steps.swagger-ui.outputs.release_tag }} > swagger-ui.version
- 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: Update swagger-ui to ${{ steps.swagger-ui.outputs.release_tag }} commit-message: Update swagger-ui to ${{ steps.swagger-ui.outputs.release_tag }}
title: Update SwaggerUI to ${{ steps.swagger-ui.outputs.release_tag }} title: Update SwaggerUI to ${{ steps.swagger-ui.outputs.release_tag }}
@ -340,7 +341,7 @@ jobs:
updateFork: updateFork:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
with: with:
repository: fork-owner/repo repository: fork-owner/repo
- name: Reset the default branch with upstream changes - name: Reset the default branch with upstream changes
@ -349,7 +350,7 @@ jobs:
git fetch upstream main:upstream-main git fetch upstream main:upstream-main
git reset --hard upstream-main git reset --hard upstream-main
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v3 uses: peter-evans/create-pull-request@v4
with: with:
token: ${{ secrets.PAT }} token: ${{ secrets.PAT }}
branch: upstream-changes branch: upstream-changes
@ -368,7 +369,7 @@ jobs:
format: format:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Download website - name: Download website
run: | run: |
wget \ wget \
@ -382,7 +383,7 @@ jobs:
--domains quotes.toscrape.com \ --domains quotes.toscrape.com \
http://quotes.toscrape.com/ http://quotes.toscrape.com/
- 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: update local website copy commit-message: update local website copy
title: Automated Updates to Local Website Copy title: Automated Updates to Local Website Copy
@ -427,7 +428,7 @@ An `on: repository_dispatch` workflow can be triggered from another workflow wit
```yml ```yml
- name: Repository Dispatch - name: Repository Dispatch
uses: peter-evans/repository-dispatch@v1 uses: peter-evans/repository-dispatch@v2
with: with:
token: ${{ secrets.REPO_ACCESS_TOKEN }} token: ${{ secrets.REPO_ACCESS_TOKEN }}
repository: username/my-repo repository: username/my-repo
@ -464,7 +465,7 @@ jobs:
if: startsWith(github.head_ref, 'autopep8-patches') == false && github.event.pull_request.head.repo.full_name == github.repository if: startsWith(github.head_ref, 'autopep8-patches') == false && github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
with: with:
ref: ${{ github.head_ref }} ref: ${{ github.head_ref }}
- name: autopep8 - name: autopep8
@ -477,7 +478,7 @@ jobs:
run: echo ::set-output name=branch-name::"autopep8-patches/${{ github.head_ref }}" run: echo ::set-output name=branch-name::"autopep8-patches/${{ github.head_ref }}"
- name: Create Pull Request - name: Create Pull Request
if: steps.autopep8.outputs.exit-code == 2 if: steps.autopep8.outputs.exit-code == 2
uses: peter-evans/create-pull-request@v3 uses: peter-evans/create-pull-request@v4
with: with:
commit-message: autopep8 action fixes commit-message: autopep8 action fixes
title: Fixes by autopep8 action title: Fixes by autopep8 action
@ -511,13 +512,13 @@ jobs:
if: startsWith(github.ref, 'refs/heads/') if: startsWith(github.ref, 'refs/heads/')
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
... ...
someOtherJob: someOtherJob:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
... ...
``` ```
@ -535,7 +536,7 @@ The recommended method is to use [`set-output`](https://docs.github.com/en/actio
echo ::set-output name=pr_body::"This PR was auto-generated on $(date +%d-%m-%Y) \ echo ::set-output name=pr_body::"This PR was auto-generated on $(date +%d-%m-%Y) \
by [create-pull-request](https://github.com/peter-evans/create-pull-request)." by [create-pull-request](https://github.com/peter-evans/create-pull-request)."
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v3 uses: peter-evans/create-pull-request@v4
with: with:
title: ${{ steps.vars.outputs.pr_title }} title: ${{ steps.vars.outputs.pr_title }}
body: ${{ steps.vars.outputs.pr_body }} body: ${{ steps.vars.outputs.pr_body }}
@ -556,7 +557,7 @@ The content must be [escaped to preserve newlines](https://github.community/t/se
echo ::set-output name=body::$body echo ::set-output name=body::$body
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v3 uses: peter-evans/create-pull-request@v4
with: with:
body: ${{ steps.get-pr-body.outputs.body }} body: ${{ steps.get-pr-body.outputs.body }}
``` ```
@ -573,7 +574,7 @@ The template is rendered using the [render-template](https://github.com/chuhlomi
```yml ```yml
- name: Render template - name: Render template
id: template id: template
uses: chuhlomin/render-template@v1.2 uses: chuhlomin/render-template@v1.4
with: with:
template: .github/pull-request-template.md template: .github/pull-request-template.md
vars: | vars: |
@ -581,7 +582,7 @@ The template is rendered using the [render-template](https://github.com/chuhlomi
bar: that bar: that
- name: Create Pull Request - name: Create Pull Request
uses: peter-evans/create-pull-request@v3 uses: peter-evans/create-pull-request@v4
with: with:
body: ${{ steps.template.outputs.result }} body: ${{ steps.template.outputs.result }}
``` ```

View File

@ -1,3 +1,17 @@
## Updating from `v3` to `v4`
### Breaking changes
- The `add-paths` input no longer accepts `-A` as a valid value. When committing all new and modified files the `add-paths` input should be omitted.
- If using self-hosted runners or GitHub Enterprise Server, there are minimum requirements for `v4` to run. See "What's new" below for details.
### What's new
- Updated runtime to Node.js 16
- The action now requires a minimum version of v2.285.0 for the [Actions Runner](https://github.com/actions/runner/releases/tag/v2.285.0).
- If using GitHub Enterprise Server, the action requires [GHES 3.4](https://docs.github.com/en/enterprise-server@3.4/admin/release-notes) or later.
## Updating from `v2` to `v3` ## Updating from `v2` to `v3`
### Breaking changes ### Breaking changes
@ -31,7 +45,7 @@
push-to-fork: machine-user/fork-of-repository push-to-fork: machine-user/fork-of-repository
``` ```
### New features ### What's new
- The action has been converted to Typescript giving it a significant performance improvement. - The action has been converted to Typescript giving it a significant performance improvement.
@ -66,7 +80,7 @@
If neither `author` or `committer` are set the action will default to making commits as the GitHub Actions bot user. If neither `author` or `committer` are set the action will default to making commits as the GitHub Actions bot user.
### New features ### What's new
- Unpushed commits made during the workflow before the action runs will now be considered as changes to be raised in the pull request. See [Create your own commits](https://github.com/peter-evans/create-pull-request#create-your-own-commits) for details. - Unpushed commits made during the workflow before the action runs will now be considered as changes to be raised in the pull request. See [Create your own commits](https://github.com/peter-evans/create-pull-request#create-your-own-commits) for details.
- New commits made to the pull request base will now be taken into account when pull requests are updated. - New commits made to the pull request base will now be taken into account when pull requests are updated.

5660
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "create-pull-request", "name": "create-pull-request",
"version": "3.0.0", "version": "4.0.0",
"private": true, "private": true,
"description": "Creates a pull request for changes to your repository in the actions workspace", "description": "Creates a pull request for changes to your repository in the actions workspace",
"main": "lib/main.js", "main": "lib/main.js",
@ -29,7 +29,7 @@
}, },
"homepage": "https://github.com/peter-evans/create-pull-request", "homepage": "https://github.com/peter-evans/create-pull-request",
"dependencies": { "dependencies": {
"@actions/core": "^1.6.0", "@actions/core": "^1.9.1",
"@actions/exec": "^1.1.0", "@actions/exec": "^1.1.0",
"@octokit/core": "^3.5.1", "@octokit/core": "^3.5.1",
"@octokit/plugin-paginate-rest": "^2.17.0", "@octokit/plugin-paginate-rest": "^2.17.0",
@ -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"
} }
} }

View File

@ -4,6 +4,7 @@ import {v4 as uuidv4} from 'uuid'
const CHERRYPICK_EMPTY = const CHERRYPICK_EMPTY =
'The previous cherry-pick is now empty, possibly due to conflict resolution.' 'The previous cherry-pick is now empty, possibly due to conflict resolution.'
const NOTHING_TO_COMMIT = 'nothing to commit, working tree clean'
export enum WorkingBaseType { export enum WorkingBaseType {
Branch = 'branch', Branch = 'branch',
@ -33,7 +34,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
@ -119,21 +122,33 @@ export async function createOrUpdateBranch(
const tempBranch = uuidv4() const tempBranch = uuidv4()
await git.checkout(tempBranch, 'HEAD') await git.checkout(tempBranch, 'HEAD')
// Commit any uncommitted changes // Commit any uncommitted changes
if (await git.isDirty(true)) { if (await git.isDirty(true, addPaths)) {
core.info('Uncommitted changes found. Adding a commit.') core.info('Uncommitted changes found. Adding a commit.')
for (const path of addPaths) { const aopts = ['add']
await git.exec(['add', path], true) if (addPaths.length > 0) {
aopts.push(...['--', ...addPaths])
} else {
aopts.push('-A')
} }
const params = ['-m', commitMessage] await git.exec(aopts, true)
const popts = ['-m', commitMessage]
if (signoff) { if (signoff) {
params.push('--signoff') popts.push('--signoff')
}
const commitResult = await git.commit(popts, true)
// 'nothing to commit' can occur when core.autocrlf is set to true
if (
commitResult.exitCode != 0 &&
!commitResult.stdout.includes(NOTHING_TO_COMMIT)
) {
throw new Error(`Unexpected error: ${commitResult.stderr}`)
} }
await git.commit(params)
// Remove uncommitted tracked and untracked changes
await git.exec(['reset', '--hard'])
await git.exec(['clean', '-f'])
} }
// Remove uncommitted tracked and untracked changes
await git.exec(['reset', '--hard'])
await git.exec(['clean', '-f', '-d'])
// Perform fetch and reset the working base // Perform fetch and reset the working base
// Commits made during the workflow will be removed // Commits made during the workflow will be removed
if (workingBaseType == WorkingBaseType.Branch) { if (workingBaseType == WorkingBaseType.Branch) {

View File

@ -60,6 +60,9 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
: baseRemote.repository : baseRemote.repository
if (inputs.pushToFork) { if (inputs.pushToFork) {
// Check if the supplied fork is really a fork of the base // Check if the supplied fork is really a fork of the base
core.info(
`Checking if '${branchRepository}' is a fork of '${baseRemote.repository}'`
)
const parentRepository = await githubHelper.getRepositoryParent( const parentRepository = await githubHelper.getRepositoryParent(
branchRepository branchRepository
) )
@ -240,8 +243,8 @@ export async function createPullRequest(inputs: Inputs): Promise<void> {
} }
} }
} }
} catch (error: any) { } catch (error) {
core.setFailed(error.message) core.setFailed(utils.getErrorMessage(error))
} finally { } finally {
// Remove auth and restore persisted auth config if it existed // Remove auth and restore persisted auth config if it existed
core.startGroup('Restore persisted git credentials') core.startGroup('Restore persisted git credentials')

View File

@ -3,6 +3,7 @@ import * as fs from 'fs'
import {GitCommandManager} from './git-command-manager' import {GitCommandManager} from './git-command-manager'
import * as path from 'path' import * as path from 'path'
import {URL} from 'url' import {URL} from 'url'
import * as utils from './utils'
export class GitAuthHelper { export class GitAuthHelper {
private git: GitCommandManager private git: GitCommandManager
@ -33,8 +34,8 @@ export class GitAuthHelper {
try { try {
await this.setExtraheaderConfig(this.persistedExtraheaderConfigValue) await this.setExtraheaderConfig(this.persistedExtraheaderConfigValue)
core.info('Persisted git credentials restored') core.info('Persisted git credentials restored')
} catch (e: any) { } catch (e) {
core.warning(e) core.warning(utils.getErrorMessage(e))
} }
} }
} }

View File

@ -53,7 +53,10 @@ export class GitCommandManager {
return await this.exec(args, allowAllExitCodes) return await this.exec(args, allowAllExitCodes)
} }
async commit(options?: string[]): Promise<void> { async commit(
options?: string[],
allowAllExitCodes = false
): Promise<GitOutput> {
const args = ['commit'] const args = ['commit']
if (this.identityGitOptions) { if (this.identityGitOptions) {
args.unshift(...this.identityGitOptions) args.unshift(...this.identityGitOptions)
@ -63,7 +66,7 @@ export class GitCommandManager {
args.push(...options) args.push(...options)
} }
await this.exec(args) return await this.exec(args, allowAllExitCodes)
} }
async config( async config(
@ -155,17 +158,22 @@ export class GitCommandManager {
return output.exitCode === 1 return output.exitCode === 1
} }
async isDirty(untracked: boolean): Promise<boolean> { async isDirty(untracked: boolean, pathspec?: string[]): Promise<boolean> {
const pathspecArgs = pathspec ? ['--', ...pathspec] : []
// Check untracked changes // Check untracked changes
if (untracked && (await this.status(['--porcelain', '-unormal']))) { const sargs = ['--porcelain', '-unormal']
sargs.push(...pathspecArgs)
if (untracked && (await this.status(sargs))) {
return true return true
} }
// Check working index changes // Check working index changes
if (await this.hasDiff()) { if (await this.hasDiff(pathspecArgs)) {
return true return true
} }
// Check staged changes // Check staged changes
if (await this.hasDiff(['--staged'])) { const dargs = ['--staged']
dargs.push(...pathspecArgs)
if (await this.hasDiff(dargs)) {
return true return true
} }
return false return false

View File

@ -1,6 +1,7 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import {Inputs} from './create-pull-request' import {Inputs} from './create-pull-request'
import {Octokit, OctokitOptions} from './octokit-client' import {Octokit, OctokitOptions} from './octokit-client'
import * as utils from './utils'
const ERROR_PR_REVIEW_FROM_AUTHOR = const ERROR_PR_REVIEW_FROM_AUTHOR =
'Review cannot be requested from pull request author' 'Review cannot be requested from pull request author'
@ -39,8 +40,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`)
@ -60,10 +65,9 @@ export class GitHubHelper {
html_url: pull.html_url, html_url: pull.html_url,
created: true created: true
} }
} catch (e: any) { } catch (e) {
if ( if (
e.message && utils.getErrorMessage(e).includes(`A pull request already exists for`)
e.message.includes(`A pull request already exists for ${headBranch}`)
) { ) {
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) {
@ -164,8 +169,8 @@ export class GitHubHelper {
pull_number: pull.number, pull_number: pull.number,
...requestReviewersParams ...requestReviewersParams
}) })
} catch (e: any) { } catch (e) {
if (e.message && e.message.includes(ERROR_PR_REVIEW_FROM_AUTHOR)) { if (utils.getErrorMessage(e).includes(ERROR_PR_REVIEW_FROM_AUTHOR)) {
core.warning(ERROR_PR_REVIEW_FROM_AUTHOR) core.warning(ERROR_PR_REVIEW_FROM_AUTHOR)
} else { } else {
throw e throw e

View File

@ -30,8 +30,8 @@ async function run(): Promise<void> {
core.debug(`Inputs: ${inspect(inputs)}`) core.debug(`Inputs: ${inspect(inputs)}`)
await createPullRequest(inputs) await createPullRequest(inputs)
} catch (error: any) { } catch (error) {
core.setFailed(error.message) core.setFailed(utils.getErrorMessage(error))
} }
} }

View File

@ -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
}) })
} }

View File

@ -47,11 +47,11 @@ 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(
'^git@' + githubServerMatch[1] + ':(.+/.+).git$', '^git@' + githubServerMatch[1] + ':(.+/.+)\\.git$',
'i' 'i'
) )
@ -134,13 +134,15 @@ export function fileExistsSync(path: string): boolean {
let stats: fs.Stats let stats: fs.Stats
try { try {
stats = fs.statSync(path) stats = fs.statSync(path)
} catch (error: any) { } catch (error) {
if (error.code === 'ENOENT') { if (hasErrorCode(error) && error.code === 'ENOENT') {
return false return false
} }
throw new Error( throw new Error(
`Encountered an error when checking whether path '${path}' exists: ${error.message}` `Encountered an error when checking whether path '${path}' exists: ${getErrorMessage(
error
)}`
) )
} }
@ -150,3 +152,13 @@ export function fileExistsSync(path: string): boolean {
return false return false
} }
/* eslint-disable @typescript-eslint/no-explicit-any */
function hasErrorCode(error: any): error is {code: string} {
return typeof (error && error.code) === 'string'
}
export function getErrorMessage(error: unknown) {
if (error instanceof Error) return error.message
return String(error)
}