-
Notifications
You must be signed in to change notification settings - Fork 3
/
export_issues.py
80 lines (63 loc) · 2.5 KB
/
export_issues.py
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
import requests
import markdown
import os
# Set your GitHub repository details
GITHUB_REPO = "qiwihui/blog"
GITHUB_TOKEN = "" # Replace with your GitHub personal access token
# Set up API URL
base_url = f"https://api.github.com/repos/{GITHUB_REPO}/issues"
# Define headers with the authorization token
headers = {"Authorization": f"token {GITHUB_TOKEN}"}
page = 0
count = 0
all_issues = []
def get_labels(issue):
labels = [l["name"] for l in issue["labels"]]
return labels
while count is not None:
page += 1
url = base_url + f"?page={page}"
print(url)
# Send the request to GitHub API
response = requests.get(url, headers=headers)
# Check if the request was successful
if response.status_code == 200:
issues = response.json()
# Create a directory to store the markdown files if it doesn't exist
output_dir = "src/blogs"
os.makedirs(output_dir, exist_ok=True)
all_issues += issues
for issue in issues:
if "TODO" in get_labels(issue):
continue
# Only export issues, not pull requests
if "pull_request" not in issue:
# Create a filename based on the issue number and title
file_title = issue["title"].replace(" ", "_").replace("/", "-")
filename = f"qiwihui-blog-{issue['number']}.md"
# Create the full path for the file
file_path = os.path.join(output_dir, filename)
# Write the issue details to the markdown file
with open(file_path, "w", encoding="utf-8") as file:
file.write(f"# {issue['title']}\n")
file.write(f"\n\n")
file.write(f"{issue['body']}\n\n")
file.write(f"[View on GitHub]({issue['html_url']})\n")
file.write("\n\n")
print(f"Exported {len(issues)} issues to {output_dir} directory.")
if len(issues) != 30:
count = None
# break
else:
print(f"Failed to retrieve issues: {response.status_code} - {response.text}")
count = None
summary_file = "src/SUMMARY.md"
with open(summary_file, "w", encoding="utf-8") as file:
file.write(f"# Summary\n")
file.write(f"\n")
file.write(f"[About Me](./README.md)\n")
for issue in all_issues:
if "TODO" in get_labels(issue):
continue
file.write(f"[{issue['number']}. {issue['title']}](./blogs/qiwihui-blog-{issue['number']}.md)\n")
file.write("\n")