Add GitHub support
This commit is contained in:
parent
f8ea2868ff
commit
3e1f20f9b3
@ -1,2 +1,4 @@
|
||||
# Need `repository` and `user` `Read` scopes with `All (public, private, and limited)`.
|
||||
# Need for:
|
||||
# Gitea: `repository` and `user` `Read` scopes with `All (public, private, and limited)`.
|
||||
# GitHub: `public_report`
|
||||
TOKEN = 'YOUR_TOKEN'
|
59
main.py
59
main.py
@ -1,29 +1,58 @@
|
||||
import requests
|
||||
import json
|
||||
import config
|
||||
from enum import Enum
|
||||
from tqdm import tqdm
|
||||
|
||||
GITEA_INSTANCE = 'https://gitea.lemnoslife.com'
|
||||
Git = Enum('Git', [
|
||||
'TEA',
|
||||
'LAB',
|
||||
'HUB',
|
||||
])
|
||||
|
||||
headers = {
|
||||
'Authorization': f'token {config.TOKEN}'
|
||||
}
|
||||
GIT_INSTANCE_URL = 'https://api.github.com'
|
||||
GIT_INSTANCE_TYPE = Git.HUB
|
||||
|
||||
if GIT_INSTANCE_TYPE == Git.HUB:
|
||||
USERNAME = getApi('user')['login']
|
||||
|
||||
headers = {}
|
||||
|
||||
match GIT_INSTANCE_TYPE:
|
||||
case Git.TEA:
|
||||
headers['Authorization'] = f'token {config.TOKEN}'
|
||||
case Git.HUB:
|
||||
headers['Authorization'] = f'Bearer {config.TOKEN}'
|
||||
|
||||
def getApi(url):
|
||||
url = f'{GITEA_INSTANCE}/api/v1/{url}'
|
||||
response = requests.get(url, headers = headers)
|
||||
if GIT_INSTANCE_TYPE == Git.TEA:
|
||||
url = f'api/v1/{url}'
|
||||
response = requests.get(f'{GIT_INSTANCE_URL}/{url}', headers = headers)
|
||||
return response.json()
|
||||
|
||||
repositories = getApi(f'user/repos')
|
||||
match GIT_INSTANCE_TYPE:
|
||||
case Git.TEA:
|
||||
repositories = getApi(f'user/repos')
|
||||
case Git.HUB:
|
||||
repositories = getApi(f'search/repositories?q=user:{USERNAME}&per_page=1000')['items']
|
||||
|
||||
print(json.dumps(repositories, indent = 4))
|
||||
|
||||
for repository in repositories:
|
||||
for repository in tqdm(repositories):
|
||||
repositoryFullName = repository['full_name']
|
||||
collaborators = getApi(f'repos/{repositoryFullName}/collaborators')
|
||||
for collaborator in collaborators:
|
||||
print(json.dumps(collaborators, indent = 4))
|
||||
# Does not seem necessary for GitHub.
|
||||
permission = getApi(f'repos/{repositoryFullName}/collaborators/{collaborator["login"]}/permission')
|
||||
if permission['permission'] != 'read':
|
||||
print(repositoryFullName)
|
||||
print(json.dumps(permission, indent = 4))
|
||||
|
||||
login = permission['user']['login']
|
||||
toPrint = [
|
||||
repositoryFullName,
|
||||
login,
|
||||
]
|
||||
match GIT_INSTANCE_TYPE:
|
||||
case Git.TEA:
|
||||
if permission.get('message') == 'Only admins can query all permissions, repo admins can query all repo permissions, collaborators can query only their own':
|
||||
continue
|
||||
if permission['permission'] != 'read':
|
||||
print(*toPrint)
|
||||
case Git.HUB:
|
||||
if login != USERNAME:
|
||||
print(*toPrint)
|
Loading…
Reference in New Issue
Block a user