cli / cli/cli

Output commit SHA when `gh pr merge` is successful

Open
#10,746 2 comments 0 reactions 0 assignees View on GitHub
enhancement gh-pr
Dominant language
Go
Stars
46.3k
Forks
9k
Avg merge
2d 9h
Merged PRs (30d)
89

Description

### 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:

```sh
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"
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.