add methods
This commit is contained in:
@ -19,7 +19,7 @@ import requests
|
||||
import json
|
||||
|
||||
|
||||
def main():
|
||||
def get_args():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Bootstrap repositories.')
|
||||
parser.add_argument(
|
||||
@ -35,25 +35,26 @@ def main():
|
||||
required=True,
|
||||
help='API Token'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--debug',
|
||||
action='store_true',
|
||||
help='Set debug mode on.'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--url',
|
||||
default='https://gitea.eco.tsi-dev.otc-service.com/api/v1/',
|
||||
help='Base URL for API request.'
|
||||
)
|
||||
return(parser.parse_args())
|
||||
|
||||
args = parser.parse_args()
|
||||
# logging.basicConfig(level=logging.DEBUG)
|
||||
path = 'orgs/docs/repos?limit=50&page='
|
||||
headers = {}
|
||||
headers['accept'] = 'application/json'
|
||||
headers['Authorization'] = 'token ' + args.token
|
||||
def get_repos(url, path, headers):
|
||||
repositories = []
|
||||
i = 1
|
||||
|
||||
while True:
|
||||
try:
|
||||
url = args.url + path + str(i)
|
||||
res = requests.request('GET', url=url, headers=headers)
|
||||
req_url = url + path + str(i)
|
||||
res = requests.request('GET', url=req_url, headers=headers)
|
||||
if res.json():
|
||||
for repo in res.json():
|
||||
repositories.append(repo)
|
||||
@ -65,11 +66,13 @@ def main():
|
||||
print("An error has occured: " + str(e))
|
||||
print("The request status is: " + str(res.status_code) + " | " + str(res.reason))
|
||||
break
|
||||
return(repositories)
|
||||
|
||||
pull_path = 'repos/docs/'
|
||||
status_path = 'repos/docs/'
|
||||
pulls = []
|
||||
def get_failed_commits(repositories, headers, args):
|
||||
failed_commits = []
|
||||
pull_path = 'repos/docs/'
|
||||
status_path = pull_path
|
||||
pulls = []
|
||||
|
||||
for repo in repositories:
|
||||
try:
|
||||
@ -107,18 +110,24 @@ def main():
|
||||
print("An error has occured: " + str(e))
|
||||
print("The request status is: " + str(res.status_code) + " | " + str(res.reason))
|
||||
break
|
||||
return(failed_commits)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
args = get_args()
|
||||
|
||||
if args.debug:
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
repo_path = 'orgs/docs/repos?limit=50&page='
|
||||
headers = {}
|
||||
headers['accept'] = 'application/json'
|
||||
headers['Authorization'] = 'token ' + args.token
|
||||
|
||||
repositories = get_repos(url=args.url, path=repo_path, headers=headers)
|
||||
failed_commits = get_failed_commits(repositories=repositories, headers=headers, args=args)
|
||||
print(json.dumps(failed_commits))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Reference in New Issue
Block a user