fork-sweeper icon indicating copy to clipboard operation
fork-sweeper copied to clipboard

Protect repositories

Open Crocmagnon opened this issue 1 year ago • 5 comments

Hello! Thank you for this nice tool, I wanted to do some cleanup in my forks but unfortunately I'd need some more features to use it.

There are many reasons a fork may need to stay even if it's old. Maybe a branch is unmerged and we're still working on it, maybe a PR is open waiting for a review. It also appears that the tool only filters forks by their createdAt date. I'm actively working on a fork and I regularly push commits & branches and they get merged regularly, so I don't want to delete this fork.

I suggest adding several features to make the tool useful to more people:

  • [x] protecting some repositories manually, because we may want to keep them even if all other "protections" fail
  • [x] protecting repositories based on last activity instead of creation date
  • [ ] protecting repositories based on open PRs in the upstream repo
  • [ ] protecting repositories based on unmerged branches (with recent activity?)

The output should mention clearly why a repo is being protected or if it's being deleted (or would be, in case the -delete flag is not provided).

Crocmagnon avatar Mar 15 '24 09:03 Crocmagnon

Thank you for the ideas; they are great!

I really like the idea of deleting repositories based on the last activity date, rather than the creation date. This can be done without changing the external flag.

Also, a --protect flag that will take a list of repositories sounds useful.

I'll start tackling tasks from the lowest level of complexity to the highest. Also, feel free to open a PR if you have strong opinions about the implementation.

rednafi avatar Mar 15 '24 10:03 rednafi

Version 0.2.0 now:

  • Fetches forked repos based on pushed_at || updated_at || created_at date.

  • Lists the forked repositories that will and won't be deleted:

    fork-sweeper --owner rednafi --token $GITHUB_TOKEN --older-than-days 0
    

    This returns:

    Fetching forked repositories for rednafi...
    
    Guarded forked repos [won't be deleted]:
    
    Unguarded forked repos [will be deleted]:
        - https://github.com/rednafi/cpython
        - https://github.com/rednafi/dysconfig
        - https://github.com/rednafi/pydantic
    
  • Explicitly filter out forked repositories with fuzzy name matching:

    fork-sweeper --owner "rednafi" --token $GITHUB_TOKEN --older-than-days 0 --guard 'py'
    

    This prints:

      Fetching forked repositories for rednafi...
    
      Guarded forked repos [won't be deleted]:
          - https://github.com/rednafi/cpython
          - https://github.com/rednafi/pydantic
    
      Unguarded forked repos [will be deleted]:
          - https://github.com/rednafi/dysconfig
    

rednafi avatar Mar 18 '24 01:03 rednafi

Nice ! 😀 I think however the biggest value would come from an "open PR" guard. It may require some more work though as I don't know if this information can easily be obtained with GitHub's API. Also, listing why repos are protected would be a good addition too IMO.

Crocmagnon avatar Mar 18 '24 16:03 Crocmagnon

Yeah, a PR guard would be nice I agree. But at the same time, it's hard to track that without consuming some event.

Listing why a repo was filtered out seems like an easy low-hanging fruit.

rednafi avatar Mar 18 '24 17:03 rednafi

After doing some exploration, it looks like the open PR feature can be implemented quite easily with the GraphQL API but would require several calls with the REST API. There’s a discussion on the refined-github repo about this, specifically this comment: https://github.com/refined-github/refined-github/issues/2268#issuecomment-562495007

Crocmagnon avatar Mar 19 '24 07:03 Crocmagnon