Add input for draft pull requests

This commit is contained in:
Peter Evans 2020-04-04 09:47:11 +09:00
parent 3474dda921
commit abc19caa82
8 changed files with 70 additions and 21 deletions

View file

@ -4,6 +4,20 @@ from github import Github, GithubException
import os
def string_to_bool(str):
if str is None:
return False
else:
return str.lower() in [
"true",
"1",
"t",
"y",
"yes",
"on",
]
def cs_string_to_list(str):
# Split the comma separated string into a list
l = [i.strip() for i in str.split(",")]
@ -56,27 +70,31 @@ def create_or_update_pull_request(
team_reviewers,
project_name,
project_column_name,
draft,
request_to_parent,
):
if request_to_parent is None:
request_to_parent = False
else:
request_to_parent = request_to_parent.lower() in ['true', '1', 't', 'y', 'yes', 'on']
github_repo = head_repo = Github(github_token).get_repo(github_repository)
if request_to_parent:
if string_to_bool(request_to_parent):
github_repo = github_repo.parent
if github_repo is None:
raise ValueError("The checked out repository is not a fork. Input 'request-to-parent' should be set to false.")
raise ValueError(
"The checked out repository is not a fork. Input 'request-to-parent' should be set to false."
)
head_branch = f"{head_repo.owner.login}:{branch}"
# Create the pull request
try:
pull_request = github_repo.create_pull(
title=title, body=body, base=base, head=head_branch
title=title,
body=body,
base=base,
head=head_branch,
draft=string_to_bool(draft),
)
print(
f"Created pull request #{pull_request.number} ({head_branch} => {github_repo.owner.login}:{base})"
)
print(f"Created pull request #{pull_request.number} ({head_branch} => {github_repo.owner.login}:{base})")
except GithubException as e:
if e.status == 422:
# A pull request exists for this branch and base
@ -86,7 +104,9 @@ def create_or_update_pull_request(
)[0]
# Update title and body
pull_request.as_issue().edit(title=title, body=body)
print(f"Updated pull request #{pull_request.number} ({head_branch} => {github_repo.owner.login}:{base})")
print(
f"Updated pull request #{pull_request.number} ({head_branch} => {github_repo.owner.login}:{base})"
)
else:
print(str(e))
raise

View file

@ -224,5 +224,6 @@ if result["action"] in ["created", "updated"]:
os.environ.get("CPR_TEAM_REVIEWERS"),
os.environ.get("CPR_PROJECT_NAME"),
os.environ.get("CPR_PROJECT_COLUMN_NAME"),
os.environ.get("CPR_DRAFT"),
os.environ.get("CPR_REQUEST_TO_PARENT"),
)

2
dist/index.js vendored
View file

@ -4274,6 +4274,7 @@ async function run() {
milestone: core.getInput("milestone"),
project: core.getInput("project"),
projectColumn: core.getInput("project-column"),
draft: core.getInput("draft"),
branch: core.getInput("branch"),
request_to_parent: core.getInput("request-to-parent"),
base: core.getInput("base"),
@ -4296,6 +4297,7 @@ async function run() {
if (inputs.milestone) process.env.CPR_MILESTONE = inputs.milestone;
if (inputs.project) process.env.CPR_PROJECT_NAME = inputs.project;
if (inputs.projectColumn) process.env.CPR_PROJECT_COLUMN_NAME = inputs.projectColumn;
if (inputs.draft) process.env.CPR_DRAFT = inputs.draft;
if (inputs.branch) process.env.CPR_BRANCH = inputs.branch;
if (inputs.request_to_parent) process.env.CPR_REQUEST_TO_PARENT = inputs.request_to_parent;
if (inputs.base) process.env.CPR_BASE = inputs.base;