|
| 1 | +import urllib3 |
| 2 | +import requests |
| 3 | +import Basic_Functions as bfs |
| 4 | + |
| 5 | +urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) |
| 6 | + |
| 7 | +# GitHub API oAuth |
| 8 | +CLIENT_ID = "6aca4b66775c629cbafd" |
| 9 | +CLIENT_SECRET = "2349a0a9266e81f9f4d7df62ca49a98ca357b20c" |
| 10 | + |
| 11 | +OWNER = "symfony" |
| 12 | +REPO = "symfony" |
| 13 | +FIRST_TIMER_LABELS = ["Easy Pick"] |
| 14 | + |
| 15 | + |
| 16 | +# ==============Functions============== |
| 17 | +def getIssueData(owner="symfony", repo="symfony", required_labels=["good first issue"]): |
| 18 | + dataset = {} |
| 19 | + |
| 20 | + # ============ Local Search ============ |
| 21 | + # ============ Online Search ============ |
| 22 | + index = 0 |
| 23 | + STOP = False |
| 24 | + STATE = "open" |
| 25 | + while not STOP: |
| 26 | + index += 1 |
| 27 | + # Example Page: https://api.github.com/repos/symfony/symfony/issues?state=closed&page=1 |
| 28 | + issues_url = "https://api.github.com/repos/{}/{}/issues?state={}&page={}&per_page=100&client_id={}&client_secret={}".format( |
| 29 | + owner, repo, STATE, index, CLIENT_ID, CLIENT_SECRET) |
| 30 | + print(issues_url) |
| 31 | + issues = requests.get(issues_url, verify=False).json() |
| 32 | + # If the length of issues is 0, check whether should search closed issue or stop the while loop |
| 33 | + if len(issues) == 0: |
| 34 | + STOP = True |
| 35 | + # Process all issues |
| 36 | + for issue in issues: |
| 37 | + RECORD = True |
| 38 | + # for label in issue["labels"]: |
| 39 | + # if label["name"] in required_labels: |
| 40 | + # RECORD = True |
| 41 | + if RECORD: |
| 42 | + # --process issue |
| 43 | + issue["title"] = str(issue["title"]).replace("\"", "'") |
| 44 | + issue["title"] = str(issue["title"]).replace('\n', "") |
| 45 | + issue["title"] = str(issue["title"]).replace('\r', "") |
| 46 | + issue["body"] = str(issue["title"]).replace("\"", "'") |
| 47 | + issue["body"] = str(issue["title"]).replace('\n', "") |
| 48 | + issue["body"] = str(issue["title"]).replace('\r', "") |
| 49 | + |
| 50 | + # Get pull request |
| 51 | + # pull_request_url = "https://api.github.com/repos/{}/{}/pulls/{}?client_id={}&client_secret={}".format( |
| 52 | + # owner, repo, issue["number"], CLIENT_ID, CLIENT_SECRET) |
| 53 | + # print(pull_request_url) |
| 54 | + # pull_request = requests.get(pull_request_url, verify=False).json() |
| 55 | + # --process pull request |
| 56 | + # commits = [] |
| 57 | + # if "number" in pull_request: |
| 58 | + # pull_request["title"] = str(pull_request["title"]).replace("\"", "'") |
| 59 | + # pull_request["body"] = str(pull_request["body"]).replace("\"", "'") |
| 60 | + # |
| 61 | + # # Get commit |
| 62 | + # pull_commits_url = "{}?client_id={}&client_secret={}".format( |
| 63 | + # pull_request["commits_url"], CLIENT_ID, CLIENT_SECRET) |
| 64 | + # print(pull_commits_url) |
| 65 | + # pull_commits = requests.get(pull_commits_url, verify=False).json() |
| 66 | + # # --process pull request |
| 67 | + # for pull_commit in pull_commits: |
| 68 | + # commits.append(pull_commit) |
| 69 | + # else: |
| 70 | + # pull_request = None |
| 71 | + |
| 72 | + # Add all data to dataset |
| 73 | + # dataset.append({"issue": issue, "pull_request": pull_request, "pull_commits": commits}) |
| 74 | + dataset[issue["number"]] = issue |
| 75 | + # dataset.append({"issue": issue}) |
| 76 | + return dataset |
| 77 | + |
| 78 | + |
| 79 | +# ==============Main============== |
| 80 | +dataset_master = getIssueData(owner=OWNER, repo=REPO, required_labels=FIRST_TIMER_LABELS) |
| 81 | + |
| 82 | +bfs.writeJsonFile(data=dataset_master, name="all_open_issues_{}".format(REPO), folder="data/open_issues") |
| 83 | + |
| 84 | +print(len(dataset_master)) |
0 commit comments