/codeowners-helper

CLI for CODEOWNERS maintenance for teams with lots of repos on GitHub Enterprise

Primary LanguageRuby

Codeowners Helper

Codeowners Helper is a command-line interface for CODEOWNERS maintenance for teams with lots of repos on GitHub Enterprise.

Features

  • Multiple ways to input required parameters or skip optional ones
  • Progress bar to keep you informed
  • Detailed results are displayed in tables
  • Messages are color- & symbol-coded for easy reading

Prerequisites

  • Ruby — 2.6 recommended

  • GitHub Enterprise
    1. Sign in to GitHub Enterprise

    2. Go to "Settings" > "Developer settings" > "OAuth Apps"

    3. Click "New OAuth App"

    4. Fill in the appropriate fields; they don't require specific values but here's some suggested values

      • Application Name: Codeowners Helper
      • Homepage URL: https://github.com/blakebuthod/codeowners-helper
      • Authorization callback URL: https://github.com/blakebuthod/codeowners-helper
    5. A client id and client secret will be generated

    1. Go to this URL in your browser: http(s)://[HOSTNAME]/login/oauth/authorize?scope=repo&client_id=[CLIENT_ID]

    2. It will redirect you (based on the value used for "Authorization callback URL") and at the end of the URL will be: ?code=...

    3. Make a POST request with that code:

      • URL: http(s)://[HOSTNAME]/login/oauth/access_token

      • Body:

        {
          "client_id": "[CLIENT_ID]",
          "client_secret": "[CLIENT_SECRET]",
          "code": "[CODE]"
        }
    4. Your token key will be in the response:

      access_token=[TOKEN_KEY]&scope=repo&token_type=bearer
      

Initialization

  1. Clone this repository
  2. Navigate into codeowners-helper/

Usage

Required Parameters

These can be passed in via command-line or typed in during execution.

  1. Hostname associated with the GitHub Enterprise
  2. OAuth token key
  3. Name of the organization of which the team belongs
  4. Name of the team

Analyze Codeowners

Description

This will audit the repos belonging to one team to determine the location of CODEOWNERS files and whether there are any missing team members or extra.

Run

This can be run without command-line arguments but you will be prompted to type required parameters during execution.

Optional parameters can be passed in via command-line after the required parameters. Alternatively they can be typed in or skipped during execution. If passed in via command-line, you won't be prompted to type in during execution.

  1. Comma-separated list of team members to remove or 0 to skip
  2. Comma-separated list of repos to remove or 0 to skip
# Without command-line arguments
ruby ./analyze_codeowners.rb

# Required parameters as command-line arguments
ruby ./analyze_codeowners.rb [HOSTNAME]
ruby ./analyze_codeowners.rb [HOSTNAME] [TOKEN_KEY]
ruby ./analyze_codeowners.rb [HOSTNAME] [TOKEN_KEY] [ORGANIZATION_NAME]
ruby ./analyze_codeowners.rb [HOSTNAME] [TOKEN_KEY] [ORGANIZATION_NAME] [TEAM_NAME]

# Required & optional parameters as command-line arguments
ruby ./analyze_codeowners.rb [HOSTNAME] [TOKEN_KEY] [ORGANIZATION_NAME] [TEAM_NAME] 2,5,8
ruby ./analyze_codeowners.rb [HOSTNAME] [TOKEN_KEY] [ORGANIZATION_NAME] [TEAM_NAME] [TEAM_MEMBERS_TO_REMOVE] 1,6,9

Fix Codeowners

Description

This will audit the repos belonging to one team to determine the location of CODEOWNERS files and whether there are any missing team members or extra.

Run

This can be run without command-line arguments but you will be prompted to type required parameters during execution.

Optional parameters can be passed in via command-line arguments after the required parameters. Alternatively they can be typed in during execution. If passed in via command-line, you won't be prompted to type in during execution.

  1. Comma-separated list of team members to remove or 0 to skip
  2. Comma-separated list of repos to remove or 0 to skip
# Without command-line arguments
ruby ./fix_codeowners.rb

# Required parameters as command-line arguments
ruby ./fix_codeowners.rb [HOSTNAME]
ruby ./fix_codeowners.rb [HOSTNAME] [TOKEN_KEY]
ruby ./fix_codeowners.rb [HOSTNAME] [TOKEN_KEY] [ORGANIZATION_NAME]
ruby ./fix_codeowners.rb [HOSTNAME] [TOKEN_KEY] [ORGANIZATION_NAME] [TEAM_NAME]

# Required & optional parameters as command-line arguments
ruby ./fix_codeowners.rb [HOSTNAME] [TOKEN_KEY] [ORGANIZATION_NAME] [TEAM_NAME] 2,5,8
ruby ./fix_codeowners.rb [HOSTNAME] [TOKEN_KEY] [ORGANIZATION_NAME] [TEAM_NAME] [TEAM_MEMBERS_TO_REMOVE] 1,6,9

Notes

  • If you don't know your organization and team name, you can find ones you belong to by running this:

    curl -u "[YOUR_GITHUB_USERNAME]" http(s)://[HOSTNAME]/api/v3/user/teams

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT