Compare commits

...

25 Commits

Author SHA1 Message Date
83c11ef20d Merge branch 'multi-platform' into multi-platform-release 2019-10-14 02:01:51 +09:00
4fce601813 Merge branch 'master' into multi-platform 2019-10-14 02:01:37 +09:00
f3b1bd6331 Update image version 2019-10-14 01:58:42 +09:00
51ade9f54b Fix for pull refs 2019-10-14 01:39:53 +09:00
3c86dbf9e6 Update README 2019-10-06 15:13:32 +09:00
b2d426ea4e Update README 2019-10-06 15:06:49 +09:00
fbe0cd3d1a Update README 2019-10-06 14:59:45 +09:00
234d8686a5 Merge branch 'multi-platform' into multi-platform-release 2019-10-06 14:58:05 +09:00
b39e1dc4cf Merge branch 'master' into multi-platform 2019-10-06 14:57:52 +09:00
5f9821866a Update workflows 2019-10-06 14:52:15 +09:00
ee153ec8cf Update image version 2019-10-06 14:52:01 +09:00
e138d84114 Add variables to override the commit author name and email 2019-10-06 14:38:15 +09:00
90843d3c39 Update README 2019-10-05 09:22:43 +09:00
90ad96bd01 Update workflows 2019-10-05 09:22:35 +09:00
f8cc05d28d Update README 2019-10-04 14:53:58 +09:00
fe78afb6d7 Update README 2019-10-04 14:46:26 +09:00
a0c4cfcf18 Merge branch 'multi-platform' into multi-platform-release 2019-10-04 14:45:05 +09:00
8c223b540a Merge branch 'master' into multi-platform 2019-10-04 14:44:44 +09:00
af7dbce93d Merge remote-tracking branch 'origin/master' 2019-10-04 14:36:11 +09:00
2e283eddc6 Add workflow to automatically update dockerhub description 2019-10-04 14:35:58 +09:00
3e0a17d097 Update action to use pre-built container 2019-10-04 14:35:22 +09:00
7ebddff547 Merge pull request #52 from peter-evans/renovate/gitpython-3.x
Update dependency GitPython to v3.0.3
2019-10-04 14:30:27 +09:00
1397aded03 Update dependency GitPython to v3.0.3 2019-10-02 19:31:01 +00:00
40fd4990fc Update README 2019-10-02 22:38:58 +09:00
5784478398 Update README 2019-10-02 19:28:30 +09:00
6 changed files with 126 additions and 36 deletions

View File

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

View File

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

View File

@ -10,7 +10,7 @@ The changes will be automatically committed to a new branch and a pull request c
Create Pull Request action will:
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.
## Usage
@ -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.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
@ -26,30 +26,39 @@ Linux
Multi platform - Linux, MacOS, Windows (beta)
```yml
- name: Create Pull Request
uses: peter-evans/create-pull-request@v1.4.0-multi
uses: peter-evans/create-pull-request@v1.5.1-multi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
**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.
These variables are *all optional*. If not set, sensible default values will be used.
- `COMMIT_MESSAGE` - The message to use when committing changes.
- `PULL_REQUEST_TITLE` - The title of the pull request.
- `PULL_REQUEST_BODY` - The body of the pull request.
- `PULL_REQUEST_LABELS` - A comma separated list of labels.
- `PULL_REQUEST_ASSIGNEES` - A comma separated list of assignees (GitHub usernames).
- `PULL_REQUEST_REVIEWERS` - A comma separated list of reviewers (GitHub usernames) to request a review from.
- `PULL_REQUEST_TEAM_REVIEWERS` - A comma separated list of GitHub teams to request a review from.
- `PULL_REQUEST_MILESTONE` - The number of the milestone to associate this pull request with.
- `PULL_REQUEST_BRANCH` - The branch name. See **Branch naming** below for details.
- `BRANCH_SUFFIX` - The branch suffix type. Valid values are `short-commit-hash` (default), `timestamp`, `random` and `none`. See **Branch naming** below for details.
| Name | Description | Default |
| --- | --- | --- |
| `COMMIT_MESSAGE` | The message to use when committing changes. | `Auto-committed changes by create-pull-request action` |
| `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. |
| `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_TITLE` | The title of the pull request. | `Auto-generated by create-pull-request action` |
| `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_LABELS` | A comma separated list of labels. | none |
| `PULL_REQUEST_ASSIGNEES` | A comma separated list of assignees (GitHub usernames). | none |
| `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` |
| `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.
**Debug environment variables**
The following parameters are available for debugging and troubleshooting.
- `DEBUG_EVENT` - If present, outputs the event data that triggered the workflow.
@ -78,7 +87,7 @@ 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.
## Example
## Examples
Here is an example that sets all the main environment variables.
@ -95,14 +104,16 @@ 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.1
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
@ -115,7 +126,42 @@ jobs:
This configuration will create pull requests that look like this:
![Pull Request Example](pull-request-example.png?raw=true)
![Pull Request Example](https://github.com/peter-evans/create-pull-request/blob/master/pull-request-example.png?raw=true)
### 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.1
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.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
## License

View File

@ -23,7 +23,7 @@ def ignore_event(event_name, event_data):
if event_name == "push":
# Ignore push events on deleted branches
# 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
# the same commit.
deleted = "{deleted}".format(**event_data)
@ -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)
@ -68,7 +68,9 @@ def set_git_config(git, email, name):
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):
@ -77,7 +79,7 @@ def checkout_branch(git, remote_exists, branch):
git.checkout(branch)
try:
git.stash('pop')
except:
except BaseException:
git.checkout('--theirs', '.')
git.reset()
else:
@ -140,7 +142,9 @@ def process_event(event_name, event_data, repo, branch, base, remote_exists):
base=base,
head=branch)
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
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
if pull_request_reviewers is not None:
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:
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
@ -174,8 +180,15 @@ if skip_ignore_event or not ignore_event(event_name, event_data):
# Fetch/Set the branch name
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/'):
base = os.environ['GITHUB_HEAD_REF']
# Reset to the merging branch instead of the merge commit
repo.git.checkout(base)
else:
base = github_ref[11:]
# Skip if the current branch is a PR branch created by this action
if base.startswith(branch):
@ -197,14 +210,19 @@ if skip_ignore_event or not ignore_event(event_name, event_data):
# Check if the remote branch exists
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
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()
# Get the HEAD committer's email and name
author_email, author_name = get_head_author(event_name, event_data)
# 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
@ -213,6 +231,12 @@ if skip_ignore_event or not ignore_event(event_name, event_data):
# 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.")
process_event(event_name, event_data, repo, branch, base, remote_exists)
process_event(
event_name,
event_data,
repo,
branch,
base,
remote_exists)
else:
print("Repository has no modified or untracked files. Skipping.")

View File

@ -1,2 +1,2 @@
GitPython==3.0.2
GitPython==3.0.3
PyGithub==1.43.8