-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupgrade.py
More file actions
151 lines (103 loc) · 2.84 KB
/
Copy pathupgrade.py
File metadata and controls
151 lines (103 loc) · 2.84 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import argparse
import os
import subprocess
from pathlib import Path
from github import Github
DEFAULT_TITLE_PREFIX = "Java Spring Boot Upgrade Planning"
def detect_local_repo():
"""
Detect current git repository name.
"""
try:
repo_path = subprocess.check_output(
["git", "rev-parse", "--show-toplevel"],
text=True
).strip()
return Path(repo_path).name
except Exception:
return "unknown-repository"
def load_template():
"""
Load issue template content.
"""
with open("issue_template.md", "r", encoding="utf-8") as file:
return file.read()
def generate_issue(repo_name):
"""
Generate issue title and body.
"""
title = f"{DEFAULT_TITLE_PREFIX} - {repo_name}"
body = load_template()
return title, body
def print_summary(repo_name):
"""
Print execution summary.
"""
print("\n" + "=" * 60)
print("Java Spring Boot Upgrade Planning Generator")
print("=" * 60)
print(f"\nTarget Repository : {repo_name}")
def create_github_issue(repo_name, title, body):
"""
Create GitHub issue if no duplicate exists.
"""
token = os.getenv("GITHUB_TOKEN")
if not token:
raise Exception(
"GITHUB_TOKEN environment variable not found"
)
github_client = Github(token)
repository = github_client.get_repo(repo_name)
existing_issues = repository.get_issues(state="open")
for issue in existing_issues:
if issue.title.strip().lower() == title.strip().lower():
print("\nDuplicate issue already exists")
print(issue.html_url)
return None
issue = repository.create_issue(
title=title,
body=body
)
return issue.html_url
def print_issue(title, body):
"""
Print generated issue.
"""
print(f"\nIssue Title:\n{title}")
print("\nIssue Body:\n")
print(body)
print("\n" + "=" * 60)
print("Dry run completed successfully")
print("=" * 60)
def main():
parser = argparse.ArgumentParser(
description="Generate Spring Boot upgrade planning issues"
)
parser.add_argument(
"--repo",
type=str,
required=True,
help="Target GitHub repository (owner/repo)"
)
parser.add_argument(
"--dry-run",
action="store_true",
help="Print generated issue without creating it"
)
args = parser.parse_args()
repo_name = args.repo
print_summary(repo_name)
title, body = generate_issue(repo_name)
if args.dry_run:
print_issue(title, body)
else:
issue_url = create_github_issue(
repo_name,
title,
body
)
if issue_url:
print("\nIssue created successfully")
print(issue_url)
if __name__ == "__main__":
main()