Compare commits

...

12 Commits

Author SHA1 Message Date
04bf3d439a Update Python to version 3.8.1 2020-01-17 16:03:01 +09:00
ec6352b0a0 Merge pull request #85 from peter-evans/dev
Minor refactor to set url via git params
2019-12-08 16:30:10 +09:00
ce4df54075 Bump version 2019-12-08 16:28:43 +09:00
c855a500d1 Add clean slash command 2019-12-08 15:36:00 +09:00
baf52378ae Minor refactor to set url via git params 2019-12-08 15:02:54 +09:00
e6ebd7ca5c Merge pull request #83 from peter-evans/dev
Add inputs for committer-name and committer-email
2019-12-06 19:17:09 +09:00
83fef4e8a1 Update README 2019-12-06 18:36:27 +09:00
d3dc225920 Add inputs for committer-name and committer-email 2019-12-06 17:06:49 +09:00
6342438c4e Updated README 2019-12-05 18:28:50 +09:00
324fe6cdde Add slash command dispatch workflow 2019-12-03 19:50:15 +09:00
4faa5d5a97 Update README 2019-11-24 09:28:14 +09:00
381bc30cef Update example screenshot 2019-11-24 09:14:05 +09:00
10 changed files with 1572 additions and 505 deletions

View File

@ -0,0 +1,16 @@
name: Slash Command Dispatch
on:
issue_comment:
types: [created]
jobs:
slashCommandDispatch:
runs-on: ubuntu-latest
steps:
- name: Slash Command Dispatch
uses: peter-evans/slash-command-dispatch@v1
with:
token: ${{ secrets.REPO_ACCESS_TOKEN }}
reaction-token: ${{ secrets.GITHUB_TOKEN }}
commands: test, clean
permission: admin
repository: peter-evans/create-pull-request-tests

View File

@ -36,17 +36,19 @@ These inputs are *all optional*. If not set, sensible default values will be use
| Name | Description | Default |
| --- | --- | --- |
| `commit-message` | The message to use when committing changes. | `Auto-committed changes by create-pull-request action` |
| `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. |
| `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. |
| `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. |
| `committer-name` | The name of the committer. | Defaults to match `author-name` |
| `committer-email` | The email address of the committer. | Defaults to match `author-email` |
| `title` | The title of the pull request. | `Auto-generated by create-pull-request action` |
| `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` |
| `labels` | A comma separated list of labels. | none |
| `assignees` | A comma separated list of assignees (GitHub usernames). | none |
| `reviewers` | A comma separated list of reviewers (GitHub usernames) to request a review from. | none |
| `team-reviewers` | A comma separated list of GitHub teams to request a review from. | none |
| `milestone` | The number of the milestone to associate this pull request with. | none |
| `project` | The name of the project for which a card should be created. Requires `project-column`. | none |
| `project-column` | The name of the project column under which a card should be created. Requires `project`. | none |
| `labels` | A comma separated list of labels. | |
| `assignees` | A comma separated list of assignees (GitHub usernames). | |
| `reviewers` | A comma separated list of reviewers (GitHub usernames) to request a review from. | |
| `team-reviewers` | A comma separated list of GitHub teams to request a review from. | |
| `milestone` | The number of the milestone to associate this pull request with. | |
| `project` | The name of the project for which a card should be created. Requires `project-column`. | |
| `project-column` | The name of the project column under which a card should be created. Requires `project`. | |
| `branch` | The branch name. See **Branch naming** below for details. | `create-pull-request/patch` |
| `base` | Sets the pull request base branch. | Defaults to the currently checked out branch, `GITHUB_REF`. For `pull_request` events, `GITHUB_HEAD_REF` |
| `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` |
@ -85,12 +87,27 @@ The branch name is defined by the input `branch` and defaults to `create-pull-re
#### Strategy B - Create and update a pull request branch
To use this strategy, set `branch-suffix` to the value `none`. The input `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.
To use this strategy, set `branch-suffix` to the value `none`. The input `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 open pull request. If the pull request is merged or closed a new one will be created.
### 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.
### Commit as github-actions[bot]
You can make commits that appear to be made by the GitHub Actions bot as follows.
```yml
- name: Create Pull Request
uses: peter-evans/create-pull-request@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
author-name: github-actions[bot]
author-email: 41898282+github-actions[bot]@users.noreply.github.com
committer-name: GitHub
committer-email: noreply@github.com
```
## Reference Example
The following workflow is a reference example that sets all the main inputs.

View File

@ -6,10 +6,14 @@ inputs:
required: true
commit-message:
description: 'The message to use when committing changes.'
author-email:
description: 'The email address of the commit author.'
author-name:
description: 'The name of the commit author.'
author-email:
description: 'The email address of the commit author.'
committer-name:
description: 'The name of the committer.'
committer-email:
description: 'The email address of the committer.'
title:
description: 'The title of the pull request.'
body:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 441 KiB

After

Width:  |  Height:  |  Size: 417 KiB

1908
dist/index.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -44,18 +44,8 @@ def get_author_default(event_name, event_data):
return email, name
def set_git_config(git, email, name):
print("Configuring git user as '%s <%s>'" % (name, email))
git.config("--global", "user.email", '"%s"' % email)
git.config("--global", "user.name", '"%s"' % 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),
)
def get_repo_url(token, github_repository):
return "https://x-access-token:%s@github.com/%s" % (token, github_repository)
def checkout_branch(git, remote_exists, branch):
@ -73,10 +63,11 @@ def checkout_branch(git, remote_exists, branch):
git.checkout("HEAD", b=branch)
def push_changes(git, branch, commit_message):
def push_changes(git, token, github_repository, branch, commit_message):
git.add("-A")
git.commit(m=commit_message)
return git.push("-f", "--set-upstream", "origin", branch)
repo_url = get_repo_url(token, github_repository)
return git.push("-f", repo_url, f"HEAD:refs/heads/{branch}")
def cs_string_to_list(str):
@ -141,7 +132,9 @@ def process_event(github_token, github_repository, repo, branch, base):
# Push the local changes to the remote branch
print("Pushing changes to 'origin/%s'" % branch)
push_result = push_changes(repo.git, branch, commit_message)
push_result = push_changes(
repo.git, github_token, github_repository, branch, commit_message
)
print(push_result)
# Create the pull request
@ -229,17 +222,26 @@ event_name = os.environ["GITHUB_EVENT_NAME"]
# Get the JSON event data
event_data = get_github_event(os.environ["GITHUB_EVENT_PATH"])
# Set the repo to the working directory
repo = Repo(os.getcwd())
# 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)
# Set author name and email overrides
author_name = os.getenv("COMMIT_AUTHOR_NAME", author_name)
# 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)
author_email = os.getenv("COMMIT_AUTHOR_EMAIL", author_email)
# Set committer name and email overrides
committer_name = os.getenv("COMMITTER_NAME", author_name)
committer_email = os.getenv("COMMITTER_EMAIL", author_email)
# Set the repo to the working directory
repo = Repo(os.getcwd())
# Set git environment. This will not persist after the action completes.
print("Configuring git author as '%s <%s>'" % (author_name, author_email))
print("Configuring git committer as '%s <%s>'" % (committer_name, committer_email))
repo.git.update_environment(
GIT_AUTHOR_NAME=author_name,
GIT_AUTHOR_EMAIL=author_email,
GIT_COMMITTER_NAME=committer_name,
GIT_COMMITTER_EMAIL=committer_email,
)
# Fetch/Set the branch name
branch_prefix = os.getenv("PULL_REQUEST_BRANCH", "create-pull-request/patch")

View File

@ -10,7 +10,7 @@ async function run() {
core.debug(`src: ${src}`);
// Setup Python from the tool cache
setupPython("3.8.0", "x64");
setupPython("3.8.1", "x64");
// Install requirements
await exec.exec("pip", [
@ -23,8 +23,10 @@ async function run() {
const inputs = {
token: core.getInput("token"),
commitMessage: core.getInput("commit-message"),
commitAuthorEmail: core.getInput("author-email"),
commitAuthorName: core.getInput("author-name"),
commitAuthorEmail: core.getInput("author-email"),
committerName: core.getInput("committer-name"),
committerEmail: core.getInput("committer-email"),
title: core.getInput("title"),
body: core.getInput("body"),
labels: core.getInput("labels"),
@ -44,8 +46,10 @@ async function run() {
// Set environment variables from inputs.
if (inputs.token) process.env.GITHUB_TOKEN = inputs.token;
if (inputs.commitMessage) process.env.COMMIT_MESSAGE = inputs.commitMessage;
if (inputs.commitAuthorEmail) process.env.COMMIT_AUTHOR_EMAIL = inputs.commitAuthorEmail;
if (inputs.commitAuthorName) process.env.COMMIT_AUTHOR_NAME = inputs.commitAuthorName;
if (inputs.commitAuthorEmail) process.env.COMMIT_AUTHOR_EMAIL = inputs.commitAuthorEmail;
if (inputs.committerName) process.env.COMMITTER_NAME = inputs.committerName;
if (inputs.committerEmail) process.env.COMMITTER_EMAIL = inputs.committerEmail;
if (inputs.title) process.env.PULL_REQUEST_TITLE = inputs.title;
if (inputs.body) process.env.PULL_REQUEST_BODY = inputs.body;
if (inputs.labels) process.env.PULL_REQUEST_LABELS = inputs.labels;

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "create-pull-request",
"version": "1.7.0",
"version": "1.8.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "create-pull-request",
"version": "1.8.0",
"version": "1.9.1",
"description": "Creates a pull request for changes to your repository in the actions workspace",
"main": "index.js",
"scripts": {

View File

@ -44,18 +44,8 @@ def get_author_default(event_name, event_data):
return email, name
def set_git_config(git, email, name):
print("Configuring git user as '%s <%s>'" % (name, email))
git.config("--global", "user.email", '"%s"' % email)
git.config("--global", "user.name", '"%s"' % 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),
)
def get_repo_url(token, github_repository):
return "https://x-access-token:%s@github.com/%s" % (token, github_repository)
def checkout_branch(git, remote_exists, branch):
@ -73,10 +63,11 @@ def checkout_branch(git, remote_exists, branch):
git.checkout("HEAD", b=branch)
def push_changes(git, branch, commit_message):
def push_changes(git, token, github_repository, branch, commit_message):
git.add("-A")
git.commit(m=commit_message)
return git.push("-f", "--set-upstream", "origin", branch)
repo_url = get_repo_url(token, github_repository)
return git.push("-f", repo_url, f"HEAD:refs/heads/{branch}")
def cs_string_to_list(str):
@ -141,7 +132,9 @@ def process_event(github_token, github_repository, repo, branch, base):
# Push the local changes to the remote branch
print("Pushing changes to 'origin/%s'" % branch)
push_result = push_changes(repo.git, branch, commit_message)
push_result = push_changes(
repo.git, github_token, github_repository, branch, commit_message
)
print(push_result)
# Create the pull request
@ -229,17 +222,26 @@ event_name = os.environ["GITHUB_EVENT_NAME"]
# Get the JSON event data
event_data = get_github_event(os.environ["GITHUB_EVENT_PATH"])
# Set the repo to the working directory
repo = Repo(os.getcwd())
# 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)
# Set author name and email overrides
author_name = os.getenv("COMMIT_AUTHOR_NAME", author_name)
# 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)
author_email = os.getenv("COMMIT_AUTHOR_EMAIL", author_email)
# Set committer name and email overrides
committer_name = os.getenv("COMMITTER_NAME", author_name)
committer_email = os.getenv("COMMITTER_EMAIL", author_email)
# Set the repo to the working directory
repo = Repo(os.getcwd())
# Set git environment. This will not persist after the action completes.
print("Configuring git author as '%s <%s>'" % (author_name, author_email))
print("Configuring git committer as '%s <%s>'" % (committer_name, committer_email))
repo.git.update_environment(
GIT_AUTHOR_NAME=author_name,
GIT_AUTHOR_EMAIL=author_email,
GIT_COMMITTER_NAME=committer_name,
GIT_COMMITTER_EMAIL=committer_email,
)
# Fetch/Set the branch name
branch_prefix = os.getenv("PULL_REQUEST_BRANCH", "create-pull-request/patch")