def run(dry_run): base_url = os.environ.get('GITHUB_API', 'https://api.github.com') desired_state = fetch_desired_state() for github_org_name, desired_github_usernames in desired_state.items(): config = get_config(desired_org_name=github_org_name) token = config['github'][github_org_name]['token'] gh = Github(token, base_url=base_url) raw_gh = RawGithubApi(token) gh_org = gh.get_organization(github_org_name) gh_org_members = gh_org.get_members(role='admin') current_github_usernames = [m.login for m in gh_org_members] invitations = raw_gh.org_invitations(github_org_name) current_github_usernames.extend(invitations) current_github_usernames = \ [m.lower() for m in current_github_usernames] desired_github_usernames = \ [m.lower() for m in desired_github_usernames] for github_username in desired_github_usernames: if github_username not in current_github_usernames: logging.info(['add_owner', github_org_name, github_username]) if not dry_run: gh_user = gh.get_user(github_username) gh_org.add_to_members(gh_user, 'admin')
def _initiate_github(self, saas_file): auth = saas_file.get('authentication') or {} auth_code = auth.get('code') or {} if auth_code: token = secret_reader.read(auth_code, settings=self.settings) else: config = get_config() github_config = config['github'] token = github_config['app-sre']['token'] base_url = os.environ.get('GITHUB_API', 'https://api.github.com') return Github(token, base_url=base_url)
def _initiate_github(self, saas_file): auth = saas_file.get('authentication') or {} auth_code = auth.get('code') or {} if auth_code: token = self.secret_reader.read(auth_code) else: # use the app-sre token by default default_org_name = 'app-sre' config = get_config(desired_org_name=default_org_name) token = config['github'][default_org_name]['token'] base_url = os.environ.get('GITHUB_API', 'https://api.github.com') return Github(token, base_url=base_url)
def _initiate_github(self, saas_file): auth = saas_file.get('authentication') or {} auth_code = auth.get('code') or {} if auth_code: token = self.secret_reader.read(auth_code) else: # use the app-sre token by default default_org_name = 'app-sre' config = get_config(desired_org_name=default_org_name) token = config['github'][default_org_name]['token'] base_url = os.environ.get('GITHUB_API', 'https://api.github.com') # This is a threaded world. Let's define a big # connections pool to live in that world # (this avoids the warning "Connection pool is # full, discarding connection: api.github.com") pool_size = 100 return Github(token, base_url=base_url, pool_size=pool_size)
def run(dry_run): base_url = os.environ.get("GITHUB_API", "https://api.github.com") config = get_config() desired_state = fetch_desired_state() for github_org_name, desired_github_usernames in desired_state.items(): token = config["github"][github_org_name]["token"] gh = Github(token, base_url=base_url) raw_gh = RawGithubApi(token) gh_org, current_github_usernames = get_current_github_usernames( github_org_name, gh, raw_gh) current_github_usernames = [ m.lower() for m in current_github_usernames ] desired_github_usernames = [ m.lower() for m in desired_github_usernames ] for github_username in desired_github_usernames: if github_username not in current_github_usernames: logging.info(["add_owner", github_org_name, github_username]) if not dry_run: gh_user = gh.get_user(github_username) gh_org.add_to_members(gh_user, "admin")
def init_github(bot_token_org_name): base_url = os.environ.get('GITHUB_API', 'https://api.github.com') config = get_config(desired_org_name=bot_token_org_name) token = config['github'][bot_token_org_name]['token'] return Github(token, base_url=base_url)
def init_github(): config = get_config() github_config = config['github'] token = github_config['app-sre']['token'] return Github(token)
def init_github(): config = get_config() github_config = config['github'] token = github_config['app-sre']['token'] return Github(token, base_url=GH_BASE_URL)