-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_log_of_today.py
More file actions
executable file
·67 lines (45 loc) · 1.82 KB
/
github_log_of_today.py
File metadata and controls
executable file
·67 lines (45 loc) · 1.82 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
#!/usr/bin/env python
from plumbum import cli, local # See https://plumbum.readthedocs.io/en/latest/cli.html
from datetime import date, timedelta
import re
class DateValidator(cli.switches.Validator):
"""
A switch-type validator that checks if the argument is a date
"""
def __call__(self, obj):
try:
obj = date.fromisoformat(obj)
except ValueError:
print(obj + " is not a date in the correct format : %Y-%m-%d")
exit(1)
return obj
def __repr__(self):
return "Just a date validator"
class GithubLog(cli.Application):
"""
Get commits since <date> of the current git directory, and create github links to see it.
"""
verbose = cli.Flag(["v", "verbose"], help="If given, I will be very talkative")
_firefox = True
@cli.switch(["n", "nofirefox"])
def not_open_firefox(self):
"""Don’t open link in firefox"""
self._firefox = False
def main(self, date_since:DateValidator()=None):
if date_since is None:
date_since = date.today()
date_since = date_since - timedelta(1)
print("Used date : " + str(date_since))
git = local["git"]
commits = git(["log", "--oneline", f"--since={date_since}"])
commits = commits.strip().split("\n")
first_commit = commits[-1].split()[0]
last_commit = commits[0].split()[0]
previous_commit = git(["log", "--oneline", f"{first_commit}^", "-1"]).strip().split()[0]
remote = re.search(r"dionisos2/(.*)\.git", git(["remote", "-v"])).group(1)
result = f"https://github.com/dionisos2/{remote}/compare/{previous_commit}...{last_commit}"
print(result)
if self._firefox:
local["firefox-developer-edition"](result)
if __name__ == "__main__":
GithubLog.run()