Skip to content

Output commit SHA when gh pr merge is successful #10746

@aduh95

Description

@aduh95

Describe the feature or problem you’d like to solve

Currently there seems to be no way to get SHA of the resulting commit when landing a PR without falling back to a "manual" call.

Proposed solution

Add support for a flag that would allow users opt-in (or opt-out) of getting the commit SHA in the stdout.

Additional context

Currently here's what we use:

jq -n \
    --arg title "${commit_title}" \
    --arg body "${commit_body}" \
    --arg head "${commit_head}" \
    '{merge_method:"squash",commit_title:$title,commit_message:$body,sha:$head}' > output.json
cat output.json
if ! commit="$(gh api -X PUT "repos/${OWNER}/${REPOSITORY}/pulls/${pr}/merge" --input output.json --jq 'if .merged then .sha else halt_error end')"; then
    pr_merge_failed "$pr" # Handle the failed merger
fi
# Use the final commit SHA
gh pr comment "$pr" --body "Landed in $commit"

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementa request to improve CLIgh-prrelating to the gh pr command

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions