Exemple #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
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
Exemple #3
0
def create_issue(github_issue):
    "Creates a `survivor.models.Issue` from a `github.Issue`."
    params = {}

    for issue_attr, github_attr in issue_attr_map.items():
        # Make all attribues as list of attributes
        if not isinstance(github_attr, list):
            github_attr = [github_attr]

        if issue_attr == 'labels':
            labels = getattr(github_issue, 'labels')
            value = [label.name for label in labels]
        else:
            # Drill done through each attribute in the order given
            value = github_issue
            for attr in github_attr:
                if value:
                    value = getattr(value, attr)
        params[issue_attr] = value

    issue = Issue(**params)

    issue.reporter = get_or_create_user(github_issue.user)
    if github_issue.assignee:
        issue.assignee = get_or_create_user(github_issue.assignee)

    # TODO comments, labels

    return issue.save()
def create_issue(github_issue):
    "Creates a `survivor.models.Issue` from a `github.Issue`."
    issue = Issue(**dict((issue_attr, getattr(github_issue, github_attr))
                         for issue_attr, github_attr in issue_attr_map.items()))

    issue.reporter = get_or_create_user(github_issue.user)
    if github_issue.assignee:
        issue.assignee = get_or_create_user(github_issue.assignee)

    # TODO comments, labels

    return issue.save()
Exemple #5
0
def create_issue(jira_issue):
    "Creates a `survivor.models.Issue` from a `jira.resources.Issue`."
    issue = Issue(
        key=jira_issue.key,
        title=jira_issue.fields.description,
        state=jira_issue.fields.status.name.lower(),
        opened=iso8601.parse_date(jira_issue.fields.created),
        updated=iso8601.parse_date(jira_issue.fields.updated),
        url=jira_issue.self,
    )

    if jira_issue.fields.reporter is not None:
        issue.reporter = get_or_create_user(jira_issue.fields.reporter)
    else:
        issue.reporter = get_or_create_user(jira_issue.fields.assignee)

    if jira_issue.fields.resolutiondate:
        issue.closed = iso8601.parse_date(jira_issue.fields.resolutiondate)
        resolution_type = jira_issue.fields.resolution.name
        issue.finished_or_fixed = resolution_type == "Finished" or resolution_type == "Fixed"

    if jira_issue.fields.assignee:
        issue.assignee = get_or_create_user(jira_issue.fields.assignee)

    # TODO comments, labels

    return issue.save()