-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcan_be_closed_python_based.py
More file actions
104 lines (80 loc) · 3.54 KB
/
can_be_closed_python_based.py
File metadata and controls
104 lines (80 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import requests
import re
import base64
from typing import List, Dict
def download_release_notes(repo_owner: str, repo_name: str, file_path: str, branch: str = "main", token: str = None) -> str:
"""
Downloads the release notes file content using GitHub API (supports private repos).
"""
headers = {"Accept": "application/vnd.github+json"}
if token:
headers["Authorization"] = f"token {token}"
url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/contents/{file_path}?ref={branch}"
response = requests.get(url, headers=headers)
if response.status_code == 200:
content_json = response.json()
file_content_base64 = content_json.get("content", "")
file_content = base64.b64decode(file_content_base64.encode("utf-8")).decode("utf-8")
return file_content
else:
raise Exception(f"Failed to fetch file from API: HTTP {response.status_code}")
def get_closed_issues(issue_list: List[Dict], release_notes_content: str) -> List[str]:
"""
Compares open issue numbers against release notes content.
"""
closed_issues = []
content = release_notes_content.lower()
for issue in issue_list:
issue_number = f"#{issue['number']}"
if re.search(re.escape(issue_number.lower()), content):
closed_issues.append(issue_number)
return closed_issues
def get_open_issues(repo_owner: str, repo_name: str, token: str = None) -> List[Dict]:
"""
Fetches a list of open issues from a GitHub repository.
"""
headers = {"Accept": "application/vnd.github+json"}
if token:
headers["Authorization"] = f"token {token}"
issues_url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/issues"
params = {"state": "open", "per_page": 100}
open_issues = []
page = 1
while True:
params["page"] = page
response = requests.get(issues_url, headers=headers, params=params)
if response.status_code != 200:
raise Exception(f"Failed to fetch issues: HTTP {response.status_code} - {response.text}")
issues = response.json()
if not issues:
break
open_issues.extend([issue for issue in issues if "pull_request" not in issue])
page += 1
return open_issues
if __name__ == "__main__":
# 🔧 CONFIGURATION
repo_owner = "umarali-nagoor"
repo_name = "Test_Repo"
file_path = "release.md"
branch = "master"
github_token = None # Set your GitHub token if repo is private
try:
print("📥 Downloading release notes...")
release_notes_content = download_release_notes(repo_owner, repo_name, file_path, branch, github_token)
print("🐛 Fetching open issues...")
issue_list = get_open_issues(repo_owner, repo_name, github_token)
print(f"📋 Open issues for {repo_owner}/{repo_name}:")
for issue in issue_list:
print(f"- #{issue['number']}: {issue['title']} (created by {issue['user']['login']})")
print("\n🔍 Checking which issues are mentioned in the release notes...")
closed_issues = get_closed_issues(issue_list, release_notes_content)
print("\n✅ Issues found in release notes and can be closed:")
for issue in closed_issues:
print(issue)
print("\n❌ Issues not found in release notes and still open:")
for issue in issue_list:
issue_number = f"#{issue['number']}"
if issue_number not in closed_issues:
print(issue_number)
except Exception as e:
print(f"❗ Error: {e}")