-
Notifications
You must be signed in to change notification settings - Fork 0
/
github_client.py
54 lines (45 loc) · 1.9 KB
/
github_client.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
import requests
import datetime
class GitHubClient:
API_BASE_URL = 'https://api.github.com'
def __init__(self, token):
self.token = token
self.headers = {'Authorization': f'token {self.token}'}
def fetch_updates(self, repo):
# 获取特定 repo 的更新(commits, issues, pull requests)
updates = {
'commits': self.fetch_commits(repo),
'issues': self.fetch_issues(repo),
'pull_requests': self.fetch_pull_requests(repo)
}
return updates
def fetch_commits(self, repo):
url = f'{self.API_BASE_URL}/repos/{repo}/commits'
response = requests.get(url, headers=self.headers)
response.raise_for_status()
return response.json()
def fetch_issues(self, repo):
url = f'{self.API_BASE_URL}/repos/{repo}/issues'
response = requests.get(url, headers=self.headers)
response.raise_for_status()
return response.json()
def fetch_pull_requests(self, repo):
url = f'{self.API_BASE_URL}/repos/{repo}/pulls'
response = requests.get(url, headers=self.headers)
response.raise_for_status()
return response.json()
def export_daily_progress(self, repo):
date_str = datetime.datetime.now().strftime('%Y-%m-%d')
issues = self.fetch_issues(repo)
pull_requests = self.fetch_pull_requests(repo)
filename = f'daily_progress/{repo.replace("/", "_")}_{date_str}.md'
with open(filename, 'w') as f:
f.write(f"# {repo} Daily Progress - {date_str}\n\n")
f.write("## Issues\n")
for issue in issues:
f.write(f"- {issue['title']} #{issue['number']}\n")
f.write("\n## Pull Requests\n")
for pr in pull_requests:
f.write(f"- {pr['title']} #{pr['number']}\n")
print(f"Exported daily progress to {filename}")
return filename