def create_issue(gh_issue): "Create an Issue from a `github.Issue`." issue = Issue(key=str(gh_issue.number), title=gh_issue.title, state=gh_issue.state, opened=gh_issue.created_at, closed=gh_issue.closed_at, url=gh_issue.html_url) if gh_issue.assignee: issue.assignee = create_user(gh_issue.assignee) return issue.save()
def sync(types, verbose=False): importer = issue_importer() if 'users' in types: if verbose: print 'Synchronising users...' User.drop_collection() importer.import_users(verbose) if 'issues' in types: if verbose: print 'Synchronising issues...' Issue.drop_collection() importer.import_issues(verbose)
def create_issue_from_jira(jira_issue, verbose): "Creates a `githubsurvivor.models.Issue` from a `jira.resources.Issue`." try: return Issue.objects.get(key=jira_issue.key) except Issue.DoesNotExist: fields = jira_issue.fields issue = Issue(key = jira_issue.key, title = jira_issue.key, state = 'open', opened = iso8601.parse_date(fields.created), closed = None, url = jira_issue.self) if verbose: print 'created issue: %s' % issue.title return issue.save()
def create_update_issue_from_pull(gh_pull, jira_id, number, verbose): "Create an Issue from a `github.Pull`." commenters = [ ] for commenter in gh_pull['commenters']: commenters.append(create_user(commenter, verbose)) reviewers = [ ] for reviewer in gh_pull['reviewers']: reviewers.append(create_user(reviewer, verbose)) testers = [ ] for tester in gh_pull['testers']: testers.append(create_user(tester, verbose)) try: issue = Issue.objects.get(key=jira_id) if issue.state != gh_pull['state']: if verbose: print 'updating issue state to %s: JIRA %s, PR %s' % (gh_pull['state'], jira_id, number) issue.state = gh_pull['state'] issue.opened = gh_pull['created_at'] issue.closed = gh_pull['merged_at'] issue.url = gh_pull['html_url'] issue.assignee = create_user(gh_pull['user'], verbose) issue.merger = create_user(gh_pull['merged_by'], verbose) issue.commenters = commenters issue.reviewers = reviewers issue.testers = testers issue.save() return issue except Issue.DoesNotExist: issue = Issue(key = jira_id, title = jira_id, state = gh_pull['state'], opened = gh_pull['created_at'], closed = gh_pull['merged_at'], url = gh_pull['html_url'], assignee = create_user(gh_pull['user'], verbose), merger = create_user(gh_pull['merged_by'], verbose), commenters = commenters, reviewers = reviewers, testers = testers) if verbose: print 'created issue: JIRA %s, PR %s' % (jira_id, number) return issue.save()
def create_issue(jira_issue): "Creates a `githubsurvivor.models.Issue` from a `jira.resources.Issue`." fields = jira_issue.fields state = 'closed' if fields.resolution and fields.resolution.name in ('Finished', 'Fixed') else 'open' parse_date = lambda d: iso8601.parse_date(d) if d else None issue = Issue(key=jira_issue.key, title=fields.summary, state=state, opened=parse_date(fields.created), closed=parse_date(fields.resolutiondate), # TODO: we need the HTML URL, not the API URL url=jira_issue.self) if fields.assignee: issue.assignee = create_user(fields.assignee) return issue.save()
def issues(self): from githubsurvivor.models import Issue return Issue.objects(assignee=self)