def _get_github(): """ This grabs the dimagi github account and stores the state in a global variable. We do not store it in `env` or `DeployMetadata` so that it's possible to unpickle the `env` object without hitting the recursion limit. """ global global_github if global_github is not None: return global_github try: from .config import GITHUB_APIKEY except ImportError: print(( "You can add a GitHub API key to automate this step:\n" " $ cp {project_root}/config.example.py {project_root}/config.py\n" "Then edit {project_root}/config.py" ).format(project_root=PROJECT_ROOT)) username = input('Github username: '******'Github password: ') global_github = login( username=username, password=password, ) else: global_github = login( token=GITHUB_APIKEY, ) return global_github
def _authenticate_github_api(request): user = request.user if user and user.is_authenticated(): auth = user.social_auth.get(provider='github') return login(token=auth.access_token) return login(token=settings.SOCIAL_AUTH_GITHUB_SECRET)
def _get_github_client(credentials_file=os.path.expanduser('~/.gh-issue')): if not os.path.exists(credentials_file): user = raw_input('Enter github username: '******'Password for {0}: '.format(user)) auth = authorize( user, password, ['user', 'repo'], 'gh-issue', 'https://github.com/vmalloc/gh-issue', two_factor_callback=_read_two_factor_auth) logbook.debug('Got auth: {} ({})', auth.id, auth.token) with open(credentials_file, 'w') as fd: print(auth.token, file=fd) print(auth.id, file=fd) gh = login(token=auth.token) else: token = id = '' with open(credentials_file) as fd: token = fd.readline().strip() id = int(fd.readline().strip()) gh = login(token=token) #auth = gh.authorization(id) #auth.update(add_scopes=['repo:status', 'gist'], rm_scopes=['user']) return gh
def __init__(self, name, token=None, username=None, password=None): Repository.__init__(self, name) if token: github = login(token=token) else: github = login(username=username, password=password) self._repo = github.repository(*self.name.split('/', 1))
def login_loop(): logged_in = False while not logged_in: usr = input("GitHub username: "******"": print("Username cannot be blank") continue tfa = input("Do you have Two Factor Authentication enabled on Github? ") if 'y' in tfa.lower(): print( "Turns out it's impossible to get a non-web application to handle two factor authentication for github.") print("Please go to https://github.com/settings/tokens and generate a token to paste in here") token = input("Access Token: ") session = login(usr, token=token) else: pwd = getpass.getpass() if pwd == "": print("Password cannot be blank") continue session = login(usr, pwd) try: ghf = GitHubFav(session) logged_in = True except GitHubFav.NotLoggedInException: print("Login Credentials invalid!") print("Logged in!") return ghf
def login(username=None): token = configs.get_access_token() if token: log.info("Using access token authentication") return github3.login(token=token) else: username = username or configs.get_username() return github3.login(*read_login_info(username=username))
def get_connection(conf): credentials = CredentialsConfig(conf.site.credentials).github if "token" in credentials: gh = login(token=credentials.token) else: gh = login(credentials.username, credentials.password, two_factor_callback=collect_two_factor_token) return gh
def _github_login(token): """ Connect to github, using token in prod and login/password in dev. """ if settings.DEBUG and settings.GITHUB_USER_ID: return github3.login(settings.GITHUB_USER_ID, password=settings.GITHUB_USER_PASSWORD) return github3.login(token=token)
def get_github_repository(reponame, login=env.get('GITHUB_LOGIN', None), password=env.get('GITHUB_PASSWORD', None), key=env.get('GITHUB_KEY', None)): if login: g = github3.login(login, password) elif key: g = github3.login(token=key) else: g = github3.GitHub() return g.repository("elasticsearch", reponame)
def get_token_or_login(): # TODO: make the exception generate a token try: gh_token = GitHubAuthToken.objects.latest('created_at') gh = login(token=gh_token.token) logger.debug("Recovered gh token from db, used that to log in.") except GitHubAuthToken.DoesNotExist: logger.debug("GitHub Token not found, try running make_github_token") logger.info("Logging in to github but not saving token") gh = login(raw_input("username:"), password=getpass.getpass()) return gh
def weekly_organization_stats(organization_names, user=None, password=None, oauth_token=None, ignore_inactive_users=False, start_date=None): """Print weekly summary data for all repos in organizations.""" if oauth_token: github_client = github3.login(token=oauth_token) else: github_client = github3.login(user, password=password) weeks = {} ignore_before = None if start_date and len(start_date) == 10: ignore_before = arrow.get(start_date) for organization_name in organization_names: organization = github_client.organization(organization_name) for repo in organization.iter_repos(): print("Looking at %s/%s" % (organization_name, repo.name)) for contrib in repo.iter_contributor_statistics(): user = contrib.author.login for week_data in contrib.weeks: week = week_data['w'] if not week in weeks: weeks[week] = {} if user not in weeks[week]: weeks[week][user] = {'a': week_data['a'], 'c': week_data['c'], 'd': week_data['d']} else: weeks[week][user]['a'] += week_data['a'] weeks[week][user]['c'] += week_data['c'] weeks[week][user]['d'] += week_data['d'] for week in sorted(weeks.keys()): week_timestamp = arrow.get(week) if ignore_before and week_timestamp < ignore_before: continue print("\nWeek beginning %s" % week_timestamp.format('YYYY-MM-DD')) for user in sorted(weeks[week].keys()): user_data = weeks[week][user] contributions = [user_data['c'], user_data['a'], user_data['d']] if ignore_inactive_users and not any(contributions): continue row_format = " {:<20} {} commits (+{}, -{})" print row_format.format( user, user_data['c'], user_data['a'], user_data['d'])
def __init__(self, args): if args.user is not None: self._user = args.user while not self.__password: self.__password = getpass( 'Password for {0}: '.format(args.user) ) self._gh = login(args.user, password=self.__password) return if args.token is not None: self._gh = login(token=args.token) return raise Exception('neither user name nor token succeeded')
def __init__(self): if os.path.isfile('secret_key'): fn = open("secret_key") # Locally, with a secret_key file self.gh = login(token=fn.read().split()[0]) elif os.environ.get('GHUB_API_TOKEN'): # On Travis? (GHUB_API_TOKEN can be set...) self.gh = login(token=os.environ['GHUB_API_TOKEN']) else: # Or just use username/password method self.gh_name = input("Username to access github with:") pss = getpass.getpass(prompt='Ghub pswd {0}:'.format(self.gh_name)) self.gh = login(self.gh_name, pss) self.urls = [r.clone_url.split('.git')[0] for r in self.gh.iter_repos()]
def acquire_github_token_task(code, state): """ Given a temporary Github code and the OAuth flow state token, get an access token and persist it with the correct repos. """ response = requests.post( settings.GITHUB_OAUTH_TOKEN_URL, headers={'accept': 'application/json'}, data={ 'client_id': settings.GITHUB_OAUTH_CLIENT_ID, 'client_secret': settings.GITHUB_OAUTH_CLIENT_SECRET, 'code': code, 'redirect_uri': '', 'state': state } ) print response.status_code print response.content access_token = response.json()['access_token'] gh = login(token=access_token) for repo in gh.iter_user_repos(gh.user().login, 'owner'): full_name = repo.full_name try: Repo.objects.create(access_token=access_token, full_name=full_name) except IntegrityError: print('Repo {full_name} already has an access token!'.format(full_name=full_name))
def github_upload(artifacts, tag): """Upload the given artifacts to GitHub. Args: artifacts: A list of (filename, mimetype, description) tuples tag: The name of the release tag """ import github3 utils.print_title("Uploading to github...") token = read_github_token() gh = github3.login(token=token) repo = gh.repository('qutebrowser', 'qutebrowser') release = None # to satisfy pylint for release in repo.releases(): if release.tag_name == tag: break else: raise Exception("No release found for {!r}!".format(tag)) for filename, mimetype, description in artifacts: with open(filename, 'rb') as f: basename = os.path.basename(filename) asset = release.upload_asset(mimetype, basename, f) asset.edit(basename, description)
def __init__(self, ghtoken): # Get handle to Github API if ghtoken is not None and ghtoken != '': self.gh = login(token=ghtoken) else: log.warning('Using unauthenticated access to Github API. This will result in severe rate limiting.') self.gh = GitHub()
def validate_users(self): self.app.log.debug('Validating GitHub account names.') # validate required config parameters if not self.app.config.get('github', 'auth_token') or not self.app.config.get('github', 'auth_id'): raise error.ConfigError("Missing config parameter 'github.auth_id' and/or 'github.auth_token'! " "Please run 'scrum-tools github authorize' first! ") key_username = self.app.config.get('core', 'users_schema_key_username') key_github = self.app.config.get('core', 'users_schema_key_github') user_repository = data.UserRepository(self.app.config) gh = login(token=self.app.config.get('github', 'auth_token')) for u in user_repository.users(): if not u[key_github]: cprint("Skipping empty GitHub account for user '%s'." % u[key_username], 'yellow', file=sys.stdout) continue print colored("Validating GitHub account '%s' for user '%s'..." % (u[key_github], u[key_username]), 'green'), try: if gh.user(u[key_github]): print colored('OK', 'green', attrs=['bold']) else: raise RuntimeError("Github user '%s' not found" % u[key_github]) except RuntimeError: print colored('Not OK', 'red', attrs=['bold'])
def main(start_from=None): # Load config information load_config() # Connect to RabbitMQ Queue connection, channel = get_queue_channel(RABBIT_HOST) # Connect to databse client = MongoClient(MONGO_HOST, MONGO_PORT) db = client[MONGO_DB] db.authenticate(MONGO_USER, MONGO_PWD) db_repos = db[MONGO_COLL] last_id = start_from # Last id variable to be advanced reauth = True # Reauth variable to check if we need to reauthenticate for GitHub gh = None # Just for good measure while 1: # Authenticate on GitHub and get all repos if reauth: gh = github3.login(GH_USERS[GH_CUR_USR]['login'], GH_USERS[GH_CUR_USR]['pwd']) repos = gh.iter_all_repos(since=last_id) # Crawl repos reauth, last_id = start_crawl(repos, db_repos, gh, channel, last_id) #Close connection to databse client.close() #Close connection to queue channel.close() connection.close()
def set_github_status(repo, sha, token=None, integration_result=None, url=None, botname=None): import github3 if not token: token = github_auth() gh = github3.login(token=token) repo = repo.strip("/") (owner, reponame) = repo.split("/") r = gh.repository(owner, reponame) if not r: raise Exception("Trouble getting a repository for %s and %s" % (owner, reponame)) # these constants are documented on http://faq.sealedabstract.com/xcodeCI/ if not integration_result: xcs_status = os.environ["XCS_INTEGRATION_RESULT"] else: xcs_status = integration_result if xcs_status == "unknown": gh_state = "pending" elif xcs_status == "build-errors": gh_state = "error" elif xcs_status == "test-failures" or xcs_status == "warnings" or xcs_status == "analyzer-warnings" or xcs_status == "test-failures": gh_state = "failure" elif xcs_status == "succeeded": gh_state = "success" else: raise Exception("Unknown xcs_status %s. Please file a bug at http://github.com/drewcrawford/cavejohnson" % xcs_status) if not url: url = get_integration_url() if not botname: botname = get_botname() r.create_status(sha=sha, state=gh_state, target_url=url, description=botname)
def __init__(self): token = id = '' try: with open(CREDENTIALS_FILE, 'r') as fd: token = fd.readline().strip() id = fd.readline().strip() except IOError: print "No token found. Requesting new." user = getuser() password = '' while not password: password = getpass('Password for {0}: '.format(user)) note = 'Trac2Github app' note_url = 'https://www.github.com/atiti/trac2github' scopes = ['user', 'repo'] auth = github3.authorize(user, password, scopes, note, note_url) with open(CREDENTIALS_FILE, 'w') as fd: fd.write(auth.token + '\n') fd.write(str(auth.id)) token = auth.token id = str(auth.id) self.gh = github3.login(token=token) print "We are in!"
def setupssett(settings): from github3 import login, authorize from getpass import getpass user = '' password = '' while not user: print "GitHub user name (will be asked only the first time): ", user = raw_input() while not password: password = getpass('GitHub password for {0}: '.format(user)) note = 'h2ggit.py' note_url = 'http://cern.ch/cms' scopes = ['user', 'repo'] auth = authorize(user, password, scopes, note, note_url) fout = open(settings,"w+") settings = { "token" : auth.token, "id" : auth.id, "user" : user } fout.write( json.dumps(settings) ) fout.close() run("chmod 600 %s " % fout,name,"") return login(token=auth.token), settings
def moz_pad(path): ether_path = "https://public.etherpad-mozilla.org/p/{}".format(path) req = requests.get(ether_path + "/export/txt") gh = login('etherbrain', token=GH_TOKEN) r = gh.repository('etherpad-archive', 'etherpad-archive.github.io') contents = r.contents(path='moz') print(contents) fname = path + ".md" if contents is None or fname not in contents: # create it for the first time r.create_file("moz/{}.md".format(path), 'etherpad from {}'.format(ether_path), content=req.content) else: # update the file f = contents[fname] f.update('updated etherpad from {}'.format(ether_path), content=req.content) return Response( "Check out: http://etherpad-archive.github.io/moz/{}.md".format(path) )
def lambda_handler(event, context, debug=False): if debug: import os import sys sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'dependencies')) print(os.path.join(os.path.dirname(__file__), 'dependencies')) from github3 import login if 'Records' in event: # SNS if VERBOSE: event_type = event['Records'][0]['Sns']['MessageAttributes']['X-Github-Event']['Value'] print(event_type + ': ' + event['Records'][0]['Sns']['Message']) message = json.loads(event['Records'][0]['Sns']['Message']) else: # API message = event if VERBOSE: print('API: ' + json.dumps(event, indent=2)) action = message.get('action') if 'pull_request' not in message or action != 'opened': print('Action: {}. Contains pull_request object: {}'.format( action, 'pull_request' in message)) return pr_id = message['number'] author = message['pull_request']['user']['login'] target_repo_owner = message['pull_request']['base']['repo']['owner']['login'] target_repo = message['pull_request']['base']['repo']['name'] target_branch = message['pull_request']['base']['ref'] if target_repo_owner != config.repo_owner or target_repo != config.repo: print("Got event for unexpected repo {}/{}".format( target_repo_owner, target_repo)) return if target_branch != config.branch: print('PR is targetting {} branch, aborting'.format(target_branch)) return if author in config.ignore_login: print('Ignoring pull requests from {}'.format(author)) return if debug: print("DONE") return gh = login(config.user, password=config.token) issue = gh.issue(target_repo_owner, target_repo, pr_id) issue.create_comment(config.comment) print('Added comment to pull request {}'.format(pr_id))
def connect_to_github(): gh=login(username="******",password="******") repo = gh.repository("interface-","chapter7" ) branch=repo.branch("master") return gh,repo,branch
def callback(): logger = g.logger.getChild('callback') response.content_type = 'text/plain' code = request.query.code state = json.loads(request.query.state) lazy_debug(logger, lambda: 'state: {}'.format(state)) res = requests.post('https://github.com/login/oauth/access_token', data={ 'client_id': g.cfg['github']['app_client_id'], 'client_secret': g.cfg['github']['app_client_secret'], 'code': code, }) args = urllib.parse.parse_qs(res.text) token = args['access_token'][0] repo_label = state['repo_label'] repo_cfg = g.repo_cfgs[repo_label] repo = get_repo(repo_label, repo_cfg) user_gh = github3.login(token=token) if state['cmd'] == 'rollup': return rollup(user_gh, state, repo_label, repo_cfg, repo) elif state['cmd'] == 'synch': return synch(user_gh, state, repo_label, repo_cfg, repo) else: abort(400, 'Invalid command')
def get_code_convening_repo_stats(): stats = { 'projects': 0, 'contributors': 0, 'forks': 0, 'stars': 0, } # authenticate with GitHub gh = github3.login(token=GITHUB_CONFIG['TOKEN']) for url in GITHUB_REPOS: url_bits = url.split('/') repo_name = url_bits[-1] repo_owner = url_bits[-2] r = requests.get('https://api.github.com/repos/{0}/{1}?access_token={2}'.format(repo_owner, repo_name, GITHUB_CONFIG['TOKEN'])) data = r.json() if data: stats['projects'] += 1 if 'forks' in data: stats['forks'] += data['forks'] if 'stargazers_count' in data: stats['stars'] += data['stargazers_count'] if 'contributors_url' in data: r = requests.get('{0}?access_token={1}'.format(data['contributors_url'], GITHUB_CONFIG['TOKEN'])) stats['contributors'] += len(r.json()) return stats
def connect_to_github(): print "[*] connect_to_github" gh = login(username="******", password="") repo = gh.repository("sedew810225","chapter7") branch = repo.branch("master") return gh,repo,branch
def test_login(self): args = ('login', 'password', None, None) with mock.patch.object(github3.api.GitHub, 'login') as login: g = github3.login(*args) assert isinstance(g, github3.github.GitHub) assert not isinstance(g, github3.github.GitHubEnterprise) login.assert_called_with(*args)
def connect_to_github(): gh = login(username="", password="") repo = gh.repository("", "") branch = repo.branch("master") return gh, repo, branch
def run_csv(): # Exporta estatísticas de um repositório em formato CSV output_csv = csv.writer(open(csv_name, 'wb'), delimiter=',') github = github3.login(username=git_username, token=git_api_token) # csv headers headers = [ 'author', 'total', 'Start of the Week', 'Deletions', 'Additions', 'Commits', ] # escreve header rows output_csv.writerow(headers) # baixa estatísticas do repositório e transcreve para csv git_stats = github.repository("gems-uff", "noworkflow").iter_contributor_statistics() for git_stat in git_stats: for git_week in git_stat.alt_weeks: commit = [ git_stat.author, git_stat.total, git_week['start of week'], git_week['deletions'], git_week['additions'], git_week['commits'], ] output_csv.writerow(commit)
def get_github_client(token=None): ghc = github3.login(token=token or settings.GITHUB_TOKEN) assert ghc.__class__ == github3.github.GitHub ghc.__class__ = GitHub return ghc
def login(): """GitHub login as decorator so a pool can be implemented later.""" yield github3.login(token=config.GITHUB_TOKEN)
def main(): parser = argparse.ArgumentParser() parser.add_argument('filename', help='Relative path of file to track history of (ex. "README")') parser.add_argument( '--repo', '-r', dest='repo', default=os.getcwd(), help='Override path to repository (defaults to current working directory)', ) parser.add_argument( '--no-color', dest='nocolor', action='store_true', help='Do not use colors (default if output is redirected)', ) args = parser.parse_args() args.quiet = Quietness.ONE_LINE_SUMMARY if not args.nocolor: colorama_init(autoreset=True) repo = pygit2.Repository(args.repo) password = None password_command = None try: username = repo.config['staredown.githubusername'] try: password = repo.config['staredown.githubpassword'] except KeyError: password_command = repo.config['staredown.githubpasswordcmd'] except KeyError: panic(ERR_NO_GH_CREDS) if not password and password_command: try: pw = subprocess.run(password_command, shell=True, check=True, stdout=subprocess.PIPE) except subprocess.CalledProcessError: panic('Did not receive GitHub password from `githubpasswordcmd`!') gh = github3.login(username, pw.stdout.strip()) else: gh = github3.login(username, password) github_remotes = extract_github_remotes(repo) if not github_remotes: panic('No GitHub remotes seem to be configured for specified git repository {}'.format(args.repo)) head_commit = repo.head.get_object() commit_ids = all_commits_where_file_changed(repo, args.filename, head_commit) if not commit_ids: panic('File has never existed in visible repository history (starting from HEAD)') for gh_remote in github_remotes: gh_repo = gh.repository(*gh_remote.split('/')) for pull in gh_repo.iter_pulls(state='all'): # Sometimes commit IDs change when getting pulled into the repo, # so we need to scan for the PR's resulting commit sha as well shas = {x.sha for x in pull.iter_commits()} shas.add(pull.merge_commit_sha) found_shas = shas.intersection(commit_ids) if found_shas: for line in format_discovered_pr(gh_remote, found_shas, pull, args): print(line)
def main(): rain_version = load_cargo_version() print("Rain version:", rain_version) if len(sys.argv) != 2 or sys.argv[1] not in ["release", "nightly"]: sys.stderr.write("Usage: make_release.py [release|nightly]\n") return if sys.argv[1] == "release": info = BasicRelease(rain_version) else: print("Building NIGHTLY version") info = NighlyRelease(rain_version) print("Relase version:", info.version) print("Git commit:", info.git_commit) dist_env = os.environ.copy() dist_env["RAIN_VERSION"] = info.version os.chdir(RAIN_ROOT) subprocess.check_call(("cargo", "build", "--release")) os.chdir(os.path.join(RAIN_ROOT, "python")) shutil.rmtree("dist") # Remove dist in python dir (create by setup.py) shutil.rmtree("rain.egg-info") shutil.rmtree("build") subprocess.check_call(("python3", "setup.py", "bdist_wheel"), env=dist_env) dist_files = list(os.listdir("dist")) assert len(dist_files) == 1 wheel = dist_files[0] wheel_path = os.path.join(RAIN_ROOT, "python", "dist", wheel) print("Wheel:", wheel) if os.path.isdir(BUILD_DIR): print("Removing old build dir", BUILD_DIR) shutil.rmtree(BUILD_DIR) print("Creating new build dir", BUILD_DIR) os.makedirs(BUILD_DIR) release_dir = os.path.join(BUILD_DIR, info.dist_name) os.makedirs(release_dir) print("Copying binary") subprocess.check_call(("cp", os.path.join(RAIN_ROOT, "target", "release", "rain"), os.path.join(release_dir, "rain"))) print("Creating archieve") tarball = info.dist_name + ".tar.xz" tarball_path = os.path.join(BUILD_DIR, tarball) subprocess.check_call(("tar", "cvJf", tarball, info.dist_name), cwd=BUILD_DIR) print("Publishing") login = input("Github login:"******"Github password:"******"substantic", "rain") release = repo.create_release( info.tag_name, "master", info.release_name, info.description, prerelease=info.prerelease) with open(tarball_path, "rb") as f: release.upload_asset("application/x-xz", tarball, f.read()) with open(wheel_path, "rb") as f: release.upload_asset("application/zip", wheel, f.read())
def connect_to_github(): gh = login(username=u_name, password=u_pass) repo = gh.repository(u_name, u_repo) branch = repo.branch(u_branch) return gh, repo, branch
slack_object = Slacker(slack_token) if len(sys.argv) >= 4: s3_access_key = sys.argv[2] s3_secret_key = sys.argv[3] s3_connection = tinys3.Connection(s3_access_key, s3_secret_key, tls=True) if len(sys.argv) >= 6: windows_key = sys.argv[4] windows_key_password = sys.argv[5] if len(sys.argv) >= 8: github_user = sys.argv[6] github_pass = sys.argv[7] # Login and get "GitHub" object gh = login(github_user, github_pass) repo = gh.repository("OpenShot", "openshot-qt") # Start log output("%s Build Log for %s" % (platform.system(), datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))) # Loop through projects for project_path, cmake_args in project_paths: # Change os directory os.chdir(project_path) # Get number of commits for line in run_command("git rev-list --count master"): commit_data[project_path] = int(line)
import argparse import github3 import migrate import json import time migrate.read_config() cfg = migrate.cfg orgs = [ 'tungstenfabric-preview', 'tungstenfabric-tools-preview', 'tungstenfabric-infra-preview' ] gh = github3.login(cfg['github_login'], password=cfg['github_password']) def create_repo(org, name, dry_run=True): print('Creating new repo: {}/{}'.format(org, name), 'DRY_RUN' if dry_run else '') if not dry_run: org = gh.organization(org) for repo in org.repositories(): if repo.name == name: print('Repo', repo.full_name, 'already exists') return org.create_repository(name) def create_repos(repos, dry_run=True): for repo in repos: create_repo(repo.new_org, repo.new_name, dry_run)
def connect_github(): gh = login(username="******", password="******") repo = gh.repository("advancenetprog", "practicumcase") brach = repo.brach("master") return gh, repo, brach
def main(): parser = create_parser() args = parser.parse_args() runner_id = args.ID config = args.config credentials = config["credentials"] repo = config["repository"] tasks_path = config["tasks_file"] whitelist = config["whitelist"] no_task_backoff_time = config["no_task_backoff_time"] logging.config.dictConfig(config["logging"]) exit_handler = ExitHandler() signal.signal(signal.SIGINT, exit_handler.finish) signal.signal(signal.SIGTERM, exit_handler.abort) gh = github3.login(token=credentials["token"]) session = util.create_session(util.make_headers(credentials["token"])) do_request = partial(util.perform_request, session=session) world = World(graphql_request=do_request, github_api=gh, session=session, repo_owner=repo["owner"], repo_name=repo["name"], runner_id=runner_id, tasks_path=tasks_path, whitelist=whitelist) while not exit_handler.done: world.check_graphql_limit() try: response = do_request(query=queries.make_pull_requests_query( world.repo_owner, world.repo_name)) except EnvironmentError as e: logger.error(e) sys.exit(1) data = util.get_data(response) repo = util.get_repository(data) repo_url = util.get_repository_url(repo) pull_requests_data = util.get_pull_requests(repo) pull_requests = sorted( (PullRequest.from_dict(pr_data) for pr_data in pull_requests_data), key=lambda pr: not pr.prioritized) for pull_request in pull_requests: for task in process_pull_request(world, pull_request, repo_url): exit_handler.register_task(task) world.available_resources.take(task) logger.info("Available resources: %s", world.available_resources) try: task.execute(world, pull_request.commit.statuses) except ReferenceError as e: logger.warning(e) except (EnvironmentError, RuntimeError) as e: logger.error(e) sentry_report_exception({"module": "github"}) sleep(ERROR_BACKOFF_TIME) finally: exit_handler.unregister_task() world.available_resources.give(task) logger.info("Available resources: %s", world.available_resources) sleep(no_task_backoff_time)
from github3 import login from os import environ GITHUB_USER = environ['GITHUB_USER'] GITHUB_PASSWORD = environ.get('GITHUB_PASSWORD') GITHUB_TOKEN = environ.get('GITHUB_TOKEN') if GITHUB_TOKEN is None and GITHUB_PASSWORD is None: raise ValueError('GITHUB_TOKEN or GITHUB_PASSWORD have to be set') ghclient = login(username=GITHUB_USER, password=GITHUB_PASSWORD, token=GITHUB_TOKEN) def get_organisation_repos(organisation): organisation = filter(lambda org: org.login == organisation, ghclient.iter_orgs()).__next__() repositories = list(organisation.iter_repos()) repositories = map(lambda repo: repo.ssh_url, repositories) return list(repositories) if __name__ == '__main__': get_organisation_repos('upday')
def connect_to_github(): gh = login(username="******", password="******") repo = gh.repository("HejunweiCoder", "ControlCenter") branch = repo.branch("master") return gh, repo, branch
def connect_to_github(): gh = login(username="******", password="******") repo = gh.repository("kHigasa", "kiddies") branch = repo.branch("master") return gh, repo, brnach
def main(): """Main.""" parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description=__doc__) addStandardArguments(parser) parser.add_argument('--ldd_output_path', help='directory to output generated LDDs', required=True) parser.add_argument('--ingest_ldd_src_dir', help='/path/to/src/ dir for IngestLDD file', default=os.path.join('tmp', 'logs'), required=True) parser.add_argument('--dev', help='flag to indicate this is a dev release', action='store_true', default=False) parser.add_argument('--token', help='github token') parser.add_argument('--repo_name', help='full name of github repo (e.g. user/repo)') parser.add_argument( '--workspace', help=( 'path of workspace. defaults to current working directory if this ' 'or GITHUB_WORKSPACE not specified')) parser.add_argument('--pds4_version', help='pds4 IM version') args, unknown = parser.parse_known_args() logging.basicConfig(level=args.loglevel, format="%(levelname)s %(message)s") if args.loglevel != logging.DEBUG: # Quiet github3 logging logging.getLogger('github3').setLevel(level=logging.WARNING) token = args.token or os.environ.get('GITHUB_TOKEN') if not token: _logger.error( 'Github token must be provided or set as environment variable (GITHUB_TOKEN).' ) sys.exit(1) repo_full_name = args.repo_name or os.environ.get('GITHUB_REPOSITORY') if not repo_full_name: _logger.error( 'Github repository must be provided or set as environment variable (GITHUB_REPOSITORY).' ) sys.exit(1) org = repo_full_name.split('/')[0] repo_name = repo_full_name.split('/')[1] workspace = args.workspace or os.environ.get('GITHUB_WORKSPACE') if not workspace: workspace = os.getcwd() os.environ['GITHUB_WORKSPACE'] = workspace try: ingest_ldd, namespace_id, ldd_version = get_info( args.ingest_ldd_src_dir) ldd_dict = find_ldds(args.ldd_output_path, namespace_id, ldd_version, args.pds4_version) assets = package_assets(ingest_ldd, ldd_dict, namespace_id) tagger = {"name": "PDSEN CI Bot", "email": "*****@*****.**"} gh = github3.login(token=token) repo = gh.repository(org, repo_name) delete_snapshot_releases(repo, SNAPSHOT_TAG_SUFFIX) for release_name in ldd_dict.keys(): if 'dependencies' not in release_name: if args.dev: tag_name = release_name + SNAPSHOT_TAG_SUFFIX else: tag_name = release_name # Check tag exists before continuing tags = Tags(org, repo_name, token=token) if not tags.get_tag(tag_name): release = create_release(repo, "main", tag_name, tagger, args.dev) _logger.info("upload assets") ldd_upload_assets(release, assets) else: _logger.warning( f"tag {tag_name} already exists. skipping...") except Exception: traceback.print_exc() sys.exit(1) _logger.info('SUCCESS: LDD release complete.')
import os import github3 MAIN_BRANCH = 'gh-pages' GITHUB_TOKEN = os.environ['GITHUB_TOKEN'] GITHUB_REPOSITORY_ID = os.environ['GITHUB_REPOSITORY_ID'] with open('index.html') as f: index_file = f.read() with open('api.json') as f: api_file = f.read() # Connect to GitHub API and push the changes. github = github3.login(token=GITHUB_TOKEN) repository = github.repository_with_id(GITHUB_REPOSITORY_ID) github_index = repository.file_contents('/index.html', ref=MAIN_BRANCH) github_api = repository.file_contents('/api.json', ref=MAIN_BRANCH) pushed_index_change = github_index.update('Bump front version', index_file.encode('utf-8'), branch=MAIN_BRANCH) print("Pushed commit {} to {} branch:\n {}".format( pushed_index_change['commit'].sha, MAIN_BRANCH, pushed_index_change['commit'].message, )) pushed_api_change = github_api.update('Bump API version',
def login(self): try: return github3.login(self.user, self.token) except github3.models.GitHubError as e: print "Failed to login due to {}".format(e) return None
def main(): module = AnsibleModule( argument_spec=dict( repo=dict(required=True), user=dict(required=True), password=dict(no_log=True), token=dict(no_log=True), action=dict(required=True, choices=['latest_release', 'create_release']), tag=dict(type='str'), target=dict(type='str'), name=dict(type='str'), body=dict(type='str'), draft=dict(type='bool', default=False), prerelease=dict(type='bool', default=False), ), supports_check_mode=True, required_one_of=(('password', 'token'), ), mutually_exclusive=(('password', 'token'), ), required_if=[('action', 'create_release', ['tag'])], ) if not HAS_GITHUB_API: module.fail_json(msg='Missing required github3 module (check docs or ' 'install with: pip install github3.py==1.0.0a4)') repo = module.params['repo'] user = module.params['user'] password = module.params['password'] login_token = module.params['token'] action = module.params['action'] tag = module.params.get('tag') target = module.params.get('target') name = module.params.get('name') body = module.params.get('body') draft = module.params.get('draft') prerelease = module.params.get('prerelease') # login to github try: if user and password: gh_obj = github3.login(user, password=password) elif login_token: gh_obj = github3.login(token=login_token) # test if we're actually logged in gh_obj.me() except github3.AuthenticationFailed as e: module.fail_json(msg='Failed to connect to GitHub: %s' % to_native(e), details="Please check username and password or token " "for repository %s" % repo) repository = gh_obj.repository(user, repo) if not repository: module.fail_json(msg="Repository %s/%s doesn't exist" % (user, repo)) if action == 'latest_release': release = repository.latest_release() if release: module.exit_json(tag=release.tag_name) else: module.exit_json(tag=None) if action == 'create_release': release_exists = repository.release_from_tag(tag) if release_exists: module.exit_json(changed=False, msg="Release for tag %s already exists." % tag) release = repository.create_release(tag, target, name, body, draft, prerelease) if release: module.exit_json(changed=True, tag=release.tag_name) else: module.exit_json(changed=False, tag=None)
import github3 import logging from anton.modules.tickets import TicketProvider, TicketProviderErrorResponse try: GITHUB_CHANNEL = config.GITHUB_CHANNEL except AttributeError: GITHUB_CHANNEL = "#twilightzone" GITHUB_AUTH_TOKEN = None GITHUB_DEFAULT_ORGANIZATION = None GITHUB_DEFAULT_REPO = None try: GITHUB_AUTH_TOKEN = config.GITHUB_AUTH_TOKEN gh = github3.login(token=GITHUB_AUTH_TOKEN) GITHUB_DEFAULT_ORGANIZATION = config.GITHUB_DEFAULT_ORGANIZATION GITHUB_DEFAULT_REPO = config.GITHUB_DEFAULT_REPO except AttributeError: pass class GitHubTicketProvider(TicketProvider): def __init__(self): if GITHUB_AUTH_TOKEN is None: raise TicketProviderErrorResponse( "No value for config.GITHUB_AUTH_TOKEN, no !ticket for you :(") def _format_searchresult(self, result): issue = result.issue
def login(token: str) -> Repository: import github3 github = github3.login(token=token) owner, repo = SLUG.split("/") return github.repository(owner, repo)
def connect_to_github(): gh = login(username="******", password="******") repo = gh.repository("blackhatpythonbook", "chapter7") branch = repo.branch("master") return gh, repo, branch
# py 3.3 #imp.reload(module) # frida import frida devices = frida.enumerate_devices() # github import github3 user = '******' repo = 'test' gh_client = github3.login(token=os.environ['GITHUB_TOKEN']) repo = gh_client.repository(owner='chillara nand', repository='test') issues = repo.iter_issues(state='all') r = repo.create_issue(title="aa", body="bb") # jira # matplotlib # In[2]: data = [ '2008 70372 332383', '2009 394567 1188382',
import github3 import re, sys, time, getpass from string import strip gh_user = raw_input("User: "******"http(s)?://.*github.com/(?P<owner>[\w.-]+)/(?P<repo>[\w.-]+)", line) if m: # Obtain the project name owner = m.group('owner') repo = m.group('repo') # Get star number of project r = gh.repository(owner, repo) stars = r.stargazers # Print out the result print >> output_file, "{} [**{:,}**]".format(strip(line), stars) print "{} [**{:,}**]".format(strip(line), stars) # Throttle the speed
# under the terms of the MIT License; see LICENSE file for more details. from .repos import check_repo, fetch_repo_info from .project_info import fetch_repo_maintainers import sys import yaml import click from github3 import login, repository from dotenv import load_dotenv import os import time load_dotenv() token = os.getenv('GH_TOKEN') GH_CLIENT = login(token=token) @click.command(context_settings=dict(help_option_names=['-h', '--help'])) @click.option('--project', default='inveniosoftware', help='Related project (default=inveniosoftware).') @click.option('--repos', multiple=True, help='The repositories to check for notifications.') @click.option('--maintainers', multiple=True, help='The maintainers to notify.') @click.option('--count', default=-1, help='How many repositories to check.') def main(project, repos, maintainers, count): tstart = time.time()
versionNumber = str(time.time()) if (platform != ''): version = 'qtox-'+platform+'-'+versionNumber else: version = 'qtox-'+versionNumber if (platform == 'windows'): title = 'qTox Windows '+datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S') elif (platform == 'linux'): title = 'qTox Linux '+datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S') else: title = 'qTox '+datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S') user = "******" password = "" if password == "": password = getpass('GitHub password for {0}: '.format(user)) # Obviously you could also prompt for an OAuth token if not (user and password): print("Cowardly refusing to login without a username and password.") sys.exit(1) g = login(user, password) repo = g.repository('tux3', 'qTox') release = repo.create_release(version,'master',title,'This is an automated release of qTox, published by qTox\'s continous integration server.',False,False) if (len(sys.argv) >= 2): file = open(sys.argv[1], 'r') release.upload_asset('application/octet-stream',sys.argv[1],file)
def connect_to_github(): gh = login(token=TOKEN) repo = gh.repository('zelttu', 'statifier') branch = repo.branch("master") return gh, repo, branch
def account_info(remote, resp): """ Retrieve remote account information used to find local user. """ gh = github3.login(token=resp['access_token']) ghuser = gh.user() # return dict(email=ghuser.email, nickname=ghuser.login) return dict(email=ghuser.email, nickname=ghuser.email)
#!/usr/bin/env python3 import github3 from urllib.parse import urlparse import sys import os import time gh = github3.login(token=os.getenv("GH_API_TOKEN")) tpl = open("issue-template.txt").read() repo = sys.argv[1] try: path = urlparse(repo).path[1:].strip().split("/") if path[1].endswith(".git"): path[1] = path[1][:-4] r = gh.repository(path[0], path[1]) contribs = "\n".join( map(lambda u: " - [ ] @{}".format(u.login), r.iter_contributors())) issue_body = tpl.replace("{{project_name}}", path[1]) + "\n" + contribs r.create_issue("Relicense under dual MIT/Apache-2.0", body=issue_body) print("Done {}".format(repo)) except Exception as e: print("Some exception in {}".format(repo)) print(e)
for line in patch.text.split("\n"): try: lead = list(line)[0] if list(line)[0] == "+" and list(line)[1] != "+": line = line[1:] xml.write(line) xml.write("<br>\n") except Exception: continue xml.write(' ]]></description>') xml.write("\n</item>\n") xml.write("\n</channel>\n</rss>\n") xml.close() # Connect to GitHub API and push the changes. github = github3.login(token=os.environ['TOKEN']) repository = github.repository(owner, 'BoSK-Watch') with open('feed.xml', 'rb') as fd: contents = fd.read() contents_object = repository.file_contents('feed.xml') push_status = contents_object.update('automatic', contents) print(push_status)
def get_github3_client(self): token = self.get_auth_token() gh = github3.login(token=token) gh.set_user_agent(self.app.useragent) return gh
def get_repository(owner, repository, token): session = github3.login(token=token) return session.repository(owner=owner, repository=repository)
def main(): logger = logging.getLogger('homu') logger.setLevel(logging.INFO) logger.addHandler(logging.StreamHandler()) with open('cfg.toml') as fp: cfg = toml.loads(fp.read()) gh = github3.login(token=cfg['main']['token']) states = {} repos = {} repo_cfgs = {} buildbot_slots = [''] my_username = gh.user().login queue_handler = lambda: process_queue(states, repos, repo_cfgs, logger, cfg, buildbot_slots) logger.info('Retrieving pull requests...') for repo_cfg in cfg['repo']: repo = gh.repository(repo_cfg['owner'], repo_cfg['repo']) states[repo.name] = {} repos[repo.name] = repo repo_cfgs[repo.name] = repo_cfg for pull in repo.iter_pulls(state='open'): status = '' for info in utils.github_iter_statuses(repo, pull.head.sha): if info.context == 'homu': status = info.state break state = PullReqState(pull.number, pull.head.sha, status, repo) state.title = pull.title state.body = pull.body state.head_ref = pull.head.repo[0] + ':' + pull.head.ref state.base_ref = pull.base.ref state.assignee = pull.assignee.login if pull.assignee else '' for comment in pull.iter_comments(): if comment.original_commit_id == pull.head.sha: parse_commands( comment.body, comment.user.login, repo_cfg['reviewers'], state, my_username, sha=comment.original_commit_id, ) for comment in pull.iter_issue_comments(): parse_commands( comment.body, comment.user.login, repo_cfg['reviewers'], state, my_username, ) states[repo.name][pull.number] = state logger.info('Done!') server.start(cfg, states, queue_handler, repo_cfgs, repos, logger, buildbot_slots, my_username) Thread(target=fetch_mergeability, args=[states, repos]).start() queue_handler()