-
Notifications
You must be signed in to change notification settings - Fork 4
/
change-author.py
35 lines (31 loc) · 1.21 KB
/
change-author.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
#!/usr/bin/env python3
import subprocess
import os
import re
# 定义要匹配的提交信息模式
commit_pattern = r"GitHub Actions Crawler ALL IN ONE at \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}"
# 创建环境变量设置命令
new_env = {
'GIT_AUTHOR_NAME': 'github-actions[bot]',
'GIT_AUTHOR_EMAIL': '41898282+github-actions[bot]@users.noreply.github.com',
'GIT_COMMITTER_NAME': 'github-actions[bot]',
'GIT_COMMITTER_EMAIL': '41898282+github-actions[bot]@users.noreply.github.com'
}
# 使用 git filter-branch
cmd = '''
git filter-branch -f --env-filter '
COMMIT_MSG=$(git log --format=%B -n 1 $GIT_COMMIT)
if [[ $COMMIT_MSG =~ "GitHub Actions Crawler ALL IN ONE at" ]]; then
export GIT_AUTHOR_NAME="github-actions[bot]"
export GIT_AUTHOR_EMAIL="41898282+github-actions[bot]@users.noreply.github.com"
export GIT_COMMITTER_NAME="github-actions[bot]"
export GIT_COMMITTER_EMAIL="41898282+github-actions[bot]@users.noreply.github.com"
else
export GIT_AUTHOR_NAME="$GIT_AUTHOR_NAME"
export GIT_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL"
export GIT_COMMITTER_NAME="$GIT_COMMITTER_NAME"
export GIT_COMMITTER_EMAIL="$GIT_COMMITTER_EMAIL"
fi
' --tag-name-filter cat -- --all
'''
subprocess.run(cmd, shell=True)