Skip to content

Make GHCP (more) aware of typical GitHub (fork) workflows #1267

@dblock

Description

@dblock

Describe the feature or problem you'd like to solve

When working with GHCP I have to constantly remind it that I work in a fork or branch.

I have been using another popular CLI to work on maintenance tasks in some repos. For example, I wanted to add support for newer versions of Mongoid to https://github.com/mongoid/mongoid-shell. GHCP did a good job minus the fact that I needed to tell it to make a feature branch and to open a PR on the upstream repo, not on my fork.

The other popular CLI is somehow automatically aware of my fork/PR workflow and always does this for me without having to ask it.

Proposed solution

Copilot should be able to recognize that I work off a fork and open PRs upstream.

Example prompts or workflows

GHCP session:

~/source/mongoid/mongoid-shell/dblock-mongoid-shell (master)$ copilot 
╭──────────────────────────────────────────────────────────────────────────────────────────────────╮
│  ╭─╮╭─╮                                                                                          │
│  ╰─╯╰─╯  GitHub Copilot v0.0.401                                                                 │
│  █ ▘▝ █  Describe a task to get started.                                                         │
│   ▔▔▔▔                                                                                           │
│  Pick a model with /model. Delegate changes with an AI-generated PR using /delegate.             │
│  Enter ? to see all commands. Copilot uses AI, so always check for mistakes.                     │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯

● 💡 No copilot instructions found. Run /init to generate a copilot-instructions.md file for this project.

❯ i have started adding support for newer versions of mongoid here, test them and finish this

● I'll explore the codebase to understand what's been started and test the newer Mongoid versions.

● List directory .
  └ 25 files found

● Read README.md
  └ 140 lines read

● Read mongoid-shell.gemspec
  └ 27 lines read

● Check git status for recent changes
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && git --no-pager status
  └ 14 lines...

● Read .github/workflows/test.yml
  └ 47 lines read

● Read Gemfile
  └ 47 lines read

● Check what changes were made
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && git --no-pager diff
  └ 62 lines...

● Good! I can see you've added Mongoid 7, 8, and 9 support. Let me run the tests to see what's working and what might need fixes.

● Install dependencies
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && bundle install
  └ 3 lines...

● Run tests with default Mongoid version (9)
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && bundle exec rake
  └ 306 lines...

● I can see 2 test failures related to default_session which doesn't exist in newer Mongoid versions. Let me check the compatibility layer and fix these issues.

● List directory lib
  └ 10 files found

● Grep "default_session"
  └ 10 lines found

● Read spec/mongoid/commands/base_spec.rb
  └ 52 lines read

● Read spec/mongoid/properties/host_spec.rb
  └ 33 lines read

● Read spec/support/helpers/mongoid_session_helper.rb
  └ 18 lines read

● Read lib/mongoid/shell/commands/base.rb
  └ 98 lines read

● I see the issue. The code uses mongoid-compatibility to check versions, but the checks only cover up to Mongoid 6. I need to update them to also handle Mongoid 7, 8, and 9. Let me
  check what compatibility methods are available.

● Check mongoid version and available compatibility methods
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && bundle exec ruby -e "require 'mongoid'; require 'mongoid-compatibility'; puts Mongoid::VERSION; puts 
  Mongoid::Compatibility::Version.methods.grep(/mongoid/)"
  └ 28 lines...

● Perfect! The mongoid-compatibility gem already has support for Mongoid 7, 8, and 9. Now I need to update the code to use default_client for Mongoid 5+, not just 5 and 6. Let me fix
  the tests and the base command.

● Edit spec/mongoid/commands/base_spec.rb (+1 -1)

● Edit spec/mongoid/properties/host_spec.rb (+1 -1)

● Edit spec/support/helpers/mongoid_session_helper.rb (+3 -3)

● Edit lib/mongoid/shell/commands/base.rb (+3 -3)

● Now let me also update the base_spec.rb where it checks for default_function:

● Edit spec/mongoid/commands/base_spec.rb (+1 -1)

● Now let me run the tests again to see if this fixes the issues:

● Run tests again with Mongoid 9
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && bundle exec rake
  └ 282 lines...

● Perfect! All tests pass with Mongoid 9. Now let me test with the other versions (7 and 8) to ensure compatibility:

● Test with Mongoid 7
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && MONGOID_VERSION=7 bundle install --quiet && MONGOID_VERSION=7 bundle exec rspec --format progress
  └ 132 lines...

● Great! Mongoid 7 tests pass. Let me test Mongoid 8:

● Test with Mongoid 8
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && MONGOID_VERSION=8 bundle install --quiet && MONGOID_VERSION=8 bundle exec rspec --format progress
  └ 132 lines...

● Excellent! All tests pass for Mongoid 7, 8, and 9. Now let me also update the README to document the supported versions and verify the changes:

● Edit README.md (+1 -1)

● Review all changes
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && git --no-pager diff
  └ 152 lines...

● Perfect! Let me run a final test to make sure everything is still working with the default version:

● Final test with default Mongoid 9
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && bundle install --quiet && bundle exec rake
  └ 294 lines...

● Perfect! All tests pass. Let me verify the current status of all changes:

● Check final status
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && git --no-pager status
  └ 19 lines...

● Excellent! I've successfully finished adding support for newer versions of Mongoid (7, 8, and 9). Here's what I did:

  Summary

  Fixed compatibility issues by updating version checks to use mongoid5_or_newer? instead of checking for individual versions, since Mongoid 5+ all use Mongoid.default_client instead
  of Mongoid.default_session.

  Changes made:

   1. Gemfile - Added support for Mongoid 7, 8, and 9
   2. CI workflow - Added test matrix entries for Mongoid 7, 8, and 9
   3. Version - Bumped to
    0.5.0
   4. CHANGELOG - Added entry for new Mongoid support
   5. README - Updated compatibility documentation
   6. Code fixes - Updated compatibility checks in:
    - lib/mongoid/shell/commands/base.rb
    - spec/mongoid/commands/base_spec.rb
    - spec/mongoid/properties/host_spec.rb
    - spec/support/helpers/mongoid_session_helper.rb

  Tests verified:

   - ✅ All 115 tests pass with Mongoid 9 (default)
   - ✅ All 115 tests pass with Mongoid 8
   - ✅ All 115 tests pass with Mongoid 7
   - ✅ No RuboCop violations

  The implementation is complete and all tests pass successfully!

❯ use gh cli to open a pr, amend the changelog with the pr number

● Commit all changes
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && git add -A && git commit -m "Add support for Mongoid 7, 8, and 9"
  └ 3 lines...

✗ Push changes to origin
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && git push origin master
  Operation aborted by user

● Operation cancelled by user

❯ do this on a branch

● Undo the last commit on master
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && git reset --soft HEAD~1
  └ 1 line...

● Create and checkout new branch
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && git checkout -b add-mongoid-7-8-9-support
  └ 2 lines...

● Commit changes on the new branch
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && git add -A && git commit -m "Add support for Mongoid 7, 8, and 9"
  └ 3 lines...

● Push the branch to origin
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && git push origin add-mongoid-7-8-9-support
  └ 14 lines...

● Create pull request
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && gh pr create --title "Add support for Mongoid 7, 8, and 9" --body "This PR adds support for Mongoid 7, 8, and 
  9.

  **Changes:**
  - Updated Gemfile to support Mongoid 7.x, 8.x, and 9.x...
  └ 14 lines...

● Set default repo
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && gh repo set-default dblock/mongoid-shell
  └ 2 lines...

● Create pull request
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && gh pr create --title "Add support for Mongoid 7, 8, and 9" --body "This PR adds support for Mongoid 7, 8, and 
  9.

  **Changes:**
  - Updated Gemfile to support Mongoid 7.x, 8.x, and 9.x...
  └ 16 lines...

● Write shell input
  └ ? Where should we push the 'add-mongoid-7-8-9-support' branch?  [Use arrows t...

● Great! PR #2 has been created. Now let me update the CHANGELOG with the PR number:

● Edit CHANGELOG.md (+1 -1)

● Amend commit with updated CHANGELOG and force push
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && git add CHANGELOG.md && git commit --amend --no-edit && git push origin add-mongoid-7-8-9-support --force
  └ 13 lines...

● Perfect! I've successfully:

   1. ✅ Created a new branch add-mongoid-7-8-9-support
   2. ✅ Committed all changes for Mongoid 7, 8, and 9 support
   3. ✅ Pushed the branch to GitHub
   4. ✅ Created Pull Request #2 (https://github.com/dblock/mongoid-shell/pull/2)
   5. ✅ Updated the CHANGELOG with the PR number and pushed the amendment

  The PR is now ready for review at: https://github.com/dblock/mongoid-shell/pull/2 (https://github.com/dblock/mongoid-shell/pull/2)

❯ the pr should be made upstream

● Check git remotes
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && git remote -v
  └ 5 lines...

● Close the existing PR
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && gh pr close 2 --comment "Closing to create PR upstream at mongoid/mongoid-shell"
  └ 2 lines...

● Push branch to upstream
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && git push upstream add-mongoid-7-8-9-support
  └ 14 lines...

● Create PR to upstream repository
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && gh pr create --repo mongoid/mongoid-shell --title "Add support for Mongoid 7, 8, and 9" --body "This PR adds 
  support for Mongoid 7, 8, and 9.

  **Changes:**
  - Updated Gemfile to support Mongoid 7.x, 8.x, and 9.x...
  └ 15 lines...

● Perfect! Now let me update the CHANGELOG with the correct PR number:

● Edit CHANGELOG.md (+1 -1)

● Amend commit with updated CHANGELOG and force push to both remotes
  $ cd /Users/dblock/source/mongoid/mongoid-shell/dblock-mongoid-shell && git add CHANGELOG.md && git commit --amend --no-edit && git push upstream add-mongoid-7-8-9-support --force && 
  git push origin add-mongoid-7-8-9-support --force
  └ 22 lines...

● Perfect! I've successfully:

   1. ✅ Closed PR #2 on dblock/mongoid-shell
   2. ✅ Pushed the branch to upstream (mongoid/mongoid-shell)
   3. ✅ Created PR #20 (https://github.com/mongoid/mongoid-shell/pull/20) on the upstream repository
   4. ✅ Updated the CHANGELOG with the correct PR number (#20)
   5. ✅ Force pushed the updated commit to both upstream and origin

  The PR is now ready for review at the upstream repository: https://github.com/mongoid/mongoid-shell/pull/20 (https://github.com/mongoid/mongoid-shell/pull/20)

 ~/source/mongoid/mongoid-shell/dblock-mongoid-shell[⎇ add-mongoid-7-8-9-support]   

Additional context

mongoid/mongoid-shell#20

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:toolsBuilt-in tools: file editing, shell, search, LSP, git, and tool call behavior
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions