|
1 | | -from github import Github, Repository, GithubException |
2 | 1 | import csv |
3 | 2 |
|
| 3 | +from github import Github, Repository, GithubException, PullRequest |
| 4 | + |
4 | 5 | EMPTY_FIELD = 'Empty field' |
5 | 6 |
|
| 7 | + |
6 | 8 | def login(token): |
7 | 9 | client = Github(login_or_token=token) |
8 | 10 | try: |
@@ -30,8 +32,27 @@ def get_next_repo(client: Github, repositories): |
30 | 32 | yield repo |
31 | 33 |
|
32 | 34 |
|
| 35 | +def get_assignee_story(github_object): |
| 36 | + assignee_result = "" |
| 37 | + events = github_object.get_issue_events() if type( |
| 38 | + github_object) is PullRequest.PullRequest else github_object.get_events() |
| 39 | + for event in events: |
| 40 | + if event.event == "assigned" or event.event == "unassigned": |
| 41 | + date = event.created_at |
| 42 | + if event.event == "assigned": |
| 43 | + assigner = github_object.user.login |
| 44 | + assignee = event.assignee.login |
| 45 | + assignee_result += f"{date}: {assigner} -> {assignee}; " |
| 46 | + else: |
| 47 | + assigner = github_object.user.login |
| 48 | + assignee = event.assignee.login |
| 49 | + assignee_result += f"{date}: {assigner} -/> {assignee}; " |
| 50 | + return assignee_result |
| 51 | + |
| 52 | + |
33 | 53 | def log_commit_to_csv(info, csv_name): |
34 | | - fieldnames = ['repository name', 'commit id', 'author name', 'author login', 'author email', 'date and time', 'changed files'] |
| 54 | + fieldnames = ['repository name', 'commit id', 'author name', 'author login', 'author email', 'date and time', |
| 55 | + 'changed files'] |
35 | 56 | with open(csv_name, 'a', newline='') as file: |
36 | 57 | writer = csv.DictWriter(file, fieldnames=fieldnames) |
37 | 58 | writer.writerow(info) |
@@ -65,7 +86,8 @@ def log_repository_commits(repository: Repository, csv_name): |
65 | 86 | def log_issue_to_csv(info, csv_name): |
66 | 87 | fieldnames = ['repository name', 'number', 'title', 'state', 'task', 'created at', 'creator name', 'creator login', |
67 | 88 | 'creator email', 'closer name', 'closer login', 'closer email', 'closed at', 'comment body', |
68 | | - 'comment created at', 'comment author name', 'comment author login', 'comment author email'] |
| 89 | + 'comment created at', 'comment author name', 'comment author login', 'comment author email', |
| 90 | + 'assignee story', ] |
69 | 91 | with open(csv_name, 'a', newline='') as file: |
70 | 92 | writer = csv.DictWriter(file, fieldnames=fieldnames) |
71 | 93 | writer.writerow(info) |
@@ -93,8 +115,11 @@ def log_repository_issues(repository: Repository, csv_name): |
93 | 115 | 'comment author name': EMPTY_FIELD, |
94 | 116 | 'comment author login': EMPTY_FIELD, |
95 | 117 | 'comment author email': EMPTY_FIELD, |
| 118 | + 'assignee story': EMPTY_FIELD, |
96 | 119 | } |
97 | 120 |
|
| 121 | + info_tmp['assignee story'] = get_assignee_story(issue) |
| 122 | + |
98 | 123 | if issue.user is not None: |
99 | 124 | info_tmp['creator name'] = issue.user.name |
100 | 125 | info_tmp['creator login'] = issue.user.login |
@@ -123,7 +148,8 @@ def log_pr_to_csv(info, csv_name): |
123 | 148 | fieldnames = ['repository name', 'title', 'state', 'commit into', 'commit from', 'created at', 'creator name', |
124 | 149 | 'creator login', 'creator email', |
125 | 150 | 'changed files', 'comment body', 'comment created at', 'comment author name', 'comment author login', |
126 | | - 'comment author email', 'merger name', 'merger login', 'merger email', 'source branch', 'target branch'] |
| 151 | + 'comment author email', 'merger name', 'merger login', 'merger email', 'source branch', |
| 152 | + 'target branch', 'assignee story', ] |
127 | 153 | with open(csv_name, 'a', newline='') as file: |
128 | 154 | writer = csv.DictWriter(file, fieldnames=fieldnames) |
129 | 155 | writer.writerow(info) |
@@ -156,13 +182,16 @@ def log_repositories_pr(repository: Repository, csv_name): |
156 | 182 | 'merger email': EMPTY_FIELD, |
157 | 183 | 'source branch': pull.head.ref, |
158 | 184 | 'target branch': pull.base.ref, |
| 185 | + 'assignee story': EMPTY_FIELD, |
159 | 186 | } |
160 | 187 |
|
161 | 188 | if pull.merged_by is not None: |
162 | 189 | info_tmp['merger name'] = pull.merged_by.name |
163 | 190 | info_tmp['merger login'] = pull.merged_by.login |
164 | 191 | info_tmp['merger email'] = pull.merged_by.email |
165 | 192 |
|
| 193 | + info_tmp['assignee story'] = get_assignee_story(pull) |
| 194 | + |
166 | 195 | if pull.get_comments().totalCount > 0: |
167 | 196 | for comment in pull.get_comments(): |
168 | 197 | info = info_tmp |
@@ -203,6 +232,7 @@ def log_pull_requests(client: Github, repositories, csv_name): |
203 | 232 | 'merger email', |
204 | 233 | 'source branch', |
205 | 234 | 'target branch', |
| 235 | + 'assignee story', |
206 | 236 | ) |
207 | 237 | ) |
208 | 238 |
|
@@ -233,6 +263,7 @@ def log_issues(client: Github, repositories, csv_name): |
233 | 263 | 'comment author name', |
234 | 264 | 'comment author login', |
235 | 265 | 'comment author email', |
| 266 | + 'assignee story', |
236 | 267 | ) |
237 | 268 | ) |
238 | 269 |
|
|
0 commit comments