-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinal_fix.py
More file actions
127 lines (92 loc) · 3.47 KB
/
Copy pathfinal_fix.py
File metadata and controls
127 lines (92 loc) · 3.47 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
#!/usr/bin/env python3
import os
import random
import subprocess
import datetime
from pathlib import Path
REPO_ROOT = Path(__file__).parent
def get_existing_dates():
result = subprocess.run(
['git', 'log', '--pretty=format:%ad', '--date=short', '--all'],
cwd=REPO_ROOT, capture_output=True, text=True
)
return {d for d in result.stdout.strip().split('\n') if d}
def create_commit(target_date):
files = list(REPO_ROOT.glob('**/*.py')) + list(REPO_ROOT.glob('**/*.md'))
files = [f for f in files if '__pycache__' not in str(f) and '.git' not in str(f)]
if not files:
return False
f = random.choice(files)
try:
with open(f, 'r', encoding='utf-8', errors='ignore') as fp:
content = fp.read()
new_content = content + f"\n# {random.choice(['优化', '修复', '重构', '改进'])}\n"
with open(f, 'w', encoding='utf-8') as fp:
fp.write(new_content)
subprocess.run(['git', 'add', str(f)], cwd=REPO_ROOT, capture_output=True)
dt = datetime.datetime.strptime(target_date, '%Y-%m-%d')
dt = dt.replace(hour=random.randint(9, 21), minute=random.randint(0, 59))
git_date = dt.strftime('%a %b %d %H:%M:%S %Y +0000')
env = os.environ.copy()
env['GIT_AUTHOR_DATE'] = git_date
env['GIT_COMMITTER_DATE'] = git_date
env['GIT_AUTHOR_NAME'] = 'norbertm2050'
env['GIT_AUTHOR_EMAIL'] = 'norbertm2050@gmail.com'
env['GIT_COMMITTER_NAME'] = 'norbertm2050'
env['GIT_COMMITTER_EMAIL'] = 'norbertm2050@gmail.com'
result = subprocess.run(
['git', 'commit', '-m', random.choice(['Update', 'Fix', 'Improve', 'Refactor'])],
cwd=REPO_ROOT, env=env, capture_output=True, text=True
)
return result.returncode == 0
except:
return False
def main():
print("=== 最终修复 ===\n")
subprocess.run(['git', 'checkout', 'full-contributions'], cwd=REPO_ROOT, capture_output=True)
today = datetime.datetime.now().date()
start_date = today - datetime.timedelta(days=364)
existing = get_existing_dates()
# 找出缺失的日期
missing = []
current = start_date
while current <= today:
ds = current.strftime('%Y-%m-%d')
if ds not in existing:
missing.append(ds)
current += datetime.timedelta(days=1)
print(f"缺失天数: {len(missing)}")
print(f"缺失日期: {missing}\n")
# 为每个缺失日期创建多个提交
for date_str in missing:
for _ in range(random.randint(2, 4)):
create_commit(date_str)
# 验证
final = get_existing_dates()
coverage = sum(1 for d in final
if start_date <= datetime.datetime.strptime(d, '%Y-%m-%d').date() <= today)
print(f"最终覆盖: {coverage}/365 天")
# 推送
print("\n推送到GitHub...")
subprocess.run(['git', 'push', '-u', 'fork', 'full-contributions:main', '--force'],
cwd=REPO_ROOT, capture_output=True)
print("✅ 完成!")
if __name__ == "__main__":
main()
# 添加日志记录
# 修复边界情况
# 增强功能
# 重构代码
# 添加验证
# 重构代码
# 重构代码 - 36
# 添加验证 - 72
# 添加日志记录 - 17
# 更新文档 - 64
# 改进错误处理 - 141
# 重构代码 - 253
# 优化性能 - 331
# 重构代码 - 368
# 优化性能 - 376
# 重构代码 - 517
# 更新文档 - 570