Skip to content

Commit b1ddad2

Browse files
peter-evansTeko012bgilbert
committed
feat: v6 (#2717)
* feat: update author and committer input defaults * Update github-actions[bot] * Update author to new email format * feat: optional input for git ops token * feat: allow push-to-fork to push to sibling repos (#2414) Fixes #2412. * build: update dist * feat: update action runtime to node 20 (#2340) * feat: add truncate warning to pull request body * perf: unshallow only when necessary * fix: remove the remote for the fork on completion * feat: infer github server and api urls * test: integration test fixes * build: bump major version * docs: update to v6 --------- Co-authored-by: Teko <[email protected]> Co-authored-by: Benjamin Gilbert <[email protected]>
1 parent bb80902 commit b1ddad2

24 files changed

+619
-490
lines changed

.github/workflows/ci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- uses: actions/checkout@v4
2323
- uses: actions/setup-node@v4
2424
with:
25-
node-version: 16.x
25+
node-version: 20.x
2626
cache: npm
2727
- run: npm ci
2828
- run: npm run build
@@ -68,8 +68,8 @@ jobs:
6868
uses: ./
6969
with:
7070
commit-message: '[CI] test ${{ matrix.target }}'
71-
committer: GitHub <noreply@github.com>
72-
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
71+
committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
72+
author: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>
7373
title: '[CI] test ${{ matrix.target }}'
7474
body: |
7575
- CI test case for target '${{ matrix.target }}'

.github/workflows/cpr-example-command.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ jobs:
1616
uses: ./
1717
with:
1818
commit-message: Update report
19-
committer: GitHub <noreply@github.com>
20-
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
19+
committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
20+
author: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>
2121
signoff: false
2222
title: '[Example] Update report'
2323
body: |

.github/workflows/update-major-version.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ on:
1111
type: choice
1212
description: The major version tag to update
1313
options:
14-
- v4
1514
- v5
15+
- v6
1616

1717
jobs:
1818
tag:

README.md

+14-13
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Create Pull Request action will:
2121

2222
- [Concepts, guidelines and advanced usage](docs/concepts-guidelines.md)
2323
- [Examples](docs/examples.md)
24-
- [Updating to v5](docs/updating.md)
24+
- [Updating to v6](docs/updating.md)
2525
- [Common issues](docs/common-issues.md)
2626

2727
## Usage
@@ -32,10 +32,10 @@ Create Pull Request action will:
3232
# Make changes to pull request here
3333

3434
- name: Create Pull Request
35-
uses: peter-evans/create-pull-request@v5
35+
uses: peter-evans/create-pull-request@v6
3636
```
3737
38-
You can also pin to a [specific release](https://github.com/peter-evans/create-pull-request/releases) version in the format `@v5.x.x`
38+
You can also pin to a [specific release](https://github.com/peter-evans/create-pull-request/releases) version in the format `@v6.x.x`
3939

4040
### Workflow permissions
4141

@@ -53,11 +53,12 @@ All inputs are **optional**. If not set, sensible defaults will be used.
5353
| Name | Description | Default |
5454
| --- | --- | --- |
5555
| `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` |
56+
| `git-token` | The [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) that the action will use for git operations. | Defaults to the value of `token` |
5657
| `path` | Relative path under `GITHUB_WORKSPACE` to the repository. | `GITHUB_WORKSPACE` |
5758
| `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). | |
5859
| `commit-message` | The message to use when committing changes. See [commit-message](#commit-message). | `[create-pull-request] automated change` |
59-
| `committer` | The committer name and email address in the format `Display Name <[email protected]>`. Defaults to the GitHub Actions bot user. | `GitHub <noreply@github.com>` |
60-
| `author` | The author name and email address in the format `Display Name <[email protected]>`. Defaults to the user who triggered the workflow run. | `${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>` |
60+
| `committer` | The committer name and email address in the format `Display Name <[email protected]>`. Defaults to the GitHub Actions bot user. | `github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>` |
61+
| `author` | The author name and email address in the format `Display Name <[email protected]>`. Defaults to the user who triggered the workflow run. | `${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>` |
6162
| `signoff` | Add [`Signed-off-by`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---signoff) line by the committer at the end of the commit log message. | `false` |
6263
| `branch` | The pull request branch name. | `create-pull-request/patch` |
6364
| `delete-branch` | Delete the `branch` if it doesn't have an active pull request associated with it. See [delete-branch](#delete-branch). | `false` |
@@ -99,7 +100,7 @@ If you want branches to be deleted immediately on merge then you should use GitH
99100
For self-hosted runners behind a corporate proxy set the `https_proxy` environment variable.
100101
```yml
101102
- name: Create Pull Request
102-
uses: peter-evans/create-pull-request@v5
103+
uses: peter-evans/create-pull-request@v6
103104
env:
104105
https_proxy: http://<proxy_address>:<port>
105106
```
@@ -119,7 +120,7 @@ Note that in order to read the step outputs the action step must have an id.
119120
```yml
120121
- name: Create Pull Request
121122
id: cpr
122-
uses: peter-evans/create-pull-request@v5
123+
uses: peter-evans/create-pull-request@v6
123124
- name: Check outputs
124125
if: ${{ steps.cpr.outputs.pull-request-number }}
125126
run: |
@@ -182,7 +183,7 @@ File changes that do not match one of the paths will be stashed and restored aft
182183

183184
```yml
184185
- name: Create Pull Request
185-
uses: peter-evans/create-pull-request@v5
186+
uses: peter-evans/create-pull-request@v6
186187
with:
187188
add-paths: |
188189
*.java
@@ -209,7 +210,7 @@ Note that the repository must be checked out on a branch with a remote, it won't
209210
- name: Uncommitted change
210211
run: date +%s > report.txt
211212
- name: Create Pull Request
212-
uses: peter-evans/create-pull-request@v5
213+
uses: peter-evans/create-pull-request@v6
213214
```
214215

215216
### Create a project card
@@ -219,7 +220,7 @@ To create a project card for the pull request, pass the `pull-request-number` st
219220
```yml
220221
- name: Create Pull Request
221222
id: cpr
222-
uses: peter-evans/create-pull-request@v5
223+
uses: peter-evans/create-pull-request@v6
223224
224225
- name: Create or Update Project Card
225226
if: ${{ steps.cpr.outputs.pull-request-number }}
@@ -254,12 +255,12 @@ jobs:
254255
255256
- name: Create Pull Request
256257
id: cpr
257-
uses: peter-evans/create-pull-request@v5
258+
uses: peter-evans/create-pull-request@v6
258259
with:
259260
token: ${{ secrets.PAT }}
260261
commit-message: Update report
261-
committer: GitHub <noreply@github.com>
262-
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
262+
committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
263+
author: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com>
263264
signoff: false
264265
branch: example-patches
265266
delete-branch: true

__test__/create-or-update-branch.int.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {GitCommandManager} from '../lib/git-command-manager'
88
import * as path from 'path'
99
import {v4 as uuidv4} from 'uuid'
1010

11-
const REPO_PATH = '/git/local/test-base'
11+
const REPO_PATH = '/git/local/repos/test-base'
1212
const REMOTE_NAME = 'origin'
1313

1414
const TRACKED_FILE = 'a/tracked-file.txt'
@@ -22,7 +22,7 @@ const INIT_COMMIT_MESSAGE = 'Add file to be a tracked file for tests'
2222
const BRANCH = 'tests/create-pull-request/patch'
2323
const BASE = DEFAULT_BRANCH
2424

25-
const FORK_REMOTE_URL = 'git://127.0.0.1/test-fork.git'
25+
const FORK_REMOTE_URL = 'git://127.0.0.1/repos/test-fork.git'
2626
const FORK_REMOTE_NAME = 'fork'
2727

2828
const ADD_PATHS_DEFAULT = []

__test__/entrypoint.sh

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ set -euo pipefail
55
WORKINGDIR=$PWD
66

77
# Create and serve a remote repo
8-
mkdir -p /git/remote
8+
mkdir -p /git/remote/repos
99
git config --global init.defaultBranch main
10-
git init --bare /git/remote/test-base.git
10+
git init --bare /git/remote/repos/test-base.git
1111
git daemon --verbose --enable=receive-pack --base-path=/git/remote --export-all /git/remote &>/dev/null &
1212

1313
# Give the daemon time to start
1414
sleep 2
1515

1616
# Create a local clone and make an initial commit
17-
mkdir -p /git/local
18-
git clone git://127.0.0.1/test-base.git /git/local/test-base
19-
cd /git/local/test-base
17+
mkdir -p /git/local/repos
18+
git clone git://127.0.0.1/repos/test-base.git /git/local/repos/test-base
19+
cd /git/local/repos/test-base
2020
git config --global user.email "[email protected]"
2121
git config --global user.name "Your Name"
2222
echo "#test-base" > README.md
@@ -30,8 +30,8 @@ git config -l
3030

3131
# Clone a server-side fork of the base repo
3232
cd $WORKINGDIR
33-
git clone --mirror git://127.0.0.1/test-base.git /git/remote/test-fork.git
34-
cd /git/remote/test-fork.git
33+
git clone --mirror git://127.0.0.1/repos/test-base.git /git/remote/repos/test-fork.git
34+
cd /git/remote/repos/test-fork.git
3535
git log -1 --pretty=oneline
3636

3737
# Restore the working directory
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,86 @@
11
import {GitCommandManager} from '../lib/git-command-manager'
2-
import {GitAuthHelper} from '../lib/git-auth-helper'
2+
import {GitConfigHelper} from '../lib/git-config-helper'
33

4-
const REPO_PATH = '/git/local/test-base'
4+
const REPO_PATH = '/git/local/repos/test-base'
55

6-
const extraheaderConfigKey = 'http.https://github.com/.extraheader'
6+
const extraheaderConfigKey = 'http.https://127.0.0.1/.extraheader'
77

8-
describe('git-auth-helper tests', () => {
8+
describe('git-config-helper integration tests', () => {
99
let git: GitCommandManager
10-
let gitAuthHelper: GitAuthHelper
10+
let gitConfigHelper: GitConfigHelper
1111

1212
beforeAll(async () => {
1313
git = await GitCommandManager.create(REPO_PATH)
14-
gitAuthHelper = new GitAuthHelper(git)
1514
})
1615

1716
it('tests save and restore with no persisted auth', async () => {
18-
await gitAuthHelper.savePersistedAuth()
19-
await gitAuthHelper.restorePersistedAuth()
17+
const gitConfigHelper = await GitConfigHelper.create(git)
18+
await gitConfigHelper.close()
2019
})
2120

2221
it('tests configure and removal of auth', async () => {
23-
await gitAuthHelper.configureToken('github-token')
22+
const gitConfigHelper = await GitConfigHelper.create(git)
23+
await gitConfigHelper.configureToken('github-token')
2424
expect(await git.configExists(extraheaderConfigKey)).toBeTruthy()
2525
expect(await git.getConfigValue(extraheaderConfigKey)).toEqual(
2626
'AUTHORIZATION: basic eC1hY2Nlc3MtdG9rZW46Z2l0aHViLXRva2Vu'
2727
)
2828

29-
await gitAuthHelper.removeAuth()
29+
await gitConfigHelper.close()
3030
expect(await git.configExists(extraheaderConfigKey)).toBeFalsy()
3131
})
3232

3333
it('tests save and restore of persisted auth', async () => {
3434
const extraheaderConfigValue = 'AUTHORIZATION: basic ***persisted-auth***'
3535
await git.config(extraheaderConfigKey, extraheaderConfigValue)
3636

37-
await gitAuthHelper.savePersistedAuth()
37+
const gitConfigHelper = await GitConfigHelper.create(git)
3838

3939
const exists = await git.configExists(extraheaderConfigKey)
4040
expect(exists).toBeFalsy()
4141

42-
await gitAuthHelper.restorePersistedAuth()
42+
await gitConfigHelper.close()
4343

4444
const configValue = await git.getConfigValue(extraheaderConfigKey)
4545
expect(configValue).toEqual(extraheaderConfigValue)
4646

47-
await gitAuthHelper.removeAuth()
47+
const unset = await git.tryConfigUnset(
48+
extraheaderConfigKey,
49+
'^AUTHORIZATION:'
50+
)
51+
expect(unset).toBeTruthy()
4852
})
4953

50-
it('tests adding and removing the safe.directory config', async () => {
54+
it('tests not adding/removing the safe.directory config when it already exists', async () => {
5155
await git.config('safe.directory', '/another-value', true, true)
5256

53-
await gitAuthHelper.removeSafeDirectory()
54-
await gitAuthHelper.addSafeDirectory()
57+
const gitConfigHelper = await GitConfigHelper.create(git)
58+
59+
expect(
60+
await git.configExists('safe.directory', '/another-value', true)
61+
).toBeTruthy()
62+
63+
await gitConfigHelper.close()
64+
65+
const unset = await git.tryConfigUnset(
66+
'safe.directory',
67+
'/another-value',
68+
true
69+
)
70+
expect(unset).toBeTruthy()
71+
})
72+
73+
it('tests adding and removing the safe.directory config', async () => {
74+
const gitConfigHelper = await GitConfigHelper.create(git)
5575

5676
expect(
5777
await git.configExists('safe.directory', REPO_PATH, true)
5878
).toBeTruthy()
5979

60-
await gitAuthHelper.addSafeDirectory()
61-
await gitAuthHelper.removeSafeDirectory()
80+
await gitConfigHelper.close()
6281

6382
expect(
6483
await git.configExists('safe.directory', REPO_PATH, true)
6584
).toBeFalsy()
66-
expect(
67-
await git.configExists('safe.directory', '/another-value', true)
68-
).toBeTruthy()
6985
})
7086
})
+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import {GitConfigHelper} from '../lib/git-config-helper'
2+
3+
describe('git-config-helper unit tests', () => {
4+
test('parseGitRemote successfully parses HTTPS remote URLs', async () => {
5+
const remote1 = GitConfigHelper.parseGitRemote(
6+
'https://github.com/peter-evans/create-pull-request'
7+
)
8+
expect(remote1.hostname).toEqual('github.com')
9+
expect(remote1.protocol).toEqual('HTTPS')
10+
expect(remote1.repository).toEqual('peter-evans/create-pull-request')
11+
12+
const remote2 = GitConfigHelper.parseGitRemote(
13+
'https://xxx:[email protected]/peter-evans/create-pull-request'
14+
)
15+
expect(remote2.hostname).toEqual('github.com')
16+
expect(remote2.protocol).toEqual('HTTPS')
17+
expect(remote2.repository).toEqual('peter-evans/create-pull-request')
18+
19+
const remote3 = GitConfigHelper.parseGitRemote(
20+
'https://github.com/peter-evans/create-pull-request.git'
21+
)
22+
expect(remote3.hostname).toEqual('github.com')
23+
expect(remote3.protocol).toEqual('HTTPS')
24+
expect(remote3.repository).toEqual('peter-evans/create-pull-request')
25+
26+
const remote4 = GitConfigHelper.parseGitRemote(
27+
'https://github.com/peter-evans/ungit'
28+
)
29+
expect(remote4.hostname).toEqual('github.com')
30+
expect(remote4.protocol).toEqual('HTTPS')
31+
expect(remote4.repository).toEqual('peter-evans/ungit')
32+
33+
const remote5 = GitConfigHelper.parseGitRemote(
34+
'https://github.com/peter-evans/ungit.git'
35+
)
36+
expect(remote5.hostname).toEqual('github.com')
37+
expect(remote5.protocol).toEqual('HTTPS')
38+
expect(remote5.repository).toEqual('peter-evans/ungit')
39+
40+
const remote6 = GitConfigHelper.parseGitRemote(
41+
'https://github.internal.company/peter-evans/create-pull-request'
42+
)
43+
expect(remote6.hostname).toEqual('github.internal.company')
44+
expect(remote6.protocol).toEqual('HTTPS')
45+
expect(remote6.repository).toEqual('peter-evans/create-pull-request')
46+
})
47+
48+
test('parseGitRemote successfully parses SSH remote URLs', async () => {
49+
const remote1 = GitConfigHelper.parseGitRemote(
50+
'[email protected]:peter-evans/create-pull-request.git'
51+
)
52+
expect(remote1.hostname).toEqual('github.com')
53+
expect(remote1.protocol).toEqual('SSH')
54+
expect(remote1.repository).toEqual('peter-evans/create-pull-request')
55+
56+
const remote2 = GitConfigHelper.parseGitRemote(
57+
'[email protected]:peter-evans/ungit.git'
58+
)
59+
expect(remote2.hostname).toEqual('github.com')
60+
expect(remote2.protocol).toEqual('SSH')
61+
expect(remote2.repository).toEqual('peter-evans/ungit')
62+
63+
const remote3 = GitConfigHelper.parseGitRemote(
64+
'[email protected]:peter-evans/create-pull-request.git'
65+
)
66+
expect(remote3.hostname).toEqual('github.internal.company')
67+
expect(remote3.protocol).toEqual('SSH')
68+
expect(remote3.repository).toEqual('peter-evans/create-pull-request')
69+
})
70+
71+
test('parseGitRemote successfully parses GIT remote URLs', async () => {
72+
// Unauthenticated git protocol for integration tests only
73+
const remote1 = GitConfigHelper.parseGitRemote(
74+
'git://127.0.0.1/repos/test-base.git'
75+
)
76+
expect(remote1.hostname).toEqual('127.0.0.1')
77+
expect(remote1.protocol).toEqual('GIT')
78+
expect(remote1.repository).toEqual('repos/test-base')
79+
})
80+
81+
test('parseGitRemote fails to parse a remote URL', async () => {
82+
const remoteUrl = 'https://github.com/peter-evans'
83+
try {
84+
GitConfigHelper.parseGitRemote(remoteUrl)
85+
// Fail the test if an error wasn't thrown
86+
expect(true).toEqual(false)
87+
} catch (e: any) {
88+
expect(e.message).toEqual(
89+
`The format of '${remoteUrl}' is not a valid GitHub repository URL`
90+
)
91+
}
92+
})
93+
})

0 commit comments

Comments
 (0)