Add input for draft pull requests
This commit is contained in:
parent
3474dda921
commit
abc19caa82
8 changed files with 70 additions and 21 deletions
1
.github/workflows/cpr-example-command.yml
vendored
1
.github/workflows/cpr-example-command.yml
vendored
|
@ -28,6 +28,7 @@ jobs:
|
||||||
milestone: 1
|
milestone: 1
|
||||||
project: Example Project
|
project: Example Project
|
||||||
project-column: To do
|
project-column: To do
|
||||||
|
draft: false
|
||||||
branch: example-patches
|
branch: example-patches
|
||||||
request-to-parent: false
|
request-to-parent: false
|
||||||
- name: Check outputs
|
- name: Check outputs
|
||||||
|
|
|
@ -53,6 +53,7 @@ All inputs are **optional**. If not set, sensible default values will be used.
|
||||||
| `milestone` | The number of the milestone to associate this pull request with. | |
|
| `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` | 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`. | |
|
| `project-column` | The name of the project column under which a card should be created. Requires `project`. | |
|
||||||
|
| `draft` | Create a [draft pull request](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests#draft-pull-requests). | `false` |
|
||||||
| `branch` | The branch name. See [Branch naming](#branch-naming) for details. | `create-pull-request/patch` |
|
| `branch` | The branch name. See [Branch naming](#branch-naming) for details. | `create-pull-request/patch` |
|
||||||
| `request-to-parent` | Create the pull request in the parent repository of the checked out fork. See [push pull request branches to a fork](https://github.com/peter-evans/create-pull-request/blob/master/docs/concepts-guidelines.md#push-pull-request-branches-to-a-fork) for details. | `false` |
|
| `request-to-parent` | Create the pull request in the parent repository of the checked out fork. See [push pull request branches to a fork](https://github.com/peter-evans/create-pull-request/blob/master/docs/concepts-guidelines.md#push-pull-request-branches-to-a-fork) for details. | `false` |
|
||||||
| `base` | Sets the pull request base branch. | Defaults to the branch checked out in the workflow. |
|
| `base` | Sets the pull request base branch. | Defaults to the branch checked out in the workflow. |
|
||||||
|
@ -179,6 +180,7 @@ jobs:
|
||||||
milestone: 1
|
milestone: 1
|
||||||
project: Example Project
|
project: Example Project
|
||||||
project-column: To do
|
project-column: To do
|
||||||
|
draft: false
|
||||||
branch: example-patches
|
branch: example-patches
|
||||||
request-to-parent: false
|
request-to-parent: false
|
||||||
- name: Check outputs
|
- name: Check outputs
|
||||||
|
|
40
dist/cpr/create_or_update_pull_request.py
vendored
40
dist/cpr/create_or_update_pull_request.py
vendored
|
@ -4,6 +4,20 @@ from github import Github, GithubException
|
||||||
import os
|
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):
|
def cs_string_to_list(str):
|
||||||
# Split the comma separated string into a list
|
# Split the comma separated string into a list
|
||||||
l = [i.strip() for i in str.split(",")]
|
l = [i.strip() for i in str.split(",")]
|
||||||
|
@ -56,27 +70,31 @@ def create_or_update_pull_request(
|
||||||
team_reviewers,
|
team_reviewers,
|
||||||
project_name,
|
project_name,
|
||||||
project_column_name,
|
project_column_name,
|
||||||
|
draft,
|
||||||
request_to_parent,
|
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)
|
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
|
github_repo = github_repo.parent
|
||||||
if github_repo is None:
|
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}"
|
head_branch = f"{head_repo.owner.login}:{branch}"
|
||||||
|
|
||||||
# Create the pull request
|
# Create the pull request
|
||||||
try:
|
try:
|
||||||
pull_request = github_repo.create_pull(
|
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:
|
except GithubException as e:
|
||||||
if e.status == 422:
|
if e.status == 422:
|
||||||
# A pull request exists for this branch and base
|
# A pull request exists for this branch and base
|
||||||
|
@ -86,7 +104,9 @@ def create_or_update_pull_request(
|
||||||
)[0]
|
)[0]
|
||||||
# Update title and body
|
# Update title and body
|
||||||
pull_request.as_issue().edit(title=title, body=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:
|
else:
|
||||||
print(str(e))
|
print(str(e))
|
||||||
raise
|
raise
|
||||||
|
|
1
dist/cpr/create_pull_request.py
vendored
1
dist/cpr/create_pull_request.py
vendored
|
@ -224,5 +224,6 @@ if result["action"] in ["created", "updated"]:
|
||||||
os.environ.get("CPR_TEAM_REVIEWERS"),
|
os.environ.get("CPR_TEAM_REVIEWERS"),
|
||||||
os.environ.get("CPR_PROJECT_NAME"),
|
os.environ.get("CPR_PROJECT_NAME"),
|
||||||
os.environ.get("CPR_PROJECT_COLUMN_NAME"),
|
os.environ.get("CPR_PROJECT_COLUMN_NAME"),
|
||||||
|
os.environ.get("CPR_DRAFT"),
|
||||||
os.environ.get("CPR_REQUEST_TO_PARENT"),
|
os.environ.get("CPR_REQUEST_TO_PARENT"),
|
||||||
)
|
)
|
||||||
|
|
2
dist/index.js
vendored
2
dist/index.js
vendored
|
@ -4274,6 +4274,7 @@ async function run() {
|
||||||
milestone: core.getInput("milestone"),
|
milestone: core.getInput("milestone"),
|
||||||
project: core.getInput("project"),
|
project: core.getInput("project"),
|
||||||
projectColumn: core.getInput("project-column"),
|
projectColumn: core.getInput("project-column"),
|
||||||
|
draft: core.getInput("draft"),
|
||||||
branch: core.getInput("branch"),
|
branch: core.getInput("branch"),
|
||||||
request_to_parent: core.getInput("request-to-parent"),
|
request_to_parent: core.getInput("request-to-parent"),
|
||||||
base: core.getInput("base"),
|
base: core.getInput("base"),
|
||||||
|
@ -4296,6 +4297,7 @@ async function run() {
|
||||||
if (inputs.milestone) process.env.CPR_MILESTONE = inputs.milestone;
|
if (inputs.milestone) process.env.CPR_MILESTONE = inputs.milestone;
|
||||||
if (inputs.project) process.env.CPR_PROJECT_NAME = inputs.project;
|
if (inputs.project) process.env.CPR_PROJECT_NAME = inputs.project;
|
||||||
if (inputs.projectColumn) process.env.CPR_PROJECT_COLUMN_NAME = inputs.projectColumn;
|
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.branch) process.env.CPR_BRANCH = inputs.branch;
|
||||||
if (inputs.request_to_parent) process.env.CPR_REQUEST_TO_PARENT = inputs.request_to_parent;
|
if (inputs.request_to_parent) process.env.CPR_REQUEST_TO_PARENT = inputs.request_to_parent;
|
||||||
if (inputs.base) process.env.CPR_BASE = inputs.base;
|
if (inputs.base) process.env.CPR_BASE = inputs.base;
|
||||||
|
|
|
@ -4,6 +4,20 @@ from github import Github, GithubException
|
||||||
import os
|
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):
|
def cs_string_to_list(str):
|
||||||
# Split the comma separated string into a list
|
# Split the comma separated string into a list
|
||||||
l = [i.strip() for i in str.split(",")]
|
l = [i.strip() for i in str.split(",")]
|
||||||
|
@ -56,27 +70,31 @@ def create_or_update_pull_request(
|
||||||
team_reviewers,
|
team_reviewers,
|
||||||
project_name,
|
project_name,
|
||||||
project_column_name,
|
project_column_name,
|
||||||
|
draft,
|
||||||
request_to_parent,
|
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)
|
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
|
github_repo = github_repo.parent
|
||||||
if github_repo is None:
|
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}"
|
head_branch = f"{head_repo.owner.login}:{branch}"
|
||||||
|
|
||||||
# Create the pull request
|
# Create the pull request
|
||||||
try:
|
try:
|
||||||
pull_request = github_repo.create_pull(
|
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:
|
except GithubException as e:
|
||||||
if e.status == 422:
|
if e.status == 422:
|
||||||
# A pull request exists for this branch and base
|
# A pull request exists for this branch and base
|
||||||
|
@ -86,7 +104,9 @@ def create_or_update_pull_request(
|
||||||
)[0]
|
)[0]
|
||||||
# Update title and body
|
# Update title and body
|
||||||
pull_request.as_issue().edit(title=title, body=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:
|
else:
|
||||||
print(str(e))
|
print(str(e))
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -192,7 +192,7 @@ result = coub.create_or_update_branch(repo, repo_url, commit_message, base, bran
|
||||||
|
|
||||||
if result["action"] in ["created", "updated"]:
|
if result["action"] in ["created", "updated"]:
|
||||||
# The branch was created or updated
|
# The branch was created or updated
|
||||||
print(f"Pushing pull request branch to '{repo.full_name}/{branch}'")
|
print(f"Pushing pull request branch to 'origin/{branch}'")
|
||||||
repo.git.push("--force", repo_url, f"HEAD:refs/heads/{branch}")
|
repo.git.push("--force", repo_url, f"HEAD:refs/heads/{branch}")
|
||||||
|
|
||||||
# Set the base. It would have been 'None' if not specified as an input
|
# Set the base. It would have been 'None' if not specified as an input
|
||||||
|
@ -224,5 +224,6 @@ if result["action"] in ["created", "updated"]:
|
||||||
os.environ.get("CPR_TEAM_REVIEWERS"),
|
os.environ.get("CPR_TEAM_REVIEWERS"),
|
||||||
os.environ.get("CPR_PROJECT_NAME"),
|
os.environ.get("CPR_PROJECT_NAME"),
|
||||||
os.environ.get("CPR_PROJECT_COLUMN_NAME"),
|
os.environ.get("CPR_PROJECT_COLUMN_NAME"),
|
||||||
|
os.environ.get("CPR_DRAFT"),
|
||||||
os.environ.get("CPR_REQUEST_TO_PARENT"),
|
os.environ.get("CPR_REQUEST_TO_PARENT"),
|
||||||
)
|
)
|
||||||
|
|
|
@ -62,6 +62,7 @@ async function run() {
|
||||||
milestone: core.getInput("milestone"),
|
milestone: core.getInput("milestone"),
|
||||||
project: core.getInput("project"),
|
project: core.getInput("project"),
|
||||||
projectColumn: core.getInput("project-column"),
|
projectColumn: core.getInput("project-column"),
|
||||||
|
draft: core.getInput("draft"),
|
||||||
branch: core.getInput("branch"),
|
branch: core.getInput("branch"),
|
||||||
request_to_parent: core.getInput("request-to-parent"),
|
request_to_parent: core.getInput("request-to-parent"),
|
||||||
base: core.getInput("base"),
|
base: core.getInput("base"),
|
||||||
|
@ -84,6 +85,7 @@ async function run() {
|
||||||
if (inputs.milestone) process.env.CPR_MILESTONE = inputs.milestone;
|
if (inputs.milestone) process.env.CPR_MILESTONE = inputs.milestone;
|
||||||
if (inputs.project) process.env.CPR_PROJECT_NAME = inputs.project;
|
if (inputs.project) process.env.CPR_PROJECT_NAME = inputs.project;
|
||||||
if (inputs.projectColumn) process.env.CPR_PROJECT_COLUMN_NAME = inputs.projectColumn;
|
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.branch) process.env.CPR_BRANCH = inputs.branch;
|
||||||
if (inputs.request_to_parent) process.env.CPR_REQUEST_TO_PARENT = inputs.request_to_parent;
|
if (inputs.request_to_parent) process.env.CPR_REQUEST_TO_PARENT = inputs.request_to_parent;
|
||||||
if (inputs.base) process.env.CPR_BASE = inputs.base;
|
if (inputs.base) process.env.CPR_BASE = inputs.base;
|
||||||
|
|
Loading…
Reference in a new issue