1 Star 0 Fork 1

ant1423/RetroArch

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
github-contributors.py 2.66 KB
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/python3
#
# Get list of repo contributors from GitHub using v4 GraphQL API
#
# Copyright (C) 2016-2019 - Brad Parker
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from urllib.request import urlopen, Request
import json
### SETTINGS ###
# https://help.github.com/articles/creating-an-access-token-for-command-line-use/
TOKEN = 'Your access token here'
orgName = 'libretro'
repoName = 'RetroArch'
### END SETTINGS ###
######
lines = []
def get_contributors(after=None):
global lines
headers = {'Authorization': 'bearer ' + TOKEN}
url = 'https://api.github.com/graphql'
dataStr = """{
repository(owner: \"""" + orgName + """\", name: \"""" + repoName + """\") {
"""
if after:
dataStr += """
mentionableUsers(first: 100 after:\"""" + after + """\") {
"""
else:
dataStr += """
mentionableUsers(first: 100) {
"""
dataStr += """
edges {
node {
name
login
}
cursor
}
}
}
}
"""
d = {'query': dataStr}
data = json.dumps(d).encode('utf-8')
req = Request(url, data, headers)
with urlopen(req) as resp:
d = resp.read()
j = json.loads(d)
if len(j['data']['repository']['mentionableUsers']['edges']) == 0:
return None
cursor = None
for key in j['data']['repository']['mentionableUsers']['edges']:
line = ''
name = None
login = None
node = key['node']
if 'name' in node and node['name'] and len(node['name']) > 0:
name = node['name']
if 'login' in node and node['login'] and len(node['login']) > 0:
login = node['login']
if 'cursor' in key and key['cursor'] and len(key['cursor']) > 0:
cursor = key['cursor']
if name:
line = name
if login and login.lower() != name.lower():
line += ' (' + login + ')'
elif login:
line = login
else:
continue
if len(line) > 0:
lines.append(line)
if cursor and len(cursor) > 0:
return cursor
def doit(cont):
after = get_contributors(cont)
if after:
doit(after)
doit(None)
print('\n'.join(sorted(lines, key=str.lower)))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ant1423/RetroArch.git
git@gitee.com:ant1423/RetroArch.git
ant1423
RetroArch
RetroArch
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385