GitHub first try
This commit is contained in:
@ -45,6 +45,13 @@ def get_args():
|
||||
default='https://gitea.eco.tsi-dev.otc-service.com/api/v1/',
|
||||
help='Base URL for API request.'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--hoster',
|
||||
default='gitea',
|
||||
choices=['gitea', 'github'],
|
||||
nargs='?',
|
||||
help='Hoster for the API calls. Choose between \"github\" and \"gitea\".'
|
||||
)
|
||||
return(parser.parse_args())
|
||||
|
||||
def get_repos(url, path, headers):
|
||||
@ -112,6 +119,48 @@ def get_failed_commits(repositories, headers, args):
|
||||
break
|
||||
return(failed_commits)
|
||||
|
||||
def get_github_repos(url, headers, org):
|
||||
repositories = []
|
||||
i = 1
|
||||
|
||||
while True:
|
||||
try:
|
||||
req_url = url + 'orgs/' + org + '/repos?page=' + str(i)
|
||||
res = requests.request('GET', url=req_url, headers=headers)
|
||||
if res.json():
|
||||
for repo in res.json():
|
||||
repositories.append(repo)
|
||||
i+=1
|
||||
continue
|
||||
else:
|
||||
break
|
||||
except Exception as e:
|
||||
print("An error has occured: " + str(e))
|
||||
print("The request status is: " + str(res.status_code) + " | " + str(res.reason))
|
||||
break
|
||||
return(repositories)
|
||||
|
||||
def get_github_prs(url, headers, org, repo):
|
||||
pullrequests = []
|
||||
i = 1
|
||||
|
||||
while True:
|
||||
try:
|
||||
req_url = url + 'repos/' + org + '/' + repo + '/pulls?state=open&page=' + str(i)
|
||||
res = requests.request('GET', url=req_url, headers=headers)
|
||||
if res.json():
|
||||
for pr in res.json():
|
||||
pullrequests.append(pr)
|
||||
i+=1
|
||||
continue
|
||||
else:
|
||||
break
|
||||
except Exception as e:
|
||||
print("An error has occured: " + str(e))
|
||||
print("The request status is: " + str(res.status_code) + " | " + str(res.reason))
|
||||
break
|
||||
return(pullrequests)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
@ -120,6 +169,7 @@ def main():
|
||||
if args.debug:
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
if args.hoster == 'gitea':
|
||||
repo_path = 'orgs/docs/repos?limit=50&page='
|
||||
headers = {}
|
||||
headers['accept'] = 'application/json'
|
||||
@ -129,5 +179,27 @@ def main():
|
||||
failed_commits = get_failed_commits(repositories=repositories, headers=headers, args=args)
|
||||
print(json.dumps(failed_commits))
|
||||
|
||||
elif args.hoster == 'github':
|
||||
url = 'https://api.github.com/'
|
||||
headers = {}
|
||||
headers['accept'] = 'application/json'
|
||||
headers['Authorization'] = 'Bearer ' + args.token
|
||||
|
||||
|
||||
for org in args.orgs:
|
||||
repos = get_github_repos(url, headers, org)
|
||||
pulls = []
|
||||
for repo in repos:
|
||||
pulls.extend(get_github_prs(url, headers, org, repo['name']))
|
||||
# print(pulls)
|
||||
print(len(pulls))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Reference in New Issue
Block a user