-
Notifications
You must be signed in to change notification settings - Fork 9
/
git_tag.py
57 lines (50 loc) · 2.11 KB
/
git_tag.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import logging, os
from apktool import *
from files import *
from logger import config_logging
from pathlib import Path
def add_new_tag(info: ApkInfo):
'''Add current new tag.'''
os.system("cd %s && git tag v%s && git push origin --tags"
% (config.gradlew_location, info.version_name))
def gen_git_log(info: ApkInfo):
'''Generate git tag logs.'''
# Get last commit log pattern.
last_git_tag = _find_last_git_tag()
if len(last_git_tag) == 0:
logi("Last git tag not found.")
return
_append_gitlog_to_markdown(info, last_git_tag)
def _append_gitlog_to_markdown(info: ApkInfo, last_git_tag: str):
'''Append gitlog to markdown gitlog file.'''
po = os.popen("cd %s && git log %s..HEAD --oneline" % (config.gradlew_location, last_git_tag))
git_logs = po.buffer.read().decode('utf-8').strip()
markdown_git_logs = ('## %s \n - ' % info.version_name) + '\n- '.join(git_logs.split('\n'))
content = ''
if os.path.exists(config.output_gitlog_store_file):
content = read_file(config.output_gitlog_store_file)
content = markdown_git_logs + '\n' + content
write_file(config.output_gitlog_store_file, content)
_commit_git_log_change_event(info)
return git_logs
def _commit_git_log_change_event(info: ApkInfo):
'''Commit git log file to community repo.'''
gitlog_store_file_path = Path(config.output_gitlog_store_file)
gitlog_store_file_dir = gitlog_store_file_path.parent
gitlog_store_file_name = os.path.basename(config.output_gitlog_store_file)
os.system("cd %s\
&& git pull \
&& git add %s\
&& git commit -m \"feat: add upgrade logs for %s\"\
&& git push"
% (gitlog_store_file_dir, gitlog_store_file_name, info.version_name))
def _find_last_git_tag() -> str:
'''Get last version git tag'''
last_version_name = os.popen(
"cd %s && git describe --abbrev=0 --tags" % (config.gradlew_location)).read().strip()
return last_version_name
if __name__ == "__main__":
config_logging()
print(gen_git_log(ApkInfo(version_name="test")))