Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make pull request specifiable #11

Merged
merged 1 commit into from
Aug 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions gh-act
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function repo_json {

function pr_env {
ACT_ENV="${TEMPFILE_DIR}/.pr.env"
gh pr view --json \
gh pr view ${1:-} --json \
additions,baseRefName,body,closedAt,comments,commits,createdAt,deletions,files,headRefName,headRepositoryOwner,headRepository,id,isDraft,maintainerCanModify,mergedAt,mergedBy,milestone,number,reviews,state,title,updatedAt,url \
--template '
PR_ADDITIONS="{{.additions}}"
Expand Down Expand Up @@ -161,7 +161,7 @@ PR_URL="{{.url}}"
function pr_review_env {
# FIXME: PR_REVIEW_ID
ACT_ENV="${TEMPFILE_DIR}/.pr_review.env"
gh pr view --json \
gh pr view ${1:-} --json \
reviews \
--template '
{{$last := 0}}
Expand Down Expand Up @@ -262,10 +262,18 @@ REPO_WATCHERS_TOTAL_COUNT="{{.watchers.totalCount}}"


function pull_request_event_envs() {
pr_env
HEAD=$(gh pr view --json commits --jq .commits[].oid | tail -1)
HEAD_USER=$(gh pr view --json commits --jq .commits[].authors[].login | tail -1)
BEFORE=$(gh pr view --json commits --jq .commits[].oid | tail -2 | head -1)
# configurable vars
# PULL_REQUEST_SPEC
# PULL_REQUEST_NUMBER
PULL_REQUEST_SPEC="${PULL_REQUEST_SPEC:-}"
if [ -n "${PULL_REQUEST_NUMBER:-}" ]; then
PULL_REQUEST_SPEC="${PULL_REQUEST_NUMBER}"
fi

pr_env "${PULL_REQUEST_SPEC}"
HEAD=$(gh pr view ${PULL_REQUEST_SPEC} --json commits --jq .commits[].oid | tail -1)
HEAD_USER=$(gh pr view ${PULL_REQUEST_SPEC} --json commits --jq .commits[].authors[].login | tail -1)
BEFORE=$(gh pr view ${PULL_REQUEST_SPEC} --json commits --jq .commits[].oid | tail -2 | head -1)

# base
repo_env "${OWNER}/${REPO}" "BASE"
Expand All @@ -274,16 +282,15 @@ function pull_request_event_envs() {
BASE_SHA=$(gh api --hostname ${GITHUB_HOSTNAME} --method GET -H "Accept: application/vnd.github.v3+json" /repos/${OWNER}/${REPO}/git/refs/heads/${BASE_REF} --jq .object.sha)

if [[ "${EVENT_NAME}" =~ .*review.* ]]; then
PR_REIVE_LENGTH=$(gh pr view --json reviews --jq '.reviews | length')
if [ "${PR_REIVE_LENGTH}" == "0" ]; then
if [ "${PR_REVIEWS}" == "0" ]; then
PR_REVIEW_ID=0
PR_REVIEW_USER="${HEAD_USER}"
PR_REVIEW_BODY="gh-act review"
PR_REVIEW_AUTHOR_ASSOCIATION="OWNER"
PR_REVIEW_SUBMITTED_AT="${PR_UPDATED_AT}"
PR_REVIEW_STATE="COMMENTED"
else
pr_review_env
pr_review_env "${PULL_REQUEST_SPEC}"
fi
PR_REVIEW_USER_JSON=$(user_json "${PR_REVIEW_USER}")
fi
Expand All @@ -292,6 +299,7 @@ function pull_request_event_envs() {

function issue_event_envs() {
# configurable vars
# ISSUE_NUMBER
if [ -z "${ISSUE_NUMBER:-}" ]; then
ISSUE_NUMBER=$(gh issue list --json number --jq .[].number | head -1)
fi
Expand Down
4 changes: 2 additions & 2 deletions templates/parts/pull_request.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"active_lock_reason": null,
"additions": ${PR_ADDITIONS},
"assignee": null,
"assignees": $(gh pr view --json assignees --jq .assignees),
"assignees": $(gh pr view ${PULL_REQUEST_SPEC} --json assignees --jq .assignees),
"author_association": "OWNER",
"auto_merge": null,
"base": {
Expand Down Expand Up @@ -59,7 +59,7 @@
"html_url": "${PR_URL}",
"id": 0,
"issue_url": "https://${GITHUB_API}/repos/${OWNER}/${REPO}/issues/${PR_NUMBER}",
"labels": $(gh pr view --json labels --jq .labels),
"labels": $(gh pr view ${PULL_REQUEST_SPEC} --json labels --jq .labels),
"locked": false,
"maintainer_can_modify": ${PR_MAINTAINER_CAN_MODIFY},
"merge_commit_sha": "${PR_POTENTIAL_MERGE_COMMIT}",
Expand Down
6 changes: 3 additions & 3 deletions templates/parts/pull_request.min.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"active_lock_reason": null,
"assignee": null,
"assignees": $(gh pr view --json assignees --jq .assignees),
"assignees": $(gh pr view ${PULL_REQUEST_SPEC} --json assignees --jq .assignees),
"author_association": "OWNER",
"auto_merge": null,
"base": {
Expand All @@ -54,7 +54,7 @@
"html_url": "${PR_URL}",
"id": 0,
"issue_url": "https://${GITHUB_API}/repos/${OWNER}/${REPO}/issues/${PR_NUMBER}",
"labels": $(gh pr view --json labels --jq .labels),
"labels": $(gh pr view ${PULL_REQUEST_SPEC} --json labels --jq .labels),
"locked": false,
"merge_commit_sha": "${PR_POTENTIAL_MERGE_COMMIT}",
"merged_at": "${PR_MERGED_AT}",
Expand All @@ -68,7 +68,7 @@
"review_comments_url": "https://${GITHUB_API}/repos/${OWNER}/${REPO}/pulls/${PR_NUMBER}/comments",
"state": "${PR_STATE,,}",
"statuses_url": "https://${GITHUB_API}/repos/${OWNER}/${REPO}/statuses/${HEAD}",
"title": "$(gh pr view --json title --jq .title)",
"title": "${PR_TITLE}",
"updated_at": "${PR_UPDATED_AT}",
"url": "https://${GITHUB_API}/repos/${OWNER}/${REPO}/pulls/${PR_NUMBER}",
"user": ${BASE_USER_JSON}
Expand Down