Merge branch 'master' into multi-platform

This commit is contained in:
Peter Evans 2019-10-02 19:26:54 +09:00
commit c1363c2fed
4 changed files with 43 additions and 31 deletions

View file

@ -1,4 +1,4 @@
# Create Pull Request # <img width="24" height="24" src="logo.svg"> Create Pull Request
[![GitHub Marketplace](https://img.shields.io/badge/Marketplace-Create%20Pull%20Request-blue.svg?colorA=24292e&colorB=0366d6&style=flat&longCache=true&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAM6wAADOsB5dZE0gAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAERSURBVCiRhZG/SsMxFEZPfsVJ61jbxaF0cRQRcRJ9hlYn30IHN/+9iquDCOIsblIrOjqKgy5aKoJQj4O3EEtbPwhJbr6Te28CmdSKeqzeqr0YbfVIrTBKakvtOl5dtTkK+v4HfA9PEyBFCY9AGVgCBLaBp1jPAyfAJ/AAdIEG0dNAiyP7+K1qIfMdonZic6+WJoBJvQlvuwDqcXadUuqPA1NKAlexbRTAIMvMOCjTbMwl1LtI/6KWJ5Q6rT6Ht1MA58AX8Apcqqt5r2qhrgAXQC3CZ6i1+KMd9TRu3MvA3aH/fFPnBodb6oe6HM8+lYHrGdRXW8M9bMZtPXUji69lmf5Cmamq7quNLFZXD9Rq7v0Bpc1o/tp0fisAAAAASUVORK5CYII=)](https://github.com/marketplace/actions/create-pull-request) [![GitHub Marketplace](https://img.shields.io/badge/Marketplace-Create%20Pull%20Request-blue.svg?colorA=24292e&colorB=0366d6&style=flat&longCache=true&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAM6wAADOsB5dZE0gAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAERSURBVCiRhZG/SsMxFEZPfsVJ61jbxaF0cRQRcRJ9hlYn30IHN/+9iquDCOIsblIrOjqKgy5aKoJQj4O3EEtbPwhJbr6Te28CmdSKeqzeqr0YbfVIrTBKakvtOl5dtTkK+v4HfA9PEyBFCY9AGVgCBLaBp1jPAyfAJ/AAdIEG0dNAiyP7+K1qIfMdonZic6+WJoBJvQlvuwDqcXadUuqPA1NKAlexbRTAIMvMOCjTbMwl1LtI/6KWJ5Q6rT6Ht1MA58AX8Apcqqt5r2qhrgAXQC3CZ6i1+KMd9TRu3MvA3aH/fFPnBodb6oe6HM8+lYHrGdRXW8M9bMZtPXUji69lmf5Cmamq7quNLFZXD9Rq7v0Bpc1o/tp0fisAAAAASUVORK5CYII=)](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. A GitHub action to create a pull request for changes to your repository in the actions workspace.
@ -26,12 +26,12 @@ 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.3.1-multi uses: peter-evans/create-pull-request@v1.4.0-multi
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
``` ```
#### 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, a default value will be used.
@ -55,35 +55,26 @@ 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.
- `SKIP_IGNORE` - If present, the `ignore_event` function will be skipped. - `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. 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. - `timestamp` - Commits will be made to a branch suffixed by a timestamp. e.g. `create-pull-request/patch-1569322532`, `create-pull-request/patch-1569322552`
eg. `create-pull-request/patch-fcdfb59`, `create-pull-request/patch-394710b`
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. #### Strategy B - Create and update a pull request branch
eg. `create-pull-request/patch-1569322532`, `create-pull-request/patch-1569322552`
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. ### Ignoring files
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
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.

View file

@ -1,5 +1,9 @@
name: 'Create Pull Request' name: 'Create Pull Request'
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: 'node12' using: 'node12'
main: 'index.js' main: 'index.js'
branding:
icon: 'git-pull-request'
color: 'gray-dark'

View file

@ -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)) 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): def checkout_branch(git, remote_exists, branch):
git.add('-A')
git.commit(m=commit_message)
if remote_exists: if remote_exists:
git.stash('--include-untracked')
git.checkout(branch) git.checkout(branch)
git.rebase('-Xtheirs', '-') try:
git.stash('pop')
except:
git.checkout('--theirs', '.')
git.reset()
else: else:
git.checkout('HEAD', b=branch) 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) 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_reviewers = os.environ.get('PULL_REQUEST_REVIEWERS')
pull_request_team_reviewers = os.environ.get('PULL_REQUEST_TEAM_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 # Update URL for the 'origin' remote
set_git_remote_url(repo.git, github_token, github_repository) set_git_remote_url(repo.git, github_token, github_repository)
# Push the local changes to the remote branch # Push the local changes to the remote branch
print("Pushing changes.") 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) print(push_result)
# If the remote existed then a PR likely exists and we can finish here # If the remote existed then a PR likely exists and we can finish here
@ -199,6 +203,13 @@ if skip_ignore_event or not ignore_event(event_name, event_data):
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
author_email, author_name = get_head_author(event_name, event_data)
# 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 # 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.")

6
logo.svg Normal file
View 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