Giter VIP home page Giter VIP logo

ghctl's Introduction

ghctl

GitHub release CII Best Practices CircleCI SonarCloud Status Docker Hub

a lightweight and portable command-line GitHub repository management tool

The aim of the project is to be automatize the creation of repositories with yaml files.

Why ghctl is needed?

GitHub is a great version control system. For creating repositories with branch protection, adding some mandatory reviewers to repo is tedious. Additionally if your organisation works with microservices or serverless architecture, it means that every day you will create repo.

To automatize this kind of issues ghctl will help you apply your yaml configuration of repo and create repo with some pipeline.

ghctl helps you create repository from command-line: ghctl demo GIF

Installation

You can download the binary built for your architecture from the latest release.

macOS

The following is an example of installation on macOS:

$ curl https://github.com/amirashad/ghctl/releases/download/v0.5.0/ghctl_darwin_amd64 -L -o /usr/local/bin/ghctl
$ chmod +x /usr/local/bin/ghctl

Linux

For Linux based OS, you can use following oneliner to download latest binary for AMD64 architecture.

$ curl -L "$(curl -Ls https://api.github.com/repos/amirashad/ghctl/releases/latest | grep -o -E "https://.+?_linux_amd64")" -o /usr/local/bin/ghctl && chmod +x /usr/local/bin/ghctl 

Windows

For Windows OS, you can use following PowerShell command to download binary for AMD64 architecture.

Invoke-WebRequest https://github.com/amirashad/ghctl/releases/download/v0.5.0/ghctl_windows_amd64.exe -O ghctl.exe

Docker

You can also use ghctl via Docker.

$ docker run --rm -v $(pwd):/data -t amirashad/ghctl

You can use this image to automatize repo creation with CI/CD tools like Travis CI, CircleCI. curl and yq was preinstalled to image.

Features

  • Apply with yaml file or with cli args
  • Create repository
  • Create branch on repository
  • Create protection on branch
  • Add mandatory reviewers to branch protection
  • Add required checks to branch protection
  • Add some files to repository, branch
  • Get repositories of organisation as yaml or json
  • Get repository by name as yaml or json
  • Get members of organisation as yaml or json
  • Get teams of organisation as yaml or json

Limitations

ghctl currently only manages repositories.

Usage

  1. ghctl to work properly should set environment variable GITHUB_TOKEN and GITHUB_ORG or specify as command-line argument --token and --org appropriately.

To get more help:

$ ghctl --help
Usage: ghctl [OPTIONS] [COMMANDS] [FILE]

OPTIONS:
      --token                                   GitHub token
      --org                                     GitHub organisation
      --version                                 Display version and exit
  -o, --outputformat=[normal|json|yaml]         Output format (default: normal)
  -v, --verbose,                                Show debug output (default: false)
  -h, --help,                                   Display this help and exit

COMMANDS:
  get
    repos
    members
    teams
  create
    repo
    branch
    protection
  add
    file
    collaborator
    team
  update
    repo
    branch
    protection
  apply
  1. Create yaml file with needed configurations. For example, create repo.yml with following content
github:
  repo:
    name: << Repository name >>
    description: << Repository description >>
    homepage: 
    private: false
    defaultBranch: develop
    onCreate:
      autoInit: true
      gitignore: Java
      license: null
    pages:
      issues: true
      projects: true
      wiki: true
    merge:
      allowMergeCommit: true
      allowSquashMerge: true
      allowRebaseMerge: true
    teams:
      team-developers: push
      team-admins: admin
    branches:
    - name: develop
      minApprove: 2
      codeOwners: true
      includeAdmins: true
      requiredStatusChecks:
        requiredBranchesUpToDate: true
        contexts:
        - 'ci/circleci: validate_code'
        - 'ci/circleci: validate_infra'
      push:
        users:
        - << Github username which has access to push to this branch >>
        teams: []
    - name: master
      minApprove: 1
      codeOwners: true
      includeAdmins: true
      requiredStatusChecks:
        requiredBranchesUpToDate: true
        contexts:
        - 'ci/circleci: validate_code'
        - 'ci/circleci: validate_infra'
        - 'ci/circleci: security_checks'
      push:
        users:
        - << Github username which has access to push to this branch >>
        teams: []
  1. Apply script
$ ghctl apply -f repo.yml

Examples

Exit Statuses

ghctl returns the following exit statuses on exit:

  • 0: No issues found
  • 1: Errors occurred

FAQ

Does ghctl create projects?

  • No. ghctl not yet supports project creation.

Debugging

If you don't get the expected behavior, you can see the detailed logs when running with --verbose flag.

$ ghctl create repo --name my-repo --verbose

ghctl's People

Contributors

amirashad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ghctl's Issues

Some branch protections not supported

In the web ui, there are a few branch protection options not yet supported by ghctl, such as

  • "Require conversation resolution before merging"
  • "Require signed commits"
  • "Require linear history"

ghctl UI

As an addition it would be nice to have a GUI. There are a lot of argument to remember)
Also you can publish it to npm

apply yaml to existing repository

The apply yaml file format allows easy specification of what the repo settings should be. It would be nice if this could be applied to an existing repository.

ghctl create protection displays schema error

I am trying to create a branch protection for master branch which uses all of the defaults. I can do this in the repo settings UI, e.g. only ticking "Include administrators", and leaving everything else unticked. This is useful because it leaves unticked "Allow force pushes" and "Allow deletions".

ghctl create protection -r xyz -b master --includeadmins
PUT https://api.github.com/repos/org/xyz/branches/master/protection: 422 Invalid request.

No subschema in "anyOf" matched.
0 must be greater than or equal to 1.
Not all subschemas of "allOf" matched.
For 'anyOf/1', {"dismiss_stale_reviews"=>false, "require_code_owner_reviews"=>false, "required_approving_review_count"=>0} is not a null. []

Adding --minapprove 0 doesnt help.

Adding --minapprove 1 does get past the error, but that also enables "Require status checks to pass before merging" without any status checks being selected.

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.