Compare commits
24 Commits
v1.4.0-mul
...
v1.5.1-mul
Author | SHA1 | Date | |
---|---|---|---|
234d8686a5 | |||
b39e1dc4cf | |||
5f9821866a | |||
ee153ec8cf | |||
e138d84114 | |||
90843d3c39 | |||
90ad96bd01 | |||
f8cc05d28d | |||
fe78afb6d7 | |||
a0c4cfcf18 | |||
8c223b540a | |||
af7dbce93d | |||
2e283eddc6 | |||
3e0a17d097 | |||
7ebddff547 | |||
1397aded03 | |||
40fd4990fc | |||
5784478398 | |||
d30b03b696 | |||
c1363c2fed | |||
6e9abd8a8d | |||
ef76e27efb | |||
6be23859c3 | |||
aa09d77c75 |
@ -22,10 +22,12 @@ jobs:
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
COMMIT_MESSAGE: Add report file
|
||||
COMMIT_AUTHOR_EMAIL: peter-evans@users.noreply.github.com
|
||||
COMMIT_AUTHOR_NAME: Peter Evans
|
||||
PULL_REQUEST_TITLE: '[Example] Add report file'
|
||||
PULL_REQUEST_BODY: >
|
||||
This PR is auto-generated by
|
||||
[create-pull-request](https://github.com/peter-evans/create-pull-request).
|
||||
PULL_REQUEST_TITLE: '[Example] Add report file'
|
||||
PULL_REQUEST_LABELS: report, automated pr
|
||||
PULL_REQUEST_ASSIGNEES: peter-evans
|
||||
PULL_REQUEST_REVIEWERS: peter-evans
|
||||
|
4
.github/workflows/create-pull-request.yml
vendored
4
.github/workflows/create-pull-request.yml
vendored
@ -14,10 +14,12 @@ jobs:
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
COMMIT_MESSAGE: Add report file
|
||||
COMMIT_AUTHOR_EMAIL: peter-evans@users.noreply.github.com
|
||||
COMMIT_AUTHOR_NAME: Peter Evans
|
||||
PULL_REQUEST_TITLE: '[Example] Add report file'
|
||||
PULL_REQUEST_BODY: >
|
||||
This PR is auto-generated by
|
||||
[create-pull-request](https://github.com/peter-evans/create-pull-request).
|
||||
PULL_REQUEST_TITLE: '[Example] Add report file'
|
||||
PULL_REQUEST_LABELS: report, automated pr
|
||||
PULL_REQUEST_ASSIGNEES: peter-evans
|
||||
PULL_REQUEST_REVIEWERS: peter-evans
|
||||
|
16
.github/workflows/push.yml
vendored
Normal file
16
.github/workflows/push.yml
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
name: Update Docker Hub Description
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
jobs:
|
||||
dockerHubDescription:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Docker Hub Description
|
||||
uses: peter-evans/dockerhub-description@v2.1.0
|
||||
env:
|
||||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
DOCKERHUB_REPOSITORY: peterevans/create-pull-request
|
83
README.md
83
README.md
@ -1,4 +1,4 @@
|
||||
# Create Pull Request
|
||||
# <img width="24" height="24" src="logo.svg"> Create Pull Request
|
||||
[](https://github.com/marketplace/actions/create-pull-request)
|
||||
|
||||
A GitHub action to create a pull request for changes to your repository in the actions workspace.
|
||||
@ -18,7 +18,7 @@ Create Pull Request action will:
|
||||
Linux
|
||||
```yml
|
||||
- name: Create Pull Request
|
||||
uses: peter-evans/create-pull-request@v1.4.0
|
||||
uses: peter-evans/create-pull-request@v1.5.0
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
@ -26,12 +26,15 @@ Linux
|
||||
Multi platform - Linux, MacOS, Windows (beta)
|
||||
```yml
|
||||
- name: Create Pull Request
|
||||
uses: peter-evans/create-pull-request@v1.3.1-multi
|
||||
uses: peter-evans/create-pull-request@v1.5.0-multi
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
|
||||
#### Environment variables
|
||||
**Note**: If you want pull requests created by this action to trigger an `on: pull_request` workflow then you must use a Personal Access Token instead of the default `GITHUB_TOKEN`.
|
||||
See [this issue](https://github.com/peter-evans/create-pull-request/issues/48) for further details.
|
||||
|
||||
### Environment variables
|
||||
|
||||
These variables are all optional. If not set, a default value will be used.
|
||||
|
||||
@ -55,39 +58,30 @@ The following parameters are available for debugging and troubleshooting.
|
||||
- `DEBUG_EVENT` - If present, outputs the event data that triggered the workflow.
|
||||
- `SKIP_IGNORE` - If present, the `ignore_event` function will be skipped.
|
||||
|
||||
#### Branch naming
|
||||
### Branch naming
|
||||
|
||||
For branch naming there are two strategies. Always create a new branch each time there are changes to be committed, OR, create a pull request branch that will be updated with any new commits until it is merged or closed.
|
||||
For branch naming there are two strategies. Always create a new branch each time there are changes to be committed, OR, create a fixed-name pull request branch that will be updated with any new commits until it is merged or closed.
|
||||
|
||||
**Strategy A - Always create a new pull request branch (default)**
|
||||
#### Strategy A - Always create a new pull request branch (default)
|
||||
|
||||
For this strategy there are three options to suffix the branch name.
|
||||
The branch name is defined by the variable `PULL_REQUEST_BRANCH` and defaults to `create-pull-request/patch`.
|
||||
The branch name is defined by the variable `PULL_REQUEST_BRANCH` and defaults to `create-pull-request/patch`. The following options are values for `BRANCH_SUFFIX`.
|
||||
|
||||
1. `short-commit-hash` (default)
|
||||
- `short-commit-hash` (default) - Commits will be made to a branch suffixed with the short SHA1 commit hash. e.g. `create-pull-request/patch-fcdfb59`, `create-pull-request/patch-394710b`
|
||||
|
||||
Commits will be made to a branch suffixed with the short SHA1 commit hash.
|
||||
eg. `create-pull-request/patch-fcdfb59`, `create-pull-request/patch-394710b`
|
||||
- `timestamp` - Commits will be made to a branch suffixed by a timestamp. e.g. `create-pull-request/patch-1569322532`, `create-pull-request/patch-1569322552`
|
||||
|
||||
2. `timestamp`
|
||||
- `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`
|
||||
|
||||
Commits will be made to a branch suffixed by a timestamp.
|
||||
eg. `create-pull-request/patch-1569322532`, `create-pull-request/patch-1569322552`
|
||||
#### Strategy B - Create and update a pull request branch
|
||||
|
||||
3. `random`
|
||||
To use this strategy, set `BRANCH_SUFFIX` to the value `none`. The variable `PULL_REQUEST_BRANCH` defaults to `create-pull-request/patch`. Commits will be made to this branch and a pull request created. Any subsequent changes will be committed to the *same* branch and reflected in the existing pull request.
|
||||
|
||||
Commits will be made to a branch suffixed with a random alpha-numeric string. This option must be used if multiple pull requests will be created during the execution of a workflow.
|
||||
eg. `create-pull-request/patch-6qj97jr`, `create-pull-request/patch-5jrjhvd`
|
||||
|
||||
**Strategy B - Create and update a pull request branch**
|
||||
|
||||
To use this strategy, set `BRANCH_SUFFIX` to the value `none`. The variable `PULL_REQUEST_BRANCH` defaults to `create-pull-request/patch`. Commits will be made to this branch and a pull request created. Any subsequent changes will be committed to the same branch and reflected in the existing pull request.
|
||||
|
||||
#### Ignoring files
|
||||
### Ignoring files
|
||||
|
||||
If there are files or directories you want to ignore you can simply add them to a `.gitignore` file at the root of your repository. The action will respect this file.
|
||||
|
||||
## Example
|
||||
## Examples
|
||||
|
||||
Here is an example that sets all the main environment variables.
|
||||
|
||||
@ -104,14 +98,14 @@ jobs:
|
||||
- name: Create report file
|
||||
run: date +%s > report.txt
|
||||
- name: Create Pull Request
|
||||
uses: peter-evans/create-pull-request@v1.4.0
|
||||
uses: peter-evans/create-pull-request@v1.5.0
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
COMMIT_MESSAGE: Add report file
|
||||
PULL_REQUEST_TITLE: '[Example] Add report file'
|
||||
PULL_REQUEST_BODY: >
|
||||
This PR is auto-generated by
|
||||
[create-pull-request](https://github.com/peter-evans/create-pull-request).
|
||||
PULL_REQUEST_TITLE: '[Example] Add report file'
|
||||
PULL_REQUEST_LABELS: report, automated pr
|
||||
PULL_REQUEST_ASSIGNEES: peter-evans
|
||||
PULL_REQUEST_REVIEWERS: peter-evans
|
||||
@ -124,7 +118,42 @@ jobs:
|
||||
|
||||
This configuration will create pull requests that look like this:
|
||||
|
||||

|
||||

|
||||
|
||||
### Dynamic configuration using variables
|
||||
|
||||
The following examples show how configuration for the action can be dynamically defined in a previous workflow step.
|
||||
|
||||
The recommended method is to use `set-output`. Note that the step where output variables are defined must have an id.
|
||||
|
||||
```yml
|
||||
- name: Set output variables
|
||||
id: vars
|
||||
run: |
|
||||
echo ::set-output name=pr_title::"[Test] Add report file $(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)."
|
||||
- name: Create Pull Request
|
||||
uses: peter-evans/create-pull-request@v1.5.0
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
PULL_REQUEST_TITLE: ${{ steps.vars.outputs.pr_title }}
|
||||
PULL_REQUEST_BODY: ${{ steps.vars.outputs.pr_body }}
|
||||
```
|
||||
|
||||
Since the action reads environment variables from the system, it's technically not necessary to explicitly pass them as long as they exist in the environment. So the following method using `set-env` *also* works, but explicitly passing the configuration parameters using the previous method is perferred for its clarity.
|
||||
|
||||
```yml
|
||||
- name: Set environment variables
|
||||
run: |
|
||||
echo ::set-env name=PULL_REQUEST_TITLE::"[Test] Add report file $(date +%d-%m-%Y)"
|
||||
echo ::set-env name=PULL_REQUEST_BODY::"This PR was auto-generated on $(date +%d-%m-%Y) \
|
||||
by [create-pull-request](https://github.com/peter-evans/create-pull-request)."
|
||||
- name: Create Pull Request
|
||||
uses: peter-evans/create-pull-request@v1.5.0
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
|
@ -1,5 +1,9 @@
|
||||
name: 'Create Pull Request'
|
||||
author: 'Peter Evans'
|
||||
description: 'Creates a pull request for changes to your repository in the actions workspace'
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'index.js'
|
||||
branding:
|
||||
icon: 'git-pull-request'
|
||||
color: 'gray-dark'
|
@ -52,7 +52,7 @@ def remote_branch_exists(repo, branch):
|
||||
return False
|
||||
|
||||
|
||||
def get_head_author(event_name, event_data):
|
||||
def get_author_default(event_name, event_data):
|
||||
if event_name == "push":
|
||||
email = "{head_commit[author][email]}".format(**event_data)
|
||||
name = "{head_commit[author][name]}".format(**event_data)
|
||||
@ -71,14 +71,22 @@ def set_git_remote_url(git, token, github_repository):
|
||||
git.remote('set-url', 'origin', "https://x-access-token:%s@github.com/%s" % (token, github_repository))
|
||||
|
||||
|
||||
def push_changes(git, remote_exists, branch, commit_message):
|
||||
git.add('-A')
|
||||
git.commit(m=commit_message)
|
||||
def checkout_branch(git, remote_exists, branch):
|
||||
if remote_exists:
|
||||
git.stash('--include-untracked')
|
||||
git.checkout(branch)
|
||||
git.rebase('-Xtheirs', '-')
|
||||
try:
|
||||
git.stash('pop')
|
||||
except:
|
||||
git.checkout('--theirs', '.')
|
||||
git.reset()
|
||||
else:
|
||||
git.checkout('HEAD', b=branch)
|
||||
|
||||
|
||||
def push_changes(git, branch, commit_message):
|
||||
git.add('-A')
|
||||
git.commit(m=commit_message)
|
||||
return git.push('-f', '--set-upstream', 'origin', branch)
|
||||
|
||||
|
||||
@ -110,16 +118,12 @@ def process_event(event_name, event_data, repo, branch, base, remote_exists):
|
||||
pull_request_reviewers = os.environ.get('PULL_REQUEST_REVIEWERS')
|
||||
pull_request_team_reviewers = os.environ.get('PULL_REQUEST_TEAM_REVIEWERS')
|
||||
|
||||
# Get the HEAD committer's email and name
|
||||
author_email, author_name = get_head_author(event_name, event_data)
|
||||
# Set git configuration
|
||||
set_git_config(repo.git, author_email, author_name)
|
||||
# Update URL for the 'origin' remote
|
||||
set_git_remote_url(repo.git, github_token, github_repository)
|
||||
|
||||
# Push the local changes to the remote branch
|
||||
print("Pushing changes.")
|
||||
push_result = push_changes(repo.git, remote_exists, branch, commit_message)
|
||||
push_result = push_changes(repo.git, branch, commit_message)
|
||||
print(push_result)
|
||||
|
||||
# If the remote existed then a PR likely exists and we can finish here
|
||||
@ -199,6 +203,16 @@ if skip_ignore_event or not ignore_event(event_name, event_data):
|
||||
print("Pull request branch '%s' already exists for this commit. Skipping." % branch)
|
||||
sys.exit()
|
||||
|
||||
# Get the default for author email and name
|
||||
author_email, author_name = get_author_default(event_name, event_data)
|
||||
# Set commit author overrides
|
||||
author_email = os.getenv('COMMIT_AUTHOR_EMAIL', author_email)
|
||||
author_name = os.getenv('COMMIT_AUTHOR_NAME', author_name)
|
||||
# Set git configuration
|
||||
set_git_config(repo.git, author_email, author_name)
|
||||
# Checkout branch
|
||||
checkout_branch(repo.git, remote_exists, branch)
|
||||
|
||||
# Check if there are changes to pull request
|
||||
if repo.is_dirty() or len(repo.untracked_files) > 0:
|
||||
print("Repository has modified or untracked files.")
|
||||
|
6
logo.svg
Normal file
6
logo.svg
Normal file
@ -0,0 +1,6 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="43%" height="43%" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="color: #000000;"><title>git-pull-request</title>
|
||||
<circle cx="18" cy="18" r="3"></circle>
|
||||
<circle cx="6" cy="6" r="3"></circle>
|
||||
<path d="M13 6h3a2 2 0 0 1 2 2v7"></path>
|
||||
<line x1="6" y1="9" x2="6" y2="21"></line>
|
||||
</svg>
|
After Width: | Height: | Size: 416 B |
@ -1,2 +1,2 @@
|
||||
GitPython==3.0.2
|
||||
GitPython==3.0.3
|
||||
PyGithub==1.43.8
|
||||
|
Reference in New Issue
Block a user