Compare commits

..

20 Commits
v2.8.0 ... v2

Author SHA1 Message Date
Peter Evans
4d3b0a48ef Merge pull request #394 from peter-evans/update-distribution
Update distribution
2020-06-27 17:10:28 +09:00
peter-evans
e9a825aacd Update distribution 2020-06-27 08:06:58 +00:00
Peter Evans
3509fd45ae Merge pull request #389 from peter-evans/dev
Parse repo urls with credentials
2020-06-27 17:03:41 +09:00
Peter Evans
14ee9d1df2 Parse repo urls with credentials 2020-06-27 16:45:24 +09:00
Peter Evans
5d969a55c1 Add gradle example 2020-06-05 18:23:04 +09:00
Peter Evans
44130f6fc9 Merge pull request #369 from peter-evans/types
Add missing types
2020-06-03 17:09:43 +09:00
Peter Evans
86ccd8cdef Add missing types 2020-06-03 16:47:02 +09:00
Peter Evans
7e7fa32a5f Merge pull request #364 from peter-evans/fix-ci
Fix ci artifacts
2020-06-02 18:21:51 +09:00
Peter Evans
5f7beeb2ff Fix ci artifacts 2020-06-02 18:16:23 +09:00
Peter Evans
926d56fcba Update documentation 2020-06-02 16:44:14 +09:00
Peter Evans
8d744a2cd3 Remove reaction-token 2020-06-02 15:58:02 +09:00
Peter Evans
c2d829c681 Update documentation 2020-05-27 11:43:25 +09:00
Peter Evans
d77392faf0 Update slash command dispatch token 2020-05-25 17:15:16 +09:00
Peter Evans
ccd2b64012 Add rebase slash command 2020-05-25 16:12:13 +09:00
Peter Evans
58fb221778 Merge pull request #339 from peter-evans/update-distribution
Update distribution
2020-05-24 09:36:26 +09:00
peter-evans
7a856e8b5d Update distribution 2020-05-24 00:34:21 +00:00
Peter Evans
65d7a66451 Merge pull request #293 from peter-evans/renovate/setuptools-46.x
Update dependency setuptools to v46.4.0
2020-05-24 09:30:21 +09:00
Renovate Bot
44a7f59b6f Update dependency setuptools to v46.4.0 2020-05-23 06:24:24 +00:00
Peter Evans
8acaf6bb4c Merge pull request #330 from peter-evans/int-tests
Integration testing
2020-05-23 15:16:37 +09:00
Peter Evans
498d78cb23 Add integration testing 2020-05-23 14:43:18 +09:00
25 changed files with 2099 additions and 1871 deletions

View File

@@ -32,6 +32,10 @@ jobs:
with:
name: dist
path: dist
- uses: actions/upload-artifact@v2
with:
name: action.yml
path: action.yml
test:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
@@ -49,6 +53,11 @@ jobs:
with:
name: dist
path: dist
- if: matrix.target == 'built' || github.event_name == 'pull_request'
uses: actions/download-artifact@v2
with:
name: action.yml
path: .
- name: Create change
run: date +%s > report.txt

View File

@@ -9,8 +9,7 @@ jobs:
- name: Slash Command Dispatch
uses: peter-evans/slash-command-dispatch@v1
with:
token: ${{ secrets.REPO_ACCESS_TOKEN }}
reaction-token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
config: >
[
{
@@ -34,5 +33,11 @@ jobs:
"command": "cpr-example",
"permission": "admin",
"issue_type": "issue"
},
{
"command": "rebase",
"permission": "admin",
"repository": "peter-evans/slash-command-dispatch-processor",
"issue_type": "pull-request"
}
]

View File

@@ -55,10 +55,10 @@ All inputs are **optional**. If not set, sensible default values will be used.
| `project` | *Deprecated*. See [Create a project card](#create-a-project-card) for details. | |
| `project-column` | *Deprecated*. See [Create a project card](#create-a-project-card) for details. | |
| `draft` | Create a [draft pull request](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests#draft-pull-requests). | `false` |
| `branch` | The branch name. See [Branch naming](#branch-naming) for details. | `create-pull-request/patch` |
| `branch` | The branch name. See [Action behaviour](#action-behaviour) for details. | `create-pull-request/patch` |
| `request-to-parent` | Create the pull request in the parent repository of the checked out fork. See [push pull request branches to a fork](https://github.com/peter-evans/create-pull-request/blob/master/docs/concepts-guidelines.md#push-pull-request-branches-to-a-fork) for details. | `false` |
| `base` | Sets the pull request base branch. | Defaults to the branch checked out in the workflow. |
| `branch-suffix` | The branch suffix type. Valid values are `random`, `timestamp` and `short-commit-hash`. See [Branch naming](#branch-naming) for details. | |
| `branch-suffix` | The branch suffix type. Valid values are `random`, `timestamp` and `short-commit-hash`. See [Action behaviour](#action-behaviour) for details. | |
### Action outputs
@@ -86,20 +86,29 @@ If there is some reason you need to use `actions/checkout@v1` the following step
- run: git checkout "${GITHUB_REF:11}"
```
### Branch naming
### Action behaviour
For branch naming there are two strategies. Create a fixed-name pull request branch that will be updated with new changes until it is merged or closed, OR, always create a new unique branch each time there are changes to be committed.
The default behaviour of the action is to create a pull request that will be continually updated with new changes until it is merged or closed.
Changes are committed and pushed to a fixed-name branch, the name of which can be configured with the `branch` input.
Any subsequent changes will be committed to the *same* branch and reflected in the open pull request.
#### Strategy A - Create and update a pull request branch (default)
How the action behaves:
This strategy is the default behaviour of the action. The input `branch` defaults to `create-pull-request/patch`. Changes will be committed to this branch and a pull request created. Any subsequent changes will be committed to the *same* branch and reflected in the open pull request. If the pull request is merged or closed a new one will be created. If subsequent changes cause the branch to no longer differ from the base the pull request will be automatically closed and the branch deleted.
- 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 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 exists and new changes on the base branch make the pull request unnecessary (i.e. there is no longer a diff between the base and pull request branch), the pull request is automatically closed and the branch deleted.
#### Strategy B - Always create a new pull request branch
For further details about how the action works and usage guidelines, see [Concepts, guidelines and advanced usage](docs/concepts-guidelines.md).
For this strategy there are three options to suffix the branch name.
The branch name is defined by the input `branch` and defaults to `create-pull-request/patch`. The following options are values for `branch-suffix`.
#### Alternative strategy - Always create a new pull request branch
- `random` - Commits will be made to a branch suffixed with a random alpha-numeric string. This option should be used if multiple pull requests will be created during the execution of a workflow. e.g. `create-pull-request/patch-6qj97jr`, `create-pull-request/patch-5jrjhvd`
For some use cases it *may* be desirable to always create a new unique branch each time there are changes to be committed.
This strategy is not recommended and mainly kept for backwards compatibility.
To use this strategy, set input `branch-suffix` with one of the following options.
- `random` - Commits will be made to a branch suffixed with a random alpha-numeric string. e.g. `create-pull-request/patch-6qj97jr`, `create-pull-request/patch-5jrjhvd`
- `timestamp` - Commits will be made to a branch suffixed by a timestamp. e.g. `create-pull-request/patch-1569322532`, `create-pull-request/patch-1569322552`

29
__test__/entrypoint.sh Executable file
View File

@@ -0,0 +1,29 @@
#!/bin/sh -l
set -euo pipefail
# Save the working directory
WORKINGDIR=$PWD
# Serve remote repo
mkdir /git
git init --bare /git/test-repo.git
git daemon --verbose --enable=receive-pack --base-path=/git --export-all /git/test-repo.git &>/dev/null &
# Give the daemon time to start
sleep 2
# Clone and make an initial commit
git clone git://127.0.0.1/test-repo.git /git/test-repo
cd /git/test-repo
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
echo "#test-repo" > README.md
git add .
git commit -m "initial commit"
git push -u
# Restore the working directory
cd $WORKINGDIR
# Execute integration tests
jest int

View File

@@ -1,6 +1,4 @@
import * as path from 'path'
import {
ConfigOption,
getRepoPath,
execGit,
addConfigOption,
@@ -15,7 +13,7 @@ const originalGitHubWorkspace = process.env['GITHUB_WORKSPACE']
describe('git tests', () => {
beforeAll(() => {
// GitHub workspace
process.env['GITHUB_WORKSPACE'] = __dirname
process.env['GITHUB_WORKSPACE'] = '/git/test-repo'
})
afterAll(() => {
@@ -26,14 +24,7 @@ describe('git tests', () => {
}
})
test('getRepoPath', async () => {
expect(getRepoPath()).toEqual(process.env['GITHUB_WORKSPACE'])
expect(getRepoPath('foo')).toEqual(
path.resolve(process.env['GITHUB_WORKSPACE'] || '', 'foo')
)
})
test('execGit', async () => {
it('successfully executes a git command', async () => {
const repoPath = getRepoPath()
const result = await execGit(
repoPath,
@@ -75,13 +66,13 @@ describe('git tests', () => {
expect(unset).toBeTruthy()
})
test('configOptionExists returns true', async () => {
it('determines that a config option exists', async () => {
const repoPath = getRepoPath()
const result = await configOptionExists(repoPath, 'remote.origin.url')
expect(result).toBeTruthy()
})
test('configOptionExists returns false', async () => {
it('determines that a config option does not exist', async () => {
const repoPath = getRepoPath()
const result = await configOptionExists(repoPath, 'this.key.does.not.exist')
expect(result).toBeFalsy()

26
__test__/git.unit.test.ts Normal file
View File

@@ -0,0 +1,26 @@
import * as path from 'path'
import {getRepoPath} from '../lib/git'
const originalGitHubWorkspace = process.env['GITHUB_WORKSPACE']
describe('git tests', () => {
beforeAll(() => {
// GitHub workspace
process.env['GITHUB_WORKSPACE'] = __dirname
})
afterAll(() => {
// Restore GitHub workspace
delete process.env['GITHUB_WORKSPACE']
if (originalGitHubWorkspace) {
process.env['GITHUB_WORKSPACE'] = originalGitHubWorkspace
}
})
test('getRepoPath', async () => {
expect(getRepoPath()).toEqual(process.env['GITHUB_WORKSPACE'])
expect(getRepoPath('foo')).toEqual(
path.resolve(process.env['GITHUB_WORKSPACE'] || '', 'foo')
)
})
})

23
__test__/integration-tests.sh Executable file
View File

@@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -euo pipefail
IMAGE="cpr-integration-tests:latest"
ARG1=${1:-}
if [[ "$(docker images -q $IMAGE 2> /dev/null)" == "" || $ARG1 == "build" ]]; then
echo "Building Docker image $IMAGE ..."
cat > Dockerfile << EOF
FROM node:12-alpine
RUN apk --no-cache add git git-daemon
RUN npm install jest --global
WORKDIR /cpr
COPY __test__/entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
EOF
docker build -t $IMAGE .
rm Dockerfile
fi
docker run -v $PWD:/cpr $IMAGE

2
dist/cpr/common.py vendored
View File

@@ -11,7 +11,7 @@ def get_random_string(length=7, chars=string.ascii_lowercase + string.digits):
def parse_github_repository(url):
# Parse the protocol and github repository from a URL
# e.g. HTTPS, peter-evans/create-pull-request
https_pattern = re.compile(r"^https://github.com/(.+/.+)$")
https_pattern = re.compile(r"^https://.*@?github.com/(.+/.+)$")
ssh_pattern = re.compile(r"^git@github.com:(.+/.+).git$")
match = https_pattern.match(url)

View File

@@ -1,4 +1,4 @@
setuptools==46.2.0
setuptools==46.4.0
wheel==0.34.2
GitPython==3.1.2
PyGithub==1.51

View File

@@ -16,6 +16,12 @@ def test_parse_github_repository_success():
assert protocol == "HTTPS"
assert repository == "peter-evans/create-pull-request"
protocol, repository = cmn.parse_github_repository(
"https://xxx:x-oauth-basic@github.com/peter-evans/create-pull-request"
)
assert protocol == "HTTPS"
assert repository == "peter-evans/create-pull-request"
protocol, repository = cmn.parse_github_repository(
"git@github.com:peter-evans/create-pull-request.git"
)

18
dist/index.js vendored
View File

@@ -4861,14 +4861,16 @@ function bytesToUuid(buf, offset) {
var i = offset || 0;
var bth = byteToHex;
// join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4
return ([bth[buf[i++]], bth[buf[i++]],
bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]],
bth[buf[i++]], bth[buf[i++]],
bth[buf[i++]], bth[buf[i++]]]).join('');
return ([
bth[buf[i++]], bth[buf[i++]],
bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]],
bth[buf[i++]], bth[buf[i++]],
bth[buf[i++]], bth[buf[i++]]
]).join('');
}
module.exports = bytesToUuid;

Binary file not shown.

BIN
dist/vendor/certifi-2020.6.20.tar.gz vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
dist/vendor/requests-2.24.0.tar.gz vendored Normal file

Binary file not shown.

View File

@@ -241,7 +241,9 @@ jobs:
image: alpine
steps:
- name: Install dependencies
run: apk --no-cache add git python3
run: |
apk --no-cache add git python3
python3 -m ensurepip
- uses: actions/checkout@v2

View File

@@ -5,6 +5,7 @@
- [Keep a branch up-to-date with another](#keep-a-branch-up-to-date-with-another)
- [Use case: Create a pull request to update X periodically](#use-case-create-a-pull-request-to-update-x-periodically)
- [Update NPM dependencies](#update-npm-dependencies)
- [Update Gradle dependencies](#update-gradle-dependencies)
- [Update SwaggerUI for GitHub Pages](#update-swaggerui-for-github-pages)
- [Spider and download a website](#spider-and-download-a-website)
- [Use case: Create a pull request to update X by calling the GitHub API](#use-case-create-a-pull-request-to-update-x-by-calling-the-github-api)
@@ -144,6 +145,44 @@ jobs:
- run: npm run build
```
### Update Gradle dependencies
The following workflow will create a pull request for Gradle dependencies.
It requires first configuring your project to use Gradle lockfiles.
See [here](https://github.com/peter-evans/gradle-auto-dependency-updates) for how to configure your project and use the following workflow.
```yml
name: Update Dependencies
on:
schedule:
- cron: '0 1 * * 1'
jobs:
update-dep:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Perform dependency resolution and write new lockfiles
run: ./gradlew dependencies --write-locks
- name: Create Pull Request
uses: peter-evans/create-pull-request@v2
with:
token: ${{ secrets.PAT }}
commit-message: Update dependencies
title: Update dependencies
body: |
- Dependency updates
Auto-generated by [create-pull-request][1]
[1]: https://github.com/peter-evans/create-pull-request
branch: update-dependencies
```
### Update SwaggerUI for GitHub Pages
When using [GitHub Pages to host Swagger documentation](https://github.com/peter-evans/swagger-github-pages), this workflow updates the repository with the latest distribution of [SwaggerUI](https://github.com/swagger-api/swagger-ui).

3719
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -10,7 +10,9 @@
"format": "prettier --write '**/*.ts'",
"format-check": "prettier --check '**/*.ts'",
"lint": "eslint src/**/*.ts",
"test": "jest --passWithNoTests",
"test:unit": "jest unit",
"test:int": "__test__/integration-tests.sh",
"test": "npm run test:unit && npm run test:int",
"pack-assets": "mkdir -p dist/cpr && cp -rv src/cpr/* dist/cpr",
"vendor-deps": "pip download -r src/cpr/requirements.txt --no-binary=:all: -d dist/vendor",
"package": "npm run build && npm run pack-assets && npm run vendor-deps"

View File

@@ -11,7 +11,7 @@ def get_random_string(length=7, chars=string.ascii_lowercase + string.digits):
def parse_github_repository(url):
# Parse the protocol and github repository from a URL
# e.g. HTTPS, peter-evans/create-pull-request
https_pattern = re.compile(r"^https://github.com/(.+/.+)$")
https_pattern = re.compile(r"^https://.*@?github.com/(.+/.+)$")
ssh_pattern = re.compile(r"^git@github.com:(.+/.+).git$")
match = https_pattern.match(url)

View File

@@ -1,4 +1,4 @@
setuptools==46.2.0
setuptools==46.4.0
wheel==0.34.2
GitPython==3.1.2
PyGithub==1.51

View File

@@ -16,6 +16,12 @@ def test_parse_github_repository_success():
assert protocol == "HTTPS"
assert repository == "peter-evans/create-pull-request"
protocol, repository = cmn.parse_github_repository(
"https://xxx:x-oauth-basic@github.com/peter-evans/create-pull-request"
)
assert protocol == "HTTPS"
assert repository == "peter-evans/create-pull-request"
protocol, repository = cmn.parse_github_repository(
"git@github.com:peter-evans/create-pull-request.git"
)

View File

@@ -50,7 +50,11 @@ export async function execGit(
return result
}
export async function addConfigOption(repoPath, name, value): Promise<boolean> {
export async function addConfigOption(
repoPath: string,
name: string,
value: string
): Promise<boolean> {
const result = await execGit(
repoPath,
['config', '--local', '--add', name, value],
@@ -60,8 +64,8 @@ export async function addConfigOption(repoPath, name, value): Promise<boolean> {
}
export async function unsetConfigOption(
repoPath,
name,
repoPath: string,
name: string,
valueRegex = '.'
): Promise<boolean> {
const result = await execGit(
@@ -73,8 +77,8 @@ export async function unsetConfigOption(
}
export async function configOptionExists(
repoPath,
name,
repoPath: string,
name: string,
valueRegex = '.'
): Promise<boolean> {
const result = await execGit(
@@ -86,8 +90,8 @@ export async function configOptionExists(
}
export async function getConfigOption(
repoPath,
name,
repoPath: string,
name: string,
valueRegex = '.'
): Promise<ConfigOption> {
const option = new ConfigOption()
@@ -102,8 +106,8 @@ export async function getConfigOption(
}
export async function getAndUnsetConfigOption(
repoPath,
name,
repoPath: string,
name: string,
valueRegex = '.'
): Promise<ConfigOption> {
if (await configOptionExists(repoPath, name, valueRegex)) {

View File

@@ -10,7 +10,7 @@ import * as semver from 'semver'
* @param {string} versionSpec version of Python
* @param {string} arch architecture (x64|x32)
*/
export function setupPython(versionSpec, arch): Promise<void> {
export function setupPython(versionSpec: string, arch: string): Promise<void> {
return new Promise(resolve => {
const IS_WINDOWS = process.platform === 'win32'