forked from hehao98/LibraryMigration
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_prs_by_commits.py
More file actions
50 lines (43 loc) · 1.79 KB
/
get_prs_by_commits.py
File metadata and controls
50 lines (43 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import time
import logging
import pandas as pd
from github import Github, Issue
from ghutil import get_tokens
def issue_to_excel_row(issue: Issue, commit_sha: str) -> dict:
return {
"id": issue.id,
"number": issue.number,
"repoName": issue.repository.name,
"relatedCommit": commit_sha,
"url": "https://github.com/{}/issues/{}".format(issue.repository.full_name, issue.number),
"api_url": issue.url,
"title": issue.title
}
def run():
tokens = get_tokens("tokens.txt")
logging.info("GitHub tokens: {}".format(tokens))
gh = Github(tokens[0])
migrations = pd.read_excel("data/migrations.xlsx")
commits = set(migrations["startCommit"]) | set(migrations["endCommit"])
repo_names = set(map(lambda x: x.replace("_", "/"), migrations["repoName"]))
logging.info(
"{} repositories, {} commits".format(
len(repo_names),
len(commits)))
# Although it looks like we are retrieving issues, actually all we get are
# PRs!
issue_list = []
for idx, commit in enumerate(commits):
logging.info("Commit {}/{}: {}".format(idx + 1, len(commits), commit))
while True:
try:
for issue in gh.search_issues("SHA:{}".format(commit)):
logging.info(" {} {} {} {}".format(
issue.id, issue.number, issue.repository.full_name, gh.rate_limiting))
issue_list.append(issue_to_excel_row(issue, commit))
break
except Exception as ex:
logging.error(" {}".format(ex))
logging.info(" wait for 60 seconds...")
time.sleep(60)
pd.DataFrame(issue_list).to_excel("data/prs.xlsx", index=False)