From fbe0cd3d1afa961be8910d1a2122724c6edbb3d1 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Sun, 6 Oct 2019 14:59:45 +0900 Subject: [PATCH 1/5] Update README --- README.md | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 5c8a79c..0e649d1 100644 --- a/README.md +++ b/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: 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.5.0 + uses: peter-evans/create-pull-request@v1.5.1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ``` @@ -26,7 +26,7 @@ Linux Multi platform - Linux, MacOS, Windows (beta) ```yml - name: Create Pull Request - uses: peter-evans/create-pull-request@v1.5.0-multi + uses: peter-evans/create-pull-request@v1.5.1-multi env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ``` @@ -36,18 +36,22 @@ See [this issue](https://github.com/peter-evans/create-pull-request/issues/48) f ### 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, defaults to the HEAD commit author. Otherwise, @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, defaults to the HEAD commit author. Otherwise, , 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 @@ -98,7 +102,7 @@ jobs: - name: Create report file run: date +%s > report.txt - name: Create Pull Request - uses: peter-evans/create-pull-request@v1.5.0 + uses: peter-evans/create-pull-request@v1.5.1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} COMMIT_MESSAGE: Add report file @@ -134,7 +138,7 @@ The recommended method is to use `set-output`. Note that the step where output v 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 + uses: peter-evans/create-pull-request@v1.5.1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} PULL_REQUEST_TITLE: ${{ steps.vars.outputs.pr_title }} @@ -150,7 +154,7 @@ Since the action reads environment variables from the system, it's technically n 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 + uses: peter-evans/create-pull-request@v1.5.1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ``` From b2d426ea4e62990783b36bc12b36781e5943b1b9 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Sun, 6 Oct 2019 15:06:49 +0900 Subject: [PATCH 2/5] Update README --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0e649d1..3f897b8 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,8 @@ These variables are *all optional*. If not set, sensible default values will be | 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, defaults to the HEAD commit author. Otherwise, @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, defaults to the HEAD commit author. Otherwise, , the GitHub user that initiated the event. | +| `COMMIT_AUTHOR_EMAIL` | The email address of the commit author. | For `push` events, the HEAD commit author. Otherwise, @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, , 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` | @@ -53,10 +53,12 @@ These variables are *all optional*. If not set, sensible default values will be | `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. @@ -106,6 +108,8 @@ 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 From 3c86dbf9e60640ac50676008b4beac75cd572e9d Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Sun, 6 Oct 2019 15:13:32 +0900 Subject: [PATCH 3/5] Update README --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3f897b8..425058d 100644 --- a/README.md +++ b/README.md @@ -45,11 +45,11 @@ These variables are *all optional*. If not set, sensible default values will be | `COMMIT_AUTHOR_NAME` | The name of the commit author. | For `push` events, the HEAD commit author. Otherwise, , 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_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` | From 51ade9f54beafcd51569665987714b0bb9f3a952 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Mon, 14 Oct 2019 01:39:53 +0900 Subject: [PATCH 4/5] Fix for pull refs --- create-pull-request.py | 43 +++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/create-pull-request.py b/create-pull-request.py index e5c0c33..5035fac 100755 --- a/create-pull-request.py +++ b/create-pull-request.py @@ -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) @@ -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,10 +210,12 @@ 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 default for author email and name @@ -216,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.") From f3b1bd6331542dc6827a6389240940ee18c300a3 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Mon, 14 Oct 2019 01:58:42 +0900 Subject: [PATCH 5/5] Update image version --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 8a6dbf5..2b277ed 100644 --- a/action.yml +++ b/action.yml @@ -3,7 +3,7 @@ author: 'Peter Evans' description: 'Creates a pull request for changes to your repository in the actions workspace' runs: using: 'docker' - image: 'docker://peterevans/create-pull-request:1.5.1' + image: 'docker://peterevans/create-pull-request:1.5.2' branding: icon: 'git-pull-request' color: 'gray-dark'