Skip to content

Instantly share code, notes, and snippets.

@smiklosovic
Created May 20, 2024 11:17
Show Gist options
  • Save smiklosovic/8f21145add0aaf9b4ada2505c01eb076 to your computer and use it in GitHub Desktop.
Save smiklosovic/8f21145add0aaf9b4ada2505c01eb076 to your computer and use it in GitHub Desktop.
gets all pulls which are not closed but they are resolved in jira
#!/usr/bin/env python3
import requests
import json
import jq
import re
pulls_url_template = "https://api.github.com/repos/apache/cassandra/pulls?state=open&per_page=100&page=%s"
def main():
for i in range(1, 4):
process_page(i)
def get_pulls(state, open_pulls):
pulls_in_state = []
for open_pull in open_pulls:
pull = json.loads(open_pull)
pull_state = pull['state']
if pull_state == state:
pulls_in_state.append(pull)
return pulls_in_state
def process_page(page_number):
pulls = json.dumps(requests.get(pulls_url_template.format(page_number)).json())
all_pulls = jq.compile('.[] | {url: .url, title: .title, state: .state}').input_text(pulls).text().splitlines()
for pull in get_pulls("open", all_pulls):
url = pull['url']
title = pull['title']
github_ticket_number = url.rsplit('/', 1)[-1]
p = re.compile("CASSANDRA[- ]\\d+", re.IGNORECASE)
match = p.search(title)
if match:
jira_ticket_number = match.group().replace(" ", "-").upper()
r = requests.get("https://issues.apache.org/jira/rest/api/latest/issue/" + jira_ticket_number).json()
data = json.loads(json.dumps(r))
status = data['fields']['status']['name']
if status == 'Resolved':
print(jira_ticket_number + " " + "https://github.com/apache/cassandra/pull/" + github_ticket_number)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment