forked from lengstrom/gitlinks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.py
43 lines (27 loc) · 1011 Bytes
/
scripts.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
import csv
import pandas as pd
import regex as re
from git.repo import Repo
from tqdm import tqdm
def export_commit_history(repo_path, csv_path):
repo = Repo(path=repo_path)
commits = list(repo.iter_commits())[::-1]
# get all keys in csv
df=pd.read_csv(csv_path)
keys = set(df['key'])
for commit in tqdm(commits):
if str(commit.message).startswith('Set key '):
key = re.search(r'\"(.+?)\"', commit.message).group(1)
if key in keys:
# print(commit.committed_datetime, key)
df.loc[df['key'] == key, 'date'] = commit.committed_datetime.strftime('%Y-%m-%d %H:%M:%S')
df.to_csv(csv_path, index=False)
def add_hide_column(csv_path):
df = pd.read_csv(csv_path)
df['hide'] = False
df.to_csv(csv_path, index=False)
if __name__ == "__main__":
# `cp ~/.gitlinks/index.csv .`
export_commit_history('~/.gitlinks/.git', 'index.csv')
add_hide_column('index.csv')
# `cp index.csv ~/.golink`