def sync(types, verbose=False): "Refresh selected collections from JIRA." jira_project = config["jira.project"] jira_username = config["jira.username"] jira_password = config["jira.password"] jira_server = config["jira.server"] jira = JIRA(basic_auth=(jira_username, jira_password), options={"server": jira_server}) if "users" in types: User.drop_collection() # FIXME: can this come from config? for jira_user in jira.search_assignable_users_for_projects("", jira_project): try: user = create_user(jira_user) except: print "Error creating user: %s" % jira_user.name raise if verbose: print "created user: %s" % jira_user.name if "issues" in types: Issue.drop_collection() issues = jira.search_issues( "project=%s and (status=OPEN or status=CLOSED)" % jira_project, maxResults=MAX_ISSUE_RESULTS ) for jira_issue in issues: try: issue = create_issue(jira_issue) except: print "Error creating %s" % jira_issue.key raise if verbose: print "created issue: %s" % jira_issue.key
def sync(types, verbose=False): "Refresh selected collections from GitHub." auth_token = config['github.oauth_token'] account_name, repo_name = config['github.repo'].split('/') account = github.Github(auth_token).get_user(account_name) if 'users' in types: User.drop_collection() # FIXME: can this come from config? for github_user in account.get_repo('contests').get_collaborators(): try: user = create_user(github_user) except: print 'Error creating user: %s' % github_user raise if verbose: print 'created user: %s' % user.login if 'issues' in types: Issue.drop_collection() repo = account.get_repo(repo_name) issues = itertools.chain(repo.get_issues(state='open'), repo.get_issues(state='closed')) for gh_issue in issues: try: issue = create_issue(gh_issue) except: print 'Error creating %s' % gh_issue raise if verbose: print 'created issue: %s' % issue.title