1 Star 0 Fork 0

ForGraduation/CoRA_Test

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
pr_get.py 2.63 KB
一键复制 编辑 原始数据 按行查看 历史
Kaicheng Wu 提交于 2022-04-09 15:51 . update
# -*- coding: utf-8 -*-
# @Time : 2022/4/7 21:24
# @Author : Kaicheng
import os
import urllib
import github
GH = github.Github("your_access_token")
ROOT_DIR = "D:/OSS_Projects"
repo_list = ["jruby/jruby", "netty/netty", "spring-projects/spring-framework", "bumptech/glide", "jfree/jfreechart", "apache/lucene-solr"]
def file_download(local_path, url):
if not os.path.exists(os.path.dirname(local_path)):
os.makedirs(os.path.dirname(local_path))
if not os.path.exists(local_path):
urllib.request.urlretrieve(url, local_path)
for repo_str in repo_list:
repo = GH.get_repo(repo_str)
pr_list = repo.get_pulls(state='open', sort='created')
for index in range(pr_list.totalCount):
pr = pr_list[index]
# select the appropriate PRs
java_count = 0
for f in pr.get_files():
if f.filename.endswith(".java"):
java_count += 1
if java_count < 2 or java_count > 100:
continue
print(pr.title + " " + str(pr.number))
first_commit = pr.get_commits()[0]
parent_commit = first_commit.parents[0]
pre_repo_url = f"https://github.com/{repo_str}/raw/{parent_commit.sha}"
print("parent commit repo resource url: " + pre_repo_url)
print("parent commit repo front-end url: " + pre_repo_url.replace("/raw/", "/tree/"))
for f in pr.get_files():
if not f.filename.endswith(".java"):
continue
print(f.filename)
if f.status == "removed":
local_old_path = f"{ROOT_DIR}/{repo_str}/{str(pr.number)}/old/{f.filename}"
file_download(local_old_path, f.raw_url)
elif f.status == "added":
local_new_path = f"{ROOT_DIR}/{repo_str}/{str(pr.number)}/new/{f.filename}"
file_download(local_new_path, f.raw_url)
else:
# download new version
local_new_path = f"{ROOT_DIR}/{repo_str}/{str(pr.number)}/new/{f.filename}"
file_download(local_new_path, f.raw_url)
# download old version
try:
old_raw_url = f"{pre_repo_url}/{f.filename.replace('/', '%2F')}"
local_old_path = f"{ROOT_DIR}/{repo_str}/{str(pr.number)}/old/{f.filename}"
file_download(local_old_path, old_raw_url)
except:
print()
print(f"404: {pre_repo_url}/{f.filename.replace('/', '%2F')}")
continue
print("--------------------------------------------------")
print("===================================================")
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/for-gradutation/CoraTest.git
git@gitee.com:for-gradutation/CoraTest.git
for-gradutation
CoraTest
CoRA_Test
master

搜索帮助