Giter VIP home page Giter VIP logo

fork-sweeper's Introduction

fork sweeper | \|/ -|- // \\ /// \\\ //// \\\\

Remove unused GitHub forks

Installation

  • On macOS, brew install:

    brew tap rednafi/fork-sweeper https://github.com/rednafi/fork-sweeper \
        && brew install fork-sweeper
  • Elsewhere, go install:

    go install github.com/rednafi/fork-sweeper/cmd/fork-sweeper

Prerequisites

  • Collect your GitHub API access token. The token will be sent as Bearer <token> in the HTTP header while making API requests.
  • The token must have write and delete access to the forked repos.
  • Set the GITHUB_TOKEN to your current shell environment with export GITHUB_TOKEN=<token> command.

Usage

  • Run help:

    fork-sweeper -h
    Usage of fork-sweeper:
      -delete
            Delete forked repos
      -guard value
            List of repos to protect from deletion (fuzzy match name)
      -max-page int
            Maximum number of pages to fetch (default 100)
      -older-than-days int
            Fetch forked repos modified more than n days ago (default 60)
      -owner string
            GitHub repo owner (required)
      -per-page int
            Number of forked repos fetched per page (default 100)
      -token string
            GitHub access token (required)
      -version
            Print version
  • List forked repos older than n days. By default, it'll fetch all forked repositories that were modified at least 60 days ago. The following command lists all forked repositories.

    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
  • The CLI won't delete any repository unless you explicitly tell it to do so with the --delete flag:

    fork-sweeper --owner rednafi --token $GITHUB_TOKEN --delete
  • You can explicitly protect some repositories from deletion with the --guard parameter:

    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

    The --guard parameter can be passed multiple times to filter out multiple repos.

  • By default, the CLI will fetch 100 pages of forked repositories with 100 entries on each page. If you need more, you can set the page number as follows:

    fork-sweeper --owner rednafi --token $GITHUB_TOKEN --max-page 200 --per-page 100

fork-sweeper's People

Contributors

rednafi avatar

Stargazers

sudo pacman -Syu avatar Emmanuel Raymond avatar  avatar Cameron Eagans avatar Shashank Priyadarshi avatar Damian Truszkiewicz avatar Oleg Shparber avatar Duncan Thomas avatar Steve Coffman avatar Peter Nguyen avatar Alexey Korolev avatar Can Evgin avatar Jim Tittsler avatar Koichi Shiraishi avatar Clayton Kehoe avatar Pablo Crivella avatar Michael S. Manley avatar Sevdalin Sabev avatar Shafayet Khan Shafee avatar Tanvir Raj avatar Matthew Martin avatar  avatar HDVinnie avatar

Watchers

 avatar  avatar

fork-sweeper's Issues

Print a helpful message when the token doesn't have enough permission

If the GITHUB_TOKEN doesn't have enough permission to perform --delete it prints:

fork-sweeper --owner doesnotexist --token $GITHUB_TOKEN --delete
Deleting forked repositories...

Error deleting repositories: API request failed with status: 403

Turn it into a better error message. Go's error handling is lame!

Print a helpful message when the username doesn't exist

Currently, when you run:

fork-sweeper --owner doesnotexist --token $GITHUB_TOKEN

it prints:

Fetching repositories for doesnotexist...

Error fetching repositories: API request failed with status: 404

Return a more intuitive error message. I hate Go's error handling.

Protect repositories

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:

  • protecting some repositories manually, because we may want to keep them even if all other "protections" fail
  • 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).

Add a --timeout flag

Add a --timeout flag to timeout the operation. Also, provide a sensible default here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.