jhylands

Code eye

Jan 2nd, 2021
959
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.65 KB | None | 0 0
  1. import requests
  2. import json
  3.  
  4. from requests import Response
  5. from typing import Dict, Any
  6. token = "token"
  7. url = "https://gitlab.com/api/v4/projects/1/merge_requests?state=opened&scope=all&per_page=1000&private_token=" + token
  8. response = requests.get(url)  # type: Response
  9. merge_requests_by_author = {}  # type: Dict[str, List[Tuple]]
  10. if response.status_code == 200:
  11.     json_body = response.text
  12.     request_body = json.loads(json_body)  # type: List[Dict[Any, Any]]
  13. request_body
  14. def lookup(iid):
  15.     url = "https://gitlab.com/api/v4/projects/1/merge_requests/{}/changes?private_token={}".format(iid, token)
  16.     response = requests.get(url)  # type: Response
  17.     merge_requests_by_author = {}  # type: Dict[str, List[Tuple]]
  18.     if response.status_code == 200:
  19.         json_body = response.text
  20.         request_body = json.loads(json_body)  # type: List[Dict[Any, Any]]
  21.     return request_body
  22. def get_requests():
  23.     url = "https://gitlab.com/api/v4/projects/1/merge_requests?state=opened&scope=all&per_page=1000&private_token=" + token
  24.     response = requests.get(url)  # type: Response
  25.     merge_requests_by_author = {}  # type: Dict[str, List[Tuple]]
  26.     if response.status_code == 200:
  27.         json_body = response.text
  28.         request_body = json.loads(json_body)  # type: List[Dict[Any, Any]]
  29.         for merge_request in request_body:
  30.             yield lookup(merge_request['iid'])
  31. for request in get_requests():
  32.     paths = [change['old_path'] for change in request['changes']]
  33.     if "my_refactored_file.py" in paths:
  34.         print("my_refactored_file.py found:{}:{} - {}".format(request['iid'], request['title'], request['author']['name']))
  35.  
Advertisement
Add Comment
Please, Sign In to add comment