From a99db1913d6cbe21b0d111a64c421b0442a924c5 Mon Sep 17 00:00:00 2001 From: Vivek Anand Date: Nov 16 2016 10:00:34 +0000 Subject: Add assignee support for github importer --- diff --git a/pagure_importer/utils/__init__.py b/pagure_importer/utils/__init__.py index 3efa188..099b793 100644 --- a/pagure_importer/utils/__init__.py +++ b/pagure_importer/utils/__init__.py @@ -124,26 +124,32 @@ def generate_json_for_github_issue_commentors(github_username, github_project_name): ''' Will create a json file containing details of all the user who have commented on or filed any issue in the given project + This also contains users who are assignee of an issue ''' github_obj = Github(github_username, github_password) otp_auth = get_auth_token(github_obj) github_obj = Github(otp_auth) project = github_obj.get_repo(github_project_name) - issue_commentors = [] + issue_commentors_assignees = [] for issue in project.get_issues(state='all'): - if issue.user.login not in issue_commentors: - issue_commentors.append(issue.user.login) + if issue.user.login not in issue_commentors_assignees: + issue_commentors_assignees.append(issue.user.login) click.echo('commentor added: ' + issue.user.login) + if issue.assignee and \ + issue.assignee.login not in issue_commentors_assignees: + issue_commentors_assignees.append(issue.assignee.login) + click.echo('assignee added: ' + issue.assignee.login) + for comment in project.get_issues_comments(): - if comment.user.login not in issue_commentors: - issue_commentors.append(comment.user.login) + if comment.user.login not in issue_commentors_assignees: + issue_commentors_assignees.append(comment.user.login) click.echo('commentor added: ' + comment.user.login) with open('issue_commentors.json', 'w') as f: - f.write(json.dumps(issue_commentors)) + f.write(json.dumps(issue_commentors_assignees)) return diff --git a/pagure_importer/utils/importer_github.py b/pagure_importer/utils/importer_github.py index 73a90cd..023f02e 100644 --- a/pagure_importer/utils/importer_github.py +++ b/pagure_importer/utils/importer_github.py @@ -23,6 +23,21 @@ class GithubImporter(): otp_auth = get_auth_token(self.github) self.github = Github(otp_auth) + def get_issue_assignee(self, github_issue): + ''' From the github issue object, return the + assignee of the issue if any ''' + + assignee = None + if github_issue.assignee: + assignee = models.User( + name=github_issue.assignee.login, + fullname=github_issue.assignee.name, + emails=[github_get_commentor_email( + github_issue.assignee.login)] + ) + + return assignee + def import_issues(self, repo_path, repo_folder, status='all'): ''' Imports the issues on github for the given project @@ -54,8 +69,9 @@ class GithubImporter(): close_status = 'Fixed' pagure_issue_created_at = github_issue.created_at.strftime('%s') - # Not sure how to deal with this atm - pagure_issue_assignee = None + + # Get the assignee of the issue + pagure_issue_assignee = self.get_issue_assignee(github_issue) if github_issue.labels: pagure_issue_tags = [i.name for i in github_issue.labels]