config_file = sys.argv[1] try: config = HaroldConfiguration(config_file) except Exception as e: print >> sys.stderr, "%s: failed to read config file %r: %s" % ( bin_name, config_file, e, ) sys.exit(1) # connect to db gh_config = GitHubConfig(config) db_config = DatabaseConfig(config) database = SalonDatabase(SynchronousDatabase(db_config)) # figure out which repos we care about repositories = gh_config.repositories_by_name.keys() if not repositories: print "No repositories to sync!" sys.exit(0) print "I will synchronize salon status for:" for repo in repositories: print " - " + repo print # get auth credentials username = raw_input("GitHub Username: ")
def main(): # config file is an expected argument bin_name = os.path.basename(sys.argv[0]) if len(sys.argv) != 2: print >> sys.stderr, "USAGE: %s INI_FILE" % bin_name sys.exit(1) config_file = sys.argv[1] try: config = HaroldConfiguration(config_file) except Exception as e: print >> sys.stderr, "%s: failed to read config file %r: %s" % ( bin_name, config_file, e, ) sys.exit(1) # quickly load up the flask app to create the tables if not already done print "Ensuring schema present..." os.environ["HAROLD_CONFIG"] = config_file import salon.app import salon.models print "done" print # connect to db gh_config = GitHubConfig(config) db_config = DatabaseConfig(config) database = SalonDatabase(SynchronousDatabase(db_config)) # figure out which repos we care about repositories = gh_config.repositories_by_name.keys() if not repositories: print "No repositories to sync!" sys.exit(0) print "I will synchronize salon status for:" for repo in repositories: print " - " + repo print # get auth credentials print print "Please enter a GitHub personal access token (found at Settings >>" print "Applications on GitHub) with the repo scope authorized" token = getpass.getpass("Token: ").strip() # set up an http session session = requests.session() session.auth = HTTPBasicAuth(token, "x-oauth-basic") session.verify = True session.headers["User-Agent"] = "Harold-by-@spladug" # query and sync the database for repo in repositories: print repo # synchronize pull requests pull_requests = itertools.chain( fetch_paginated(session, make_pullrequest_url(repo, "open")), fetch_paginated(session, make_pullrequest_url(repo, "closed")), ) for pull_request in pull_requests: print " %s#%s" % (repo, pull_request["number"]) database.process_pullrequest(pull_request, repository=repo) # synchronize comments for comment in fetch_paginated(session, make_comments_url(repo)): print " %s comment #%d" % (repo, comment["id"]) database.process_comment(comment)