Example #1
0
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
Example #2
0
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
Example #3
0
def create_user(jira_user):
    "Creates a `survivor.models.User` from a `jira.resources.User`."
    user = User(login=jira_user.name)
    user.name = jira_user.displayName
    user.email = jira_user.emailAddress
    user.avatar_url = jira_user.avatarUrls.__dict__["48x48"]

    return user.save()
Example #4
0
def create_user(github_user):
    "Creates a `survivor.models.User` from a `github.NamedUser`."
    user = User(github_id=github_user.id)
    for k in ('login', 'name', 'email', 'avatar_url', 'gravatar_id'):
        setattr(user, k, getattr(github_user, k))
    return user.save()