Skip to content

Commit 74de54f

Browse files
authored
Merge pull request #6 from DjangoPeng/v0.3.2
Cherry-pick v0.3.2 to main branch
2 parents 0e06516 + 83b163b commit 74de54f

10 files changed

+15510
-870
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,5 @@ cython_debug/
163163

164164
# User-defined
165165
daily_progress/*
166-
166+
src/jupyter/*.md
167+
src/jupyter/daily_progress/*

src/github_client.py

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,40 @@
1-
import requests
2-
from datetime import datetime, date, timedelta
3-
import os
4-
from logger import LOG
1+
# src/github_client.py
2+
3+
import requests # 导入requests库用于HTTP请求
4+
from datetime import datetime, date, timedelta # 导入日期处理模块
5+
import os # 导入os模块用于文件和目录操作
6+
from logger import LOG # 导入日志模块
57

68
class GitHubClient:
79
def __init__(self, token):
8-
self.token = token
9-
self.headers = {'Authorization': f'token {self.token}'}
10+
self.token = token # GitHub API令牌
11+
self.headers = {'Authorization': f'token {self.token}'} # 设置HTTP头部认证信息
1012

1113
def fetch_updates(self, repo, since=None, until=None):
14+
# 获取指定仓库的更新,可以指定开始和结束日期
1215
updates = {
13-
'commits': self.fetch_commits(repo, since, until),
14-
'issues': self.fetch_issues(repo, since, until),
15-
'pull_requests': self.fetch_pull_requests(repo, since, until)
16+
'commits': self.fetch_commits(repo, since, until), # 获取提交记录
17+
'issues': self.fetch_issues(repo, since, until), # 获取问题
18+
'pull_requests': self.fetch_pull_requests(repo, since, until) # 获取拉取请求
1619
}
1720
return updates
1821

1922
def fetch_commits(self, repo, since=None, until=None):
20-
url = f'https://api.github.com/repos/{repo}/commits'
23+
url = f'https://api.github.com/repos/{repo}/commits' # 构建获取提交的API URL
2124
params = {}
2225
if since:
23-
params['since'] = since
26+
params['since'] = since # 如果指定了开始日期,添加到参数中
2427
if until:
25-
params['until'] = until
28+
params['until'] = until # 如果指定了结束日期,添加到参数中
2629

2730
response = requests.get(url, headers=self.headers, params=params)
28-
response.raise_for_status()
29-
return response.json()
31+
response.raise_for_status() # 检查请求是否成功
32+
return response.json() # 返回JSON格式的数据
3033

3134
def fetch_issues(self, repo, since=None, until=None):
32-
url = f'https://api.github.com/repos/{repo}/issues'
35+
url = f'https://api.github.com/repos/{repo}/issues' # 构建获取问题的API URL
3336
params = {
34-
'state': 'closed',
37+
'state': 'closed', # 仅获取已关闭的问题
3538
'since': since,
3639
'until': until
3740
}
@@ -40,9 +43,9 @@ def fetch_issues(self, repo, since=None, until=None):
4043
return response.json()
4144

4245
def fetch_pull_requests(self, repo, since=None, until=None):
43-
url = f'https://api.github.com/repos/{repo}/pulls'
46+
url = f'https://api.github.com/repos/{repo}/pulls' # 构建获取拉取请求的API URL
4447
params = {
45-
'state': 'closed',
48+
'state': 'closed', # 仅获取已合并的拉取请求
4649
'since': since,
4750
'until': until
4851
}
@@ -51,46 +54,46 @@ def fetch_pull_requests(self, repo, since=None, until=None):
5154
return response.json()
5255

5356
def export_daily_progress(self, repo):
54-
today = datetime.now().date().isoformat()
55-
updates = self.fetch_updates(repo, since=today)
57+
today = datetime.now().date().isoformat() # 获取今天的日期
58+
updates = self.fetch_updates(repo, since=today) # 获取今天的更新数据
5659

57-
repo_dir = os.path.join('daily_progress', repo.replace("/", "_"))
58-
os.makedirs(repo_dir, exist_ok=True)
60+
repo_dir = os.path.join('daily_progress', repo.replace("/", "_")) # 构建存储路径
61+
os.makedirs(repo_dir, exist_ok=True) # 确保目录存在
5962

60-
file_path = os.path.join(repo_dir, f'{today}.md')
63+
file_path = os.path.join(repo_dir, f'{today}.md') # 构建文件路径
6164
with open(file_path, 'w') as file:
6265
file.write(f"# Daily Progress for {repo} ({today})\n\n")
6366
file.write("\n## Issues Closed Today\n")
64-
for issue in updates['issues']:
67+
for issue in updates['issues']: # 写入今天关闭的问题
6568
file.write(f"- {issue['title']} #{issue['number']}\n")
6669
file.write("\n## Pull Requests Merged Today\n")
67-
for pr in updates['pull_requests']:
70+
for pr in updates['pull_requests']: # 写入今天合并的拉取请求
6871
file.write(f"- {pr['title']} #{pr['number']}\n")
6972

70-
LOG.info(f"Exported daily progress to {file_path}")
73+
LOG.info(f"Exported daily progress to {file_path}") # 记录日志
7174
return file_path
7275

7376
def export_progress_by_date_range(self, repo, days):
74-
today = date.today()
75-
since = today - timedelta(days=days)
77+
today = date.today() # 获取当前日期
78+
since = today - timedelta(days=days) # 计算开始日期
7679

77-
updates = self.fetch_updates(repo, since=since.isoformat(), until=today.isoformat())
80+
updates = self.fetch_updates(repo, since=since.isoformat(), until=today.isoformat()) # 获取指定日期范围内的更新
7881

79-
repo_dir = os.path.join('daily_progress', repo.replace("/", "_"))
80-
os.makedirs(repo_dir, exist_ok=True)
82+
repo_dir = os.path.join('daily_progress', repo.replace("/", "_")) # 构建目录路径
83+
os.makedirs(repo_dir, exist_ok=True) # 确保目录存在
8184

82-
# Updated filename with date range
85+
# 更新文件名以包含日期范围
8386
date_str = f"{since}_to_{today}"
84-
file_path = os.path.join(repo_dir, f'{date_str}.md')
87+
file_path = os.path.join(repo_dir, f'{date_str}.md') # 构建文件路径
8588

8689
with open(file_path, 'w') as file:
8790
file.write(f"# Progress for {repo} ({since} to {today})\n\n")
88-
file.write("\n## Issues Closed in the Last {days} Days\n")
89-
for issue in updates['issues']:
91+
file.write(f"\n## Issues Closed in the Last {days} Days\n")
92+
for issue in updates['issues']: # 写入在指定日期内关闭的问题
9093
file.write(f"- {issue['title']} #{issue['number']}\n")
91-
file.write("\n## Pull Requests Merged in the Last {days} Days\n")
92-
for pr in updates['pull_requests']:
94+
file.write(f"\n## Pull Requests Merged in the Last {days} Days\n")
95+
for pr in updates['pull_requests']: # 写入在指定日期内合并的拉取请求
9396
file.write(f"- {pr['title']} #{pr['number']}\n")
9497

95-
LOG.info(f"Exported time-range progress to {file_path}")
98+
LOG.info(f"Exported time-range progress to {file_path}") # 记录日志
9699
return file_path

0 commit comments

Comments
 (0)