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