Merge pull request #46 from peter-evans/issue-params

Issue params
This commit is contained in:
Peter Evans 2019-09-26 17:54:10 +09:00 committed by GitHub
commit ae3acffc2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 23 deletions

View file

@ -1,7 +1,7 @@
on: on:
repository_dispatch: repository_dispatch:
types: [create-pull-request-multi] types: [create-pull-request-multi]
name: create-pull-request action testing workflow name: create-pull-request workflow
jobs: jobs:
createPullRequest: createPullRequest:
name: Testing on ${{ matrix.platform }} name: Testing on ${{ matrix.platform }}
@ -10,7 +10,7 @@ jobs:
platform: [ubuntu-latest, macos-latest, windows-latest] platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }} runs-on: ${{ matrix.platform }}
steps: steps:
- uses: actions/checkout@master - uses: actions/checkout@v1
- name: Create report file - name: Create report file
if: matrix.platform == 'ubuntu-latest' || matrix.platform == 'macos-latest' if: matrix.platform == 'ubuntu-latest' || matrix.platform == 'macos-latest'
run: touch report.txt run: touch report.txt
@ -23,6 +23,10 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_MESSAGE: Add report file COMMIT_MESSAGE: 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_BODY: This PR is auto-generated by [create-pull-request](https://github.com/peter-evans/create-pull-request).
PULL_REQUEST_BRANCH: test-patches PULL_REQUEST_TITLE: '[Example] Add report file'
PULL_REQUEST_TITLE: '[Test] Add report file' PULL_REQUEST_LABELS: report, automated pr
PULL_REQUEST_ASSIGNEES: peter-evans
PULL_REQUEST_REVIEWERS: peter-evans
PULL_REQUEST_MILESTONE: 1
PULL_REQUEST_BRANCH: example-patches
BRANCH_SUFFIX: 'timestamp' BRANCH_SUFFIX: 'timestamp'

View file

@ -1,12 +1,12 @@
on: on:
repository_dispatch: repository_dispatch:
types: [create-pull-request] types: [create-pull-request]
name: create-pull-request action testing workflow name: create-pull-request workflow
jobs: jobs:
createPullRequest: createPullRequest:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@master - uses: actions/checkout@v1
- name: Create report file - name: Create report file
run: touch report.txt run: touch report.txt
- name: Create Pull Request - name: Create Pull Request
@ -15,5 +15,10 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_MESSAGE: Add report file COMMIT_MESSAGE: 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_BODY: This PR is auto-generated by [create-pull-request](https://github.com/peter-evans/create-pull-request).
PULL_REQUEST_BRANCH: test-patches PULL_REQUEST_TITLE: '[Example] Add report file'
PULL_REQUEST_TITLE: '[Test] Add report file' PULL_REQUEST_LABELS: report, automated pr
PULL_REQUEST_ASSIGNEES: peter-evans
PULL_REQUEST_REVIEWERS: peter-evans
PULL_REQUEST_MILESTONE: 1
PULL_REQUEST_BRANCH: example-patches
BRANCH_SUFFIX: short-commit-hash

View file

@ -71,19 +71,18 @@ def commit_changes(git, branch, commit_message):
return git.push('--set-upstream', 'origin', branch) return git.push('--set-upstream', 'origin', branch)
def create_pull_request(token, repo, head, base, title, body): def cs_string_to_list(str):
return Github(token).get_repo(repo).create_pull( # Split the comma separated string into a list
title=title, l = [i.strip() for i in str.split(',')]
body=body, # Remove empty strings
base=base, return list(filter(None, l))
head=head)
def process_event(event_name, event_data, repo, branch, base): def process_event(event_name, event_data, repo, branch, base):
# Fetch required environment variables # Fetch required environment variables
github_token = os.environ['GITHUB_TOKEN'] github_token = os.environ['GITHUB_TOKEN']
github_repository = os.environ['GITHUB_REPOSITORY'] github_repository = os.environ['GITHUB_REPOSITORY']
# Fetch remaining optional environment variables # Fetch optional environment variables with default values
commit_message = os.getenv( commit_message = os.getenv(
'COMMIT_MESSAGE', 'COMMIT_MESSAGE',
"Auto-committed changes by create-pull-request action") "Auto-committed changes by create-pull-request action")
@ -93,6 +92,12 @@ def process_event(event_name, event_data, repo, branch, base):
body = os.getenv( body = os.getenv(
'PULL_REQUEST_BODY', "Auto-generated pull request by " 'PULL_REQUEST_BODY', "Auto-generated pull request by "
"[create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub Action") "[create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub Action")
# Fetch optional environment variables with no default values
pull_request_labels = os.environ.get('PULL_REQUEST_LABELS')
pull_request_assignees = os.environ.get('PULL_REQUEST_ASSIGNEES')
pull_request_milestone = os.environ.get('PULL_REQUEST_MILESTONE')
pull_request_reviewers = os.environ.get('PULL_REQUEST_REVIEWERS')
pull_request_team_reviewers = os.environ.get('PULL_REQUEST_TEAM_REVIEWERS')
# Get the HEAD committer's email and name # Get the HEAD committer's email and name
author_email, author_name = get_head_author(event_name, event_data) author_email, author_name = get_head_author(event_name, event_data)
@ -108,16 +113,34 @@ def process_event(event_name, event_data, repo, branch, base):
# Create the pull request # Create the pull request
print("Creating a request to pull %s into %s." % (branch, base)) print("Creating a request to pull %s into %s." % (branch, base))
pull_request = create_pull_request( github_repo = Github(github_token).get_repo(github_repository)
github_token, pull_request = github_repo.create_pull(
github_repository, title=title,
branch, body=body,
base, base=base,
title, head=branch)
body
)
print("Created pull request %d." % pull_request.number) print("Created pull request %d." % pull_request.number)
# Set labels, assignees and milestone
if pull_request_labels is not None:
print("Applying labels")
pull_request.as_issue().edit(labels=cs_string_to_list(pull_request_labels))
if pull_request_assignees is not None:
print("Applying assignees")
pull_request.as_issue().edit(assignees=cs_string_to_list(pull_request_assignees))
if pull_request_milestone is not None:
print("Applying milestone")
milestone = github_repo.get_milestone(int(pull_request_milestone))
pull_request.as_issue().edit(milestone=milestone)
# 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))
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))
# Get the JSON event data # Get the JSON event data
event_name = os.environ['GITHUB_EVENT_NAME'] event_name = os.environ['GITHUB_EVENT_NAME']