Class: Codeowners::GithubFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/codeowners/github_fetcher.rb

Overview

Fetch teams and members from GitHub and return them in list

Constant Summary collapse

GITHUB_URL =
'https://api.github.com'

Class Method Summary collapse

Class Method Details

.get_owners(github_org, authorization_token) ⇒ Array

Fetch teams and members from GitHub. authorization_token is GitHub PAT with read:org scope

Returns:

  • (Array)

    with GitHub teams and individuals belonging to a given GitHub organization



15
16
17
18
19
20
21
22
# File 'lib/codeowners/github_fetcher.rb', line 15

def get_owners(github_org, authorization_token)
  headers = get_headers(authorization_token)
  base_url = GITHUB_URL + '/orgs/' + github_org
  owners = []
  list_entities(base_url + '/teams', headers) { |team| owners << "@#{github_org}/#{team['slug']}" }
  list_entities(base_url + '/members', headers) { |member| owners << "@#{member['login']}" }
  owners
end