Sha256: a20afd66a5ad469af7308bd771f0f74767aff42a242c30b30416a528485fb1ac

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require_relative '../checker/owners_list'

module Codeowners
  module Cli
    # Command Line Interface dealing with OWNERS generation and validation
    class OwnersListHandler < Base
      default_task :fetch

      FETCH_OWNER_MESSAGE = 'Fetching owners list from GitHub ...'
      ASK_GITHUB_ORGANIZATION = 'GitHub organization (e.g. github): '
      ASK_GITHUB_TOKEN = 'Enter GitHub token: '

      desc 'fetch [REPO]', 'Fetches .github/OWNERS based on github organization'
      def fetch(repo = '.')
        @repo = repo
        owners = owners_from_github
        Checker::OwnersList.persist!(repo, owners)
      end

      no_commands do
        def owners_from_github
          organization = config.default_organization
          organization = ask(ASK_GITHUB_ORGANIZATION) if organization.empty?
          token = ENV['GITHUB_TOKEN']
          token ||= ask(ASK_GITHUB_TOKEN, echo: false)
          puts FETCH_OWNER_MESSAGE
          Codeowners::GithubFetcher.get_owners(organization, token)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
codeowners-checker-1.1.2 lib/codeowners/cli/owners_list_handler.rb
codeowners-checker-1.1.1 lib/codeowners/cli/owners_list_handler.rb