From 92a057cb1b747845c5cb7e0ae992acdde87970b8 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 20 Sep 2022 07:41:00 +0000 Subject: [PATCH] Repo+Pull --- tools/attention_list.py | 95 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 tools/attention_list.py diff --git a/tools/attention_list.py b/tools/attention_list.py new file mode 100644 index 00000000..daeb9c15 --- /dev/null +++ b/tools/attention_list.py @@ -0,0 +1,95 @@ +#!/usr/bin/python + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import logging +import requests +import json + + +def main(): + parser = argparse.ArgumentParser( + description='Bootstrap repositories.') + parser.add_argument( + '--orgs', + nargs='+', + default=['docs'], + help='One or more organizations to be queried for failed Pull ' + 'Requests.\n' + 'Default: [docs]' + ) + parser.add_argument( + '--token', + default='682ac3d176cf614cec4ecf9c8392880c89d07488', + help='API Token' + ) + parser.add_argument( + '--url', + default='https://gitea.eco.tsi-dev.otc-service.com/api/v1/', + help='Base URL for API request.' + ) + + 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 + repositories = [] + i = 1 + + while True: + try: + url = args.url + path + str(i) + res = requests.request('GET', url=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 + + pull_path = 'repos/docs/' + pulls = [] + + for repo in repositories: + try: + url = args.url + pull_path + repo['name'] + '/pulls?state=open' + res = requests.request('GET', url=url, headers=headers) + if res.json(): + for pull in res.json(): + pulls.append(pull) + continue + else: + continue + except Exception as e: + print("An error has occured: " + str(e)) + print("The request status is: " + str(res.status_code) + " | " + str(res.reason)) + break + + # print(len(pulls)) + + + + + + +if __name__ == '__main__': + main() \ No newline at end of file