Git Product home page Git Product logo

gh-org-repo-sync's Introduction

gh-org-repo-sync

Build Lint CodeQL Analysis Go Report Card

GitHub CLI extension to clone all repositories in an Organization, with the ability to filter via search queries. If a local clone already exists, it fetches all remotes and pulls changes from the default branch.

Installation

  • Install the gh CLI. See https://github.com/cli/cli#installation for further details.
  • If not done already, also install Git.
  • To be able to clone private repos you have access to inside the Organization, authenticate with your GitHub account by running gh auth login. Alternatively, the CLI will respect the GITHUB_TOKEN environment variable.
  • Install the extension:
gh extension install rm3l/gh-org-repo-sync

Usage

❯ gh org-repo-sync -h

Usage: gh org-repo-sync <organization> [options]
Options: 
  -batch-size int
        the number of elements to retrieve at once. Must not exceed 100 (default 50)
  -dry-run
        dry run mode. to display the repositories that will get cloned or updated, 
        without actually performing those actions
  -force
        whether to force sync repositories.
        Caution: this will hard-reset the branch of the destination repository to match the source repository.
  -output string
        the output path (default ".")
  -protocol string
        the protocol to use for cloning. Possible values: system, ssh, https. (default "system")
  -query string
        GitHub search query, to filter the Organization repositories.
        Example: "language:Java stars:>10 pushed:>2010-11-12"
        See https://bit.ly/3HurHe3 for more details on the search syntax

Working with the source code

  1. Clone the repository:
git clone https://github.com/rm3l/gh-org-repo-sync
cd gh-org-repo-sync
  1. Download and install Go to build the project. Or if you are already using the asdf version manager, you can just run asdf install to install all the necessary tools (declared in the .tool-versions file).

  2. Install the local version of this extension; gh symlinks to your local source code directory.

# Install the local version
gh extension install .
  1. At this point, you can start using it:
gh org-repo-sync <my-organization>
  1. To see changes in the code as you develop, simply build and use the extension
go build && gh org-repo-sync <my-organization>

Contribution Guidelines

Contributions and issue reporting are more than welcome. So to help out, do feel free to fork this repo and open up a pull request. I'll review and merge your changes as quickly as possible.

You can use GitHub issues to report bugs. However, please make sure your description is clear enough and has sufficient instructions to be able to reproduce the issue.

Developed by

License

The MIT License (MIT)

Copyright (c) 2022 Armel Soro

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

gh-org-repo-sync's People

Contributors

dependabot[bot] avatar rm3l avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gh-org-repo-sync's Issues

Add support for secure token storage

Token storage change in latest release of gh

This is a message from the GitHub CLI team, maintainers of gh, writing to inform you that the most recent release of gh contains changes which may affect your extension. The latest release introduces the feature of storing authentication tokens in the system keyring (encrypted storage) instead of in a plain text file.
The keyrings that are supported are:

  • Keychain on macOS

  • GNOME Keyring on Linux (Secret Service dbus interface)

  • Wincred on Windows

This has huge security benefits for the users of our tool and was one of our oldest outstanding issues. Unfortunately this change has the potential to break extensions that rely on utilizing the users authentication token to work.

In order to have continued compatibility with gh there are some actions you, as an extension author, need to take. These actions will depend on the implementation of your extension.

Extensions built in Go using go-gh:

  1. Upgrade your go-gh version to v1.2.1, the latest version.

  2. Verify that in your extension retrieval of the user authentication token is done using the auth.TokenForHost function.

    • If you were previously accessing the authentication token using any other method it will no longer work.
    • Automatic resolution of the authentication token when using the API clients will continue to work without changes.

All other extensions:

  1. Verify that in your extension retrieval of the user authentication token is done by shelling out to the gh auth token command.

    • If you were previously accessing the authentication token using the gh config get command, reading the configuration file directly, or any other methods it will no longer work.

As of right now storing the authentication token in the system keyring is an opt-in feature, but in the near future it will be required and at that point if the changes above are not made then your extension will be broken for all users. If you have any questions/concerns about this change please feel free to open a discussion in the gh repo.

Thanks,
The GitHub CLI Team

Add delete command. when repos don't exist anymore

Nice, I've got this in bash to delete the repos when out of sync, ie I run gh repo list --json name --jq '.[].name' | xargs -I {} git clone "{}"

cd path
comm -23 \
   <(command ls -1 | sort) \
   <(gh repo list --json name --jq '.[].name' | sort) \
   | xargs -I {} bash -c 'command rm -rf "{}"'

xargs has -p arg for parallel. Ovs not as quick, but.

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.