Compare commits
31 Commits
Author | SHA1 | Date | |
---|---|---|---|
e1e9dd3f1c | |||
8c2a43987b | |||
c5ff844b40 | |||
1f47cf3861 | |||
bcdc7ae6f9 | |||
91ca84eab5 | |||
875d189c30 | |||
7c3f5f4833 | |||
7a7e797068 | |||
a41f37fc96 | |||
10554ac6c3 | |||
2439726cfe | |||
4f04f4efd9 | |||
32d0abbc7c | |||
ed5b8b1eea | |||
ea241dfc79 | |||
0e70fec054 | |||
5077e8d6bd | |||
901e854f30 | |||
f3b1bd6331 | |||
51ade9f54b | |||
3c86dbf9e6 | |||
b2d426ea4e | |||
fbe0cd3d1a | |||
5f9821866a | |||
ee153ec8cf | |||
e138d84114 | |||
90843d3c39 | |||
90ad96bd01 | |||
f8cc05d28d | |||
fe78afb6d7 |
13
.github/workflows/create-pull-request-multi.yml
vendored
13
.github/workflows/create-pull-request-multi.yml
vendored
@ -1,7 +1,7 @@
|
|||||||
|
name: create-pull-request workflow
|
||||||
on:
|
on:
|
||||||
repository_dispatch:
|
repository_dispatch:
|
||||||
types: [create-pull-request-multi]
|
types: [create-pull-request-multi]
|
||||||
name: create-pull-request workflow
|
|
||||||
jobs:
|
jobs:
|
||||||
createPullRequest:
|
createPullRequest:
|
||||||
name: Testing on ${{ matrix.platform }}
|
name: Testing on ${{ matrix.platform }}
|
||||||
@ -22,10 +22,15 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
COMMIT_MESSAGE: Add report file
|
COMMIT_MESSAGE: Add report file
|
||||||
PULL_REQUEST_BODY: >
|
COMMIT_AUTHOR_EMAIL: peter-evans@users.noreply.github.com
|
||||||
This PR is auto-generated by
|
COMMIT_AUTHOR_NAME: Peter Evans
|
||||||
[create-pull-request](https://github.com/peter-evans/create-pull-request).
|
|
||||||
PULL_REQUEST_TITLE: '[Example] Add report file'
|
PULL_REQUEST_TITLE: '[Example] Add report file'
|
||||||
|
PULL_REQUEST_BODY: |
|
||||||
|
New report
|
||||||
|
- Contains *today's* date
|
||||||
|
- Auto-generated by [create-pull-request][1]
|
||||||
|
|
||||||
|
[1]: https://github.com/peter-evans/create-pull-request
|
||||||
PULL_REQUEST_LABELS: report, automated pr
|
PULL_REQUEST_LABELS: report, automated pr
|
||||||
PULL_REQUEST_ASSIGNEES: peter-evans
|
PULL_REQUEST_ASSIGNEES: peter-evans
|
||||||
PULL_REQUEST_REVIEWERS: peter-evans
|
PULL_REQUEST_REVIEWERS: peter-evans
|
||||||
|
13
.github/workflows/create-pull-request.yml
vendored
13
.github/workflows/create-pull-request.yml
vendored
@ -1,7 +1,7 @@
|
|||||||
|
name: create-pull-request workflow
|
||||||
on:
|
on:
|
||||||
repository_dispatch:
|
repository_dispatch:
|
||||||
types: [create-pull-request]
|
types: [create-pull-request]
|
||||||
name: create-pull-request workflow
|
|
||||||
jobs:
|
jobs:
|
||||||
createPullRequest:
|
createPullRequest:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@ -14,10 +14,15 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
COMMIT_MESSAGE: Add report file
|
COMMIT_MESSAGE: Add report file
|
||||||
PULL_REQUEST_BODY: >
|
COMMIT_AUTHOR_EMAIL: peter-evans@users.noreply.github.com
|
||||||
This PR is auto-generated by
|
COMMIT_AUTHOR_NAME: Peter Evans
|
||||||
[create-pull-request](https://github.com/peter-evans/create-pull-request).
|
|
||||||
PULL_REQUEST_TITLE: '[Example] Add report file'
|
PULL_REQUEST_TITLE: '[Example] Add report file'
|
||||||
|
PULL_REQUEST_BODY: |
|
||||||
|
New report
|
||||||
|
- Contains *today's* date
|
||||||
|
- Auto-generated by [create-pull-request][1]
|
||||||
|
|
||||||
|
[1]: https://github.com/peter-evans/create-pull-request
|
||||||
PULL_REQUEST_LABELS: report, automated pr
|
PULL_REQUEST_LABELS: report, automated pr
|
||||||
PULL_REQUEST_ASSIGNEES: peter-evans
|
PULL_REQUEST_ASSIGNEES: peter-evans
|
||||||
PULL_REQUEST_REVIEWERS: peter-evans
|
PULL_REQUEST_REVIEWERS: peter-evans
|
||||||
|
177
README.md
177
README.md
@ -10,7 +10,7 @@ The changes will be automatically committed to a new branch and a pull request c
|
|||||||
Create Pull Request action will:
|
Create Pull Request action will:
|
||||||
|
|
||||||
1. Check for repository changes in the Actions workspace. This includes untracked (new) files as well as modified files.
|
1. Check for repository changes in the Actions workspace. This includes untracked (new) files as well as modified files.
|
||||||
2. Commit all changes to a new branch, or update an existing pull request branch. The commit will be made using the name and email of the `HEAD` commit author.
|
2. Commit all changes to a new branch, or update an existing pull request branch.
|
||||||
3. Create a pull request to merge the new branch into the currently active branch executing the workflow.
|
3. Create a pull request to merge the new branch into the currently active branch executing the workflow.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@ -18,7 +18,7 @@ Create Pull Request action will:
|
|||||||
Linux
|
Linux
|
||||||
```yml
|
```yml
|
||||||
- name: Create Pull Request
|
- name: Create Pull Request
|
||||||
uses: peter-evans/create-pull-request@v1.4.1
|
uses: peter-evans/create-pull-request@v1.5.2
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
```
|
```
|
||||||
@ -26,7 +26,7 @@ Linux
|
|||||||
Multi platform - Linux, MacOS, Windows (beta)
|
Multi platform - Linux, MacOS, Windows (beta)
|
||||||
```yml
|
```yml
|
||||||
- name: Create Pull Request
|
- name: Create Pull Request
|
||||||
uses: peter-evans/create-pull-request@v1.4.1-multi
|
uses: peter-evans/create-pull-request@v1.5.2-multi
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
```
|
```
|
||||||
@ -36,23 +36,30 @@ See [this issue](https://github.com/peter-evans/create-pull-request/issues/48) f
|
|||||||
|
|
||||||
### Environment variables
|
### Environment variables
|
||||||
|
|
||||||
These variables are all optional. If not set, a default value will be used.
|
These variables are *all optional*. If not set, sensible default values will be used.
|
||||||
|
|
||||||
- `COMMIT_MESSAGE` - The message to use when committing changes.
|
| Name | Description | Default |
|
||||||
- `PULL_REQUEST_TITLE` - The title of the pull request.
|
| --- | --- | --- |
|
||||||
- `PULL_REQUEST_BODY` - The body of the pull request.
|
| `COMMIT_MESSAGE` | The message to use when committing changes. | `Auto-committed changes by create-pull-request action` |
|
||||||
- `PULL_REQUEST_LABELS` - A comma separated list of labels.
|
| `COMMIT_AUTHOR_EMAIL` | The email address of the commit author. | For `push` events, the HEAD commit author. Otherwise, <GITHUB_ACTOR>@users.noreply.github.com, where `GITHUB_ACTOR` is the GitHub user that initiated the event. |
|
||||||
- `PULL_REQUEST_ASSIGNEES` - A comma separated list of assignees (GitHub usernames).
|
| `COMMIT_AUTHOR_NAME` | The name of the commit author. | For `push` events, the HEAD commit author. Otherwise, <GITHUB_ACTOR>, the GitHub user that initiated the event. |
|
||||||
- `PULL_REQUEST_REVIEWERS` - A comma separated list of reviewers (GitHub usernames) to request a review from.
|
| `PULL_REQUEST_TITLE` | The title of the pull request. | `Auto-generated by create-pull-request action` |
|
||||||
- `PULL_REQUEST_TEAM_REVIEWERS` - A comma separated list of GitHub teams to request a review from.
|
| `PULL_REQUEST_BODY` | The body of the pull request. | `Auto-generated pull request by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub Action` |
|
||||||
- `PULL_REQUEST_MILESTONE` - The number of the milestone to associate this pull request with.
|
| `PULL_REQUEST_LABELS` | A comma separated list of labels. | none |
|
||||||
- `PULL_REQUEST_BRANCH` - The branch name. See **Branch naming** below for details.
|
| `PULL_REQUEST_ASSIGNEES` | A comma separated list of assignees (GitHub usernames). | none |
|
||||||
- `BRANCH_SUFFIX` - The branch suffix type. Valid values are `short-commit-hash` (default), `timestamp`, `random` and `none`. See **Branch naming** below for details.
|
| `PULL_REQUEST_REVIEWERS` | A comma separated list of reviewers (GitHub usernames) to request a review from. | none |
|
||||||
|
| `PULL_REQUEST_TEAM_REVIEWERS` | A comma separated list of GitHub teams to request a review from. | none |
|
||||||
|
| `PULL_REQUEST_MILESTONE` | The number of the milestone to associate this pull request with. | none |
|
||||||
|
| `PULL_REQUEST_BRANCH` | The branch name. See **Branch naming** below for details. | `create-pull-request/patch` |
|
||||||
|
| `PULL_REQUEST_BASE` | Overrides the base branch. **Use with caution!** | Defaults to the currently checked out branch. |
|
||||||
|
| `BRANCH_SUFFIX` | The branch suffix type. Valid values are `short-commit-hash`, `timestamp`, `random` and `none`. See **Branch naming** below for details. | `short-commit-hash` |
|
||||||
|
|
||||||
Output environment variables
|
**Output environment variables**
|
||||||
|
|
||||||
- `PULL_REQUEST_NUMBER` - The number of the pull request created.
|
- `PULL_REQUEST_NUMBER` - The number of the pull request created.
|
||||||
|
|
||||||
|
**Debug environment variables**
|
||||||
|
|
||||||
The following parameters are available for debugging and troubleshooting.
|
The following parameters are available for debugging and troubleshooting.
|
||||||
|
|
||||||
- `DEBUG_EVENT` - If present, outputs the event data that triggered the workflow.
|
- `DEBUG_EVENT` - If present, outputs the event data that triggered the workflow.
|
||||||
@ -81,15 +88,15 @@ To use this strategy, set `BRANCH_SUFFIX` to the value `none`. The variable `PUL
|
|||||||
|
|
||||||
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.
|
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.
|
Here is an example that sets all the main environment variables.
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
|
name: create-pull-request workflow
|
||||||
on:
|
on:
|
||||||
repository_dispatch:
|
repository_dispatch:
|
||||||
types: [create-pull-request]
|
types: [create-pull-request]
|
||||||
name: create-pull-request workflow
|
|
||||||
jobs:
|
jobs:
|
||||||
createPullRequest:
|
createPullRequest:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@ -98,14 +105,19 @@ jobs:
|
|||||||
- name: Create report file
|
- name: Create report file
|
||||||
run: date +%s > report.txt
|
run: date +%s > report.txt
|
||||||
- name: Create Pull Request
|
- name: Create Pull Request
|
||||||
uses: peter-evans/create-pull-request@v1.4.1
|
uses: peter-evans/create-pull-request@v1.5.2
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
COMMIT_MESSAGE: Add report file
|
COMMIT_MESSAGE: Add report file
|
||||||
PULL_REQUEST_BODY: >
|
COMMIT_AUTHOR_EMAIL: peter-evans@users.noreply.github.com
|
||||||
This PR is auto-generated by
|
COMMIT_AUTHOR_NAME: Peter Evans
|
||||||
[create-pull-request](https://github.com/peter-evans/create-pull-request).
|
|
||||||
PULL_REQUEST_TITLE: '[Example] Add report file'
|
PULL_REQUEST_TITLE: '[Example] Add report file'
|
||||||
|
PULL_REQUEST_BODY: |
|
||||||
|
New report
|
||||||
|
- Contains *today's* date
|
||||||
|
- Auto-generated by [create-pull-request][1]
|
||||||
|
|
||||||
|
[1]: https://github.com/peter-evans/create-pull-request
|
||||||
PULL_REQUEST_LABELS: report, automated pr
|
PULL_REQUEST_LABELS: report, automated pr
|
||||||
PULL_REQUEST_ASSIGNEES: peter-evans
|
PULL_REQUEST_ASSIGNEES: peter-evans
|
||||||
PULL_REQUEST_REVIEWERS: peter-evans
|
PULL_REQUEST_REVIEWERS: peter-evans
|
||||||
@ -118,7 +130,128 @@ jobs:
|
|||||||
|
|
||||||
This configuration will create pull requests that look like this:
|
This configuration will create pull requests that look like this:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
|
### Example workflow to automate periodic dependency updates
|
||||||
|
|
||||||
|
This example workflow executes once a week and will create a pull request for any dependency updates. This pattern will work well for updating any kind of static content from an external source.
|
||||||
|
|
||||||
|
```yml
|
||||||
|
name: Update Dependencies
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 10 * * 1'
|
||||||
|
jobs:
|
||||||
|
update-deps:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: '10.x'
|
||||||
|
- name: Update dependencies
|
||||||
|
id: vars
|
||||||
|
run: |
|
||||||
|
npm install -g npm-check-updates
|
||||||
|
ncu -u
|
||||||
|
npm install
|
||||||
|
- name: Create Pull Request
|
||||||
|
uses: peter-evans/create-pull-request@v1.5.2
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
COMMIT_MESSAGE: update dependencies
|
||||||
|
COMMIT_AUTHOR_EMAIL: peter-evans@users.noreply.github.com
|
||||||
|
COMMIT_AUTHOR_NAME: Peter Evans
|
||||||
|
PULL_REQUEST_TITLE: Automated Dependency Updates
|
||||||
|
PULL_REQUEST_BODY: This is an auto-generated PR with dependency updates.
|
||||||
|
PULL_REQUEST_LABELS: dep-updates, automated pr
|
||||||
|
PULL_REQUEST_REVIEWERS: peter-evans
|
||||||
|
PULL_REQUEST_BRANCH: dep-updates
|
||||||
|
BRANCH_SUFFIX: none
|
||||||
|
```
|
||||||
|
|
||||||
|
### Example usage with "on: pull_request" workflows
|
||||||
|
|
||||||
|
The following is an example workflow for a use-case where [autopep8 action](https://github.com/peter-evans/autopep8) runs as both a check on pull requests and raises a further pull request to apply code fixes. This is a pattern that would work well for any automated code linting and fixing.
|
||||||
|
|
||||||
|
How it works:
|
||||||
|
|
||||||
|
1. When a pull request is raised the workflow executes as a check
|
||||||
|
2. If autopep8 makes any fixes a pull request will be raised for those fixes to be merged into the current pull request branch. The workflow then deliberately causes the check to fail.
|
||||||
|
3. When the pull request containing the fixes is merged the workflow runs again. This time autopep8 makes no changes and the check passes.
|
||||||
|
4. The original pull request can now be merged.
|
||||||
|
|
||||||
|
```yml
|
||||||
|
name: autopep8
|
||||||
|
on: pull_request
|
||||||
|
jobs:
|
||||||
|
autopep8:
|
||||||
|
if: startsWith(github.head_ref, 'autopep8-patches') == false
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- name: autopep8
|
||||||
|
id: autopep8
|
||||||
|
uses: peter-evans/autopep8@v1.1.0
|
||||||
|
with:
|
||||||
|
args: --exit-code --recursive --in-place --aggressive --aggressive .
|
||||||
|
- name: Set autopep8 branch name
|
||||||
|
id: vars
|
||||||
|
run: echo ::set-output name=branch-name::"autopep8-patches/$GITHUB_HEAD_REF"
|
||||||
|
- name: Create Pull Request
|
||||||
|
if: steps.autopep8.outputs.exit-code == 2
|
||||||
|
uses: peter-evans/create-pull-request@v1.5.2
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
COMMIT_MESSAGE: autopep8 action fixes
|
||||||
|
COMMIT_AUTHOR_EMAIL: peter-evans@users.noreply.github.com
|
||||||
|
COMMIT_AUTHOR_NAME: Peter Evans
|
||||||
|
PULL_REQUEST_TITLE: Fixes by autopep8 action
|
||||||
|
PULL_REQUEST_BODY: This is an auto-generated PR with fixes by autopep8.
|
||||||
|
PULL_REQUEST_LABELS: autopep8, automated pr
|
||||||
|
PULL_REQUEST_REVIEWERS: peter-evans
|
||||||
|
PULL_REQUEST_BRANCH: ${{ steps.vars.outputs.branch-name }}
|
||||||
|
BRANCH_SUFFIX: none
|
||||||
|
- name: Fail if autopep8 made changes
|
||||||
|
if: steps.autopep8.outputs.exit-code == 2
|
||||||
|
run: exit 1
|
||||||
|
```
|
||||||
|
|
||||||
|
### 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.2
|
||||||
|
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.2
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ author: 'Peter Evans'
|
|||||||
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'
|
||||||
runs:
|
runs:
|
||||||
using: 'docker'
|
using: 'docker'
|
||||||
image: 'docker://peterevans/create-pull-request:1.5.0'
|
image: 'docker://peterevans/create-pull-request:1.5.3'
|
||||||
branding:
|
branding:
|
||||||
icon: 'git-pull-request'
|
icon: 'git-pull-request'
|
||||||
color: 'gray-dark'
|
color: 'gray-dark'
|
||||||
|
@ -23,7 +23,7 @@ def ignore_event(event_name, event_data):
|
|||||||
if event_name == "push":
|
if event_name == "push":
|
||||||
# Ignore push events on deleted branches
|
# Ignore push events on deleted branches
|
||||||
# The event we want to ignore occurs when a PR is created but the repository owner decides
|
# The event we want to ignore occurs when a PR is created but the repository owner decides
|
||||||
# not to commit the changes. They close the PR and delete the branch. This creates a
|
# not to commit the changes. They close the PR and delete the branch. This creates a
|
||||||
# "push" event that we want to ignore, otherwise it will create another branch and PR on
|
# "push" event that we want to ignore, otherwise it will create another branch and PR on
|
||||||
# the same commit.
|
# the same commit.
|
||||||
deleted = "{deleted}".format(**event_data)
|
deleted = "{deleted}".format(**event_data)
|
||||||
@ -52,7 +52,7 @@ def remote_branch_exists(repo, branch):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_head_author(event_name, event_data):
|
def get_author_default(event_name, event_data):
|
||||||
if event_name == "push":
|
if event_name == "push":
|
||||||
email = "{head_commit[author][email]}".format(**event_data)
|
email = "{head_commit[author][email]}".format(**event_data)
|
||||||
name = "{head_commit[author][name]}".format(**event_data)
|
name = "{head_commit[author][name]}".format(**event_data)
|
||||||
@ -68,7 +68,9 @@ def set_git_config(git, email, name):
|
|||||||
|
|
||||||
|
|
||||||
def set_git_remote_url(git, token, github_repository):
|
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))
|
git.remote(
|
||||||
|
'set-url', 'origin', "https://x-access-token:%s@github.com/%s" %
|
||||||
|
(token, github_repository))
|
||||||
|
|
||||||
|
|
||||||
def checkout_branch(git, remote_exists, branch):
|
def checkout_branch(git, remote_exists, branch):
|
||||||
@ -77,7 +79,7 @@ def checkout_branch(git, remote_exists, branch):
|
|||||||
git.checkout(branch)
|
git.checkout(branch)
|
||||||
try:
|
try:
|
||||||
git.stash('pop')
|
git.stash('pop')
|
||||||
except:
|
except BaseException:
|
||||||
git.checkout('--theirs', '.')
|
git.checkout('--theirs', '.')
|
||||||
git.reset()
|
git.reset()
|
||||||
else:
|
else:
|
||||||
@ -140,7 +142,9 @@ def process_event(event_name, event_data, repo, branch, base, remote_exists):
|
|||||||
base=base,
|
base=base,
|
||||||
head=branch)
|
head=branch)
|
||||||
print("Created pull request %d." % pull_request.number)
|
print("Created pull request %d." % pull_request.number)
|
||||||
os.system('echo ::set-env name=PULL_REQUEST_NUMBER::%d' % pull_request.number)
|
os.system(
|
||||||
|
'echo ::set-env name=PULL_REQUEST_NUMBER::%d' %
|
||||||
|
pull_request.number)
|
||||||
|
|
||||||
# Set labels, assignees and milestone
|
# Set labels, assignees and milestone
|
||||||
if pull_request_labels is not None:
|
if pull_request_labels is not None:
|
||||||
@ -157,10 +161,12 @@ def process_event(event_name, event_data, repo, branch, base, remote_exists):
|
|||||||
# Set pull request reviewers and team reviewers
|
# Set pull request reviewers and team reviewers
|
||||||
if pull_request_reviewers is not None:
|
if pull_request_reviewers is not None:
|
||||||
print("Requesting reviewers")
|
print("Requesting reviewers")
|
||||||
pull_request.create_review_request(reviewers=cs_string_to_list(pull_request_reviewers))
|
pull_request.create_review_request(
|
||||||
|
reviewers=cs_string_to_list(pull_request_reviewers))
|
||||||
if pull_request_team_reviewers is not None:
|
if pull_request_team_reviewers is not None:
|
||||||
print("Requesting team reviewers")
|
print("Requesting team reviewers")
|
||||||
pull_request.create_review_request(team_reviewers=cs_string_to_list(pull_request_team_reviewers))
|
pull_request.create_review_request(
|
||||||
|
team_reviewers=cs_string_to_list(pull_request_team_reviewers))
|
||||||
|
|
||||||
|
|
||||||
# Get the JSON event data
|
# Get the JSON event data
|
||||||
@ -174,8 +180,20 @@ if skip_ignore_event or not ignore_event(event_name, event_data):
|
|||||||
|
|
||||||
# Fetch/Set the branch name
|
# Fetch/Set the branch name
|
||||||
branch = os.getenv('PULL_REQUEST_BRANCH', 'create-pull-request/patch')
|
branch = os.getenv('PULL_REQUEST_BRANCH', 'create-pull-request/patch')
|
||||||
# Set the current branch as the target base branch
|
|
||||||
base = os.environ['GITHUB_REF'][11:]
|
# Set the base branch
|
||||||
|
github_ref = os.environ['GITHUB_REF']
|
||||||
|
if github_ref.startswith('refs/pull/'):
|
||||||
|
# Switch to the merging branch instead of the merge commit
|
||||||
|
base = os.environ['GITHUB_HEAD_REF']
|
||||||
|
else:
|
||||||
|
base = github_ref[11:]
|
||||||
|
|
||||||
|
# Optional base override
|
||||||
|
base = os.getenv('PULL_REQUEST_BASE', base)
|
||||||
|
|
||||||
|
# Checkout the base branch
|
||||||
|
repo.git.checkout(base)
|
||||||
|
|
||||||
# Skip if the current branch is a PR branch created by this action
|
# Skip if the current branch is a PR branch created by this action
|
||||||
if base.startswith(branch):
|
if base.startswith(branch):
|
||||||
@ -197,14 +215,19 @@ if skip_ignore_event or not ignore_event(event_name, event_data):
|
|||||||
# Check if the remote branch exists
|
# Check if the remote branch exists
|
||||||
remote_exists = remote_branch_exists(repo, branch)
|
remote_exists = remote_branch_exists(repo, branch)
|
||||||
|
|
||||||
# If using short commit hash prefixes, check if a remote
|
# If using short commit hash prefixes, check if a remote
|
||||||
# branch already exists for this HEAD commit
|
# branch already exists for this HEAD commit
|
||||||
if branch_suffix == 'short-commit-hash' and remote_exists:
|
if branch_suffix == 'short-commit-hash' and remote_exists:
|
||||||
print("Pull request branch '%s' already exists for this commit. Skipping." % branch)
|
print(
|
||||||
|
"Pull request branch '%s' already exists for this commit. Skipping." %
|
||||||
|
branch)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
# Get the HEAD committer's email and name
|
# Get the default for author email and name
|
||||||
author_email, author_name = get_head_author(event_name, event_data)
|
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 configuration
|
||||||
set_git_config(repo.git, author_email, author_name)
|
set_git_config(repo.git, author_email, author_name)
|
||||||
# Checkout branch
|
# Checkout branch
|
||||||
@ -213,6 +236,12 @@ if skip_ignore_event or not ignore_event(event_name, event_data):
|
|||||||
# Check if there are changes to pull request
|
# Check if there are changes to pull request
|
||||||
if repo.is_dirty() or len(repo.untracked_files) > 0:
|
if repo.is_dirty() or len(repo.untracked_files) > 0:
|
||||||
print("Repository has modified or untracked files.")
|
print("Repository has modified or untracked files.")
|
||||||
process_event(event_name, event_data, repo, branch, base, remote_exists)
|
process_event(
|
||||||
|
event_name,
|
||||||
|
event_data,
|
||||||
|
repo,
|
||||||
|
branch,
|
||||||
|
base,
|
||||||
|
remote_exists)
|
||||||
else:
|
else:
|
||||||
print("Repository has no modified or untracked files. Skipping.")
|
print("Repository has no modified or untracked files. Skipping.")
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 201 KiB After Width: | Height: | Size: 441 KiB |
@ -1,2 +1,2 @@
|
|||||||
GitPython==3.0.3
|
GitPython==3.0.3
|
||||||
PyGithub==1.43.8
|
PyGithub==1.44
|
||||||
|
Reference in New Issue
Block a user