Skip to content

Conversation

@Dan7-7-7
Copy link
Collaborator

@Dan7-7-7 Daniel Ranson (Dan7-7-7) commented Apr 14, 2025

for #6 and #167

@Dan7-7-7 Daniel Ranson (Dan7-7-7) changed the title initial thought feat (cleanup forks): initial thoughts Apr 14, 2025
@Dan7-7-7
Copy link
Collaborator Author

Agreed to leave the apply step for a future time and just output the bash command needed to loop over the forks and delete. For the sake of clarity about what is being done here.

@Dan7-7-7 Daniel Ranson (Dan7-7-7) changed the title feat (cleanup forks): initial thoughts feat (cleanup forks): detect deletable forks Sep 9, 2025
@Dan7-7-7 Daniel Ranson (Dan7-7-7) marked this pull request as ready for review September 12, 2025 13:56
Copilot AI review requested due to automatic review settings September 12, 2025 13:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements functionality to detect and clean up deletable forks in Turbolift campaigns. It adds a new cleanup command that identifies forks without open upstream PRs and provides instructions for their safe deletion.

  • Adds new GitHub API methods to check if a repository is a fork and detect open upstream PRs
  • Implements Git functionality to retrieve origin repository URLs
  • Creates a new cleanup command with comprehensive test coverage

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
internal/github/github.go Adds IsFork, UserHasOpenUpstreamPRs, and GetOriginRepoName methods to GitHub interface
internal/github/github_test.go Comprehensive test coverage for new GitHub methods
internal/github/fake_github.go Mock implementations for testing the new GitHub methods
internal/git/git.go Adds GetOriginUrl method to retrieve Git origin URL
internal/git/git_test.go Test coverage for the new GetOriginUrl method
internal/git/fake_git.go Mock implementation for GetOriginUrl method
internal/executor/fake_executor.go New fake executors that return boolean values for testing
cmd/cleanup/cleanup.go New cleanup command implementation
cmd/cleanup/cleanup_test.go Test suite for the cleanup command
cmd/root.go Registers the new cleanup command
README.md Documentation for the cleanup functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

}

func (r *RealGitHub) IsFork(output io.Writer, workingDir string) (bool, error) {
response, err := execInstance.ExecuteAndCapture(output, workingDir, "gh", "repo", "view", "--json", "isFork")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sadly I think that gh repo view --json isFork is not right. When running it locally I'm seeing it not detect forks...

Looking deeper, I think that gh repo view --json isFork is telling us about the cloned repo, not the user's fork of it. e.g. :

$ cd work/someorg/somerepo

$ gh repo view --json isFork,nameWithOwner
{
  "isFork": false,
  "nameWithOwner": "someorg/somerepo"
}

Note that git remote -v yields:

origin	[email protected]:richardnorth/somerepo.git (fetch)
origin	[email protected]:richardnorth/somerepo.git (push)
upstream	[email protected]:someorg/somerepo.git (fetch)
upstream	[email protected]:someorg/somerepo.git (push)

I've been battling with permissions on GHES but I think that if we were to use the name of the origin repo we'd be able to get the right answer. e.g. gh repo view richardnorth/somerepo --json isFork

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch - I'll update that. Should be straightforward since we're already adding a method that gets the origin repo name.

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