Skip to content

Replace git phr with GitHub CLI#521

Open
ogajduse wants to merge 6 commits intotheforeman:masterfrom
ogajduse:feature/replace-git-phr
Open

Replace git phr with GitHub CLI#521
ogajduse wants to merge 6 commits intotheforeman:masterfrom
ogajduse:feature/replace-git-phr

Conversation

@ogajduse
Copy link
Member

Summary

Replaces the custom git phr alias dependency with the standard GitHub CLI tool.

Changes

  • Updated bump_packaging to use gh pr create instead of git phr
  • Dependency documentation: Added GitHub CLI installation instructions to README

Benefits

  • Removes dependency on custom git aliases that users need to configure manually
  • Uses standard tooling available in distribution packages
  • Addresses git phr issue mentioned in Newbie installation issues #336

bump_packaging Outdated
fi

git commit -m "Release $FULLVERSION"
git push "$PACKAGING_GIT_REMOTE" "HEAD:$REMOTE_BRANCH"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pushes straight to the target branch. A PR after this is pointless because it's effectively already merged.

Remember that phr is both a push (to your own fork) and a PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #337 for an expansion of the aliases I use. Your PR here effectively implements what @evgeni suggested about using gh.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pushes straight to the target branch. A PR after this is pointless because it's effectively already merged.

Remember that phr is both a push (to your own fork) and a PR.

I have missed the fact that $PACKAGING_GIT_REMOTE is the upstream repository. I'll fix it in the next patch.

@ogajduse
Copy link
Member Author

I've pushed updates that address the issues identified in the review. Changes I've made:

  • Added GITHUB_USER setting with auto-detection via gh api user --jq .login (configurable in settings.local)
  • Added PACKAGING_FORK_REMOTE setting for configurable fork remote name
  • Use deterministic branch naming: release-$PROJECT-$FULLVERSION
  • Explicit fork creation with gh repo fork --remote-name

Benefits:

  • PR creation now creates a fork-to-upstream PR
  • Predictable remote names, branch names, and user identification
  • Other scripts can leverage the same fork setup and settings

@ogajduse
Copy link
Member Author

I initially considered using just gh pr create without explicit fork management, but decided against it for several reasons:

  • gh pr create creates forks and remotes with unpredictable names, making it impossible to reliably reference the fork setup in other scripts.
  • The existing codebase uses GIT_REMOTE=upstream and PACKAGING_GIT_REMOTE=origin conventions. Auto-managed remotes could create inconsistent setups.
  • Other scripts need predictable settings they can reference. When things break, explicit steps are much clearer than auto-detection "magic."

@ogajduse
Copy link
Member Author

ogajduse commented Sep 9, 2025

I've used the script to bump rpm/3.16 to 3.16.0. Here is the script output if anyone is interested. One thing can be improved, though. That is the gh repo fork which prompts the user for input. That should ideally be auto-answered - the default option should be used.

+ git add packages/foreman/foreman packages/foreman/foreman-installer packages/foreman/foreman-proxy packages/foreman/foreman-release packages/foreman/foreman-selinux
+ git commit -m 'Release 3.16.0'
[rpm/release-foreman-3.16.0 93d057f80] Release 3.16.0
 13 files changed, 20 insertions(+), 15 deletions(-)
 delete mode 120000 packages/foreman/foreman-installer/foreman-installer-3.16.0-rc2.tar.bz2
 create mode 120000 packages/foreman/foreman-installer/foreman-installer-3.16.0.tar.bz2
 delete mode 120000 packages/foreman/foreman-proxy/foreman-proxy-3.16.0-rc2.tar.bz2
 create mode 120000 packages/foreman/foreman-proxy/foreman-proxy-3.16.0.tar.bz2
 delete mode 120000 packages/foreman/foreman-selinux/foreman-selinux-3.16.0-rc2.tar.bz2
 create mode 120000 packages/foreman/foreman-selinux/foreman-selinux-3.16.0.tar.bz2
 delete mode 120000 packages/foreman/foreman/foreman-3.16.0-rc2.tar.bz2
 create mode 120000 packages/foreman/foreman/foreman-3.16.0.tar.bz2
+ [[ true == true ]]
+ gh repo fork theforeman/foreman-packaging --remote-name origin
! ogajduse/foreman-packaging already exists
? Would you like to clone the fork? No
+ git push origin HEAD:rpm/release-foreman-3.16.0
Enumerating objects: 31, done.
Counting objects: 100% (31/31), done.
Delta compression using up to 14 threads
Compressing objects: 100% (18/18), done.
Writing objects: 100% (18/18), 2.02 KiB | 2.02 MiB/s, done.
Total 18 (delta 10), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (10/10), completed with 10 local objects.
remote: 
remote: Create a pull request for 'rpm/release-foreman-3.16.0' on GitHub by visiting:
remote:      https://github.com/ogajduse/foreman-packaging/pull/new/rpm/release-foreman-3.16.0
remote: 
To github.com:ogajduse/foreman-packaging.git
 * [new branch]          HEAD -> rpm/release-foreman-3.16.0
+ gh pr create --repo theforeman/foreman-packaging --title 'RPM: Release Foreman 3.16.0' --head ogajduse:rpm/release-foreman-3.16.0 --base rpm/3.16 --body 'Release Foreman 3.16.0'

Creating pull request for ogajduse:rpm/release-foreman-3.16.0 into rpm/3.16 in theforeman/foreman-packaging

https://github.com/theforeman/foreman-packaging/pull/12455

settings Outdated
GIT_DEVELOP_BRANCH=develop
GIT_STABLE_BRANCH="${VERSION}-stable"
GITHUB_NAMESPACE=theforeman
GITHUB_USER="${GITHUB_USER:-$(gh api user --jq .login)}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This performs a network request and I'd suggest to avoid that. Perhaps just assume the GITHUB_USER is $USER?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're including gh in the script, the network requests are going to be performed anyway

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not always. Remember that settings is always loaded, also for commands where git isn't involved.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. In that case, there's also an option to keep this API call but do it only when needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd still lean to keeping it simple:

Suggested change
GITHUB_USER="${GITHUB_USER:-$(gh api user --jq .login)}"
GITHUB_USER="${GITHUB_USER:-$USER}"

Then users can override it in their local settings if they want. Either statically or dynamically with gh api user.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

@ogajduse ogajduse force-pushed the feature/replace-git-phr branch 2 times, most recently from 98f6be4 to 56c9e72 Compare November 5, 2025 15:55
@ogajduse ogajduse requested a review from ekohl November 5, 2025 15:56
@ogajduse
Copy link
Member Author

ogajduse commented Nov 5, 2025

settings Outdated
GITHUB_USER="${GITHUB_USER:-$USER}"
PACKAGING_DIR="$GIT_DIR/foreman-packaging"
PACKAGING_GIT_REMOTE=origin
PACKAGING_FORK_REMOTE="${PACKAGING_FORK_REMOTE:-origin}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These both default to origin, but is that really what we want? You'll end up running gh repo fork theforeman/foreman-packaging --remote-name "origin" but there is already an origin. Doesn't it make more sense to default to the GH username?

Suggested change
PACKAGING_FORK_REMOTE="${PACKAGING_FORK_REMOTE:-origin}"
PACKAGING_FORK_REMOTE="${PACKAGING_FORK_REMOTE:-${GITHUB_USER}}"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That totally makes sense. Addressed.

bump_packaging Outdated
if [[ $PACKAGING_PR == true ]] ; then
git phr -m "Release $FULLVERSION" -b "$REMOTE_BRANCH"
# Ensure fork exists with configured remote name
gh repo fork theforeman/foreman-packaging --remote-name "$PACKAGING_FORK_REMOTE"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I try this out locally I see:

$ gh repo fork theforeman/foreman-packaging --remote-name ekohl
! ekohl/foreman-packaging already exists
? Would you like to clone the fork? (y/N) 

So this is an interactive command and that goes against the spirit of the tooling. I don't see any option to make gh non-interactive and quiet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. I stumbled upon GH_PROMPT_DISABLED

GH_PROMPT_DISABLED: set to any value to disable interactive prompting in the terminal.

$ GH_PROMPT_DISABLED=1 gh repo fork theforeman/pulpcore-packaging --remote-name ekohl
✓ Created fork ogajduse/pulpcore-packaging
$ echo $?
0
$ GH_PROMPT_DISABLED=1 gh repo fork theforeman/pulpcore-packaging --remote-name ekohl
! ogajduse/pulpcore-packaging already exists
$ echo $?
0

Updated.

bump_packaging Outdated
# Ensure fork exists with configured remote name
gh repo fork theforeman/foreman-packaging --remote-name "$PACKAGING_FORK_REMOTE"

# Push to fork
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be nitpicking, but does the comment really add anything? I'd think that the command it self-explanatory.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Comment removed.

@ogajduse ogajduse requested a review from ekohl February 2, 2026 20:58
  - Replace git phr alias with gh pr create in bump_packaging script
  - Change push behavior to always push before creating PR
  - Add GitHub CLI installation documentation to README
  - Addresses git phr dependency issue mentioned in theforeman#336

  This removes the dependency on custom git aliases and uses the standard
  GitHub CLI tool that's available in distribution packages.
- Add GITHUB_USER setting with auto-detection via gh CLI
- Add PACKAGING_FORK_REMOTE setting for configurable fork remote name
- Fix git push/PR creation logic in bump_packaging:
  - Remove direct push to target branch when creating PRs
  - Use deterministic branch names: release-$PROJECT-$FULLVERSION
  - Explicitly manage fork creation with gh repo fork
  - Use configured GITHUB_USER and PACKAGING_FORK_REMOTE settings
- Document new settings in README
- Ensures predictable behavior and reusable fork setup
- Change PACKAGING_FORK_REMOTE default from 'origin' to GITHUB_USER
- Simplify git push to use --set-upstream with plain HEAD
- Update documentation to reflect actual default behavior
@ogajduse ogajduse force-pushed the feature/replace-git-phr branch from e181d42 to 0a27c76 Compare February 10, 2026 19:50
@ogajduse
Copy link
Member Author

Rebased onto master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants