Repo+Pull
This commit is contained in:
		
							
								
								
									
										95
									
								
								tools/attention_list.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								tools/attention_list.py
									
									
									
									
									
										Normal file
									
								
							@ -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()
 | 
			
		||||
		Reference in New Issue
	
	Block a user