Skip to content

Commit e3e42b6

Browse files
author
lijunnzhang
committed
feat: add repo.report command
1 parent d803a91 commit e3e42b6

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ On windows should be: `C:\\User\\<your username>`
206206
| counter_format | str | table | Output format of statistical results. Supported: [table, simple] |
207207
| git_config_format | str | table | Git local config print format. Supported: [table, normal] |
208208
| repo_info_include | list | ["remote", "branch", "log"] | Control which parts need to be displayed when viewing git repository information. Support: (path,remote,branch,log,summary) |
209-
| repo_auto_append | bool | False | Whether auto append path to repos. |
209+
| repo_auto_append | bool | True | Whether auto append path to repos. |
210210
| log_debug | bool | False | Whether run PIGIT in debug mode. |
211211
| log_output | bool | False | Whether output log in terminal. |
212212

pigit/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class Config(metaclass=Singleton):
119119
repo_info_include: List[str] = ["remote", "branch", "log"]
120120

121121
# repo conf
122-
repo_auto_append: bool = False
122+
repo_auto_append: bool = True
123123

124124
# setting conf
125125
log_debug: bool = False

pigit/entry.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ def _(args: "Namespace", unknown: List):
238238

239239
# If you want to manipulate the current folder with git,
240240
# try adding it to repos automatically.
241+
print(Conf.repo_auto_append)
241242
if Conf.repo_auto_append:
242243
repo_path, repo_conf = repo_handler.confirm_repo()
243244
repo_handler.add_repos([repo_path])
@@ -360,6 +361,19 @@ def repo_ll(args, _):
360361
)
361362

362363

364+
@repo.sub_parser("report", help="genereate report of all repos.")
365+
@argument("--author", type=str, required=True, help="select author of commits.")
366+
@argument("--since", type=str,default='', help="start range of commits.")
367+
@argument("--util", type=str,default='', help="end range of commmits.")
368+
def repo_report(args, _):
369+
report = repo_handler.report_repos(
370+
author=args.author,
371+
since=args.since,
372+
util=args.util,
373+
)
374+
console.echo(report)
375+
376+
363377
@repo.sub_parser("cd", help="jump to a repo dir.")
364378
@argument("repo", nargs="?", help="the name of repo.")
365379
def _(args, _):

pigit/git/repo.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import Callable, Dict, List, Optional, Tuple, Union, Generator
88
from collections import Counter
99
from pathlib import Path
10+
import pprint
1011

1112
from plenty.str_utils import shorten, byte_str2str
1213
from plenty.console import Console
@@ -711,6 +712,49 @@ def dump_repos(self, repos: Dict) -> bool:
711712
def clear_repos(self) -> None:
712713
self.repo_json_path.unlink(missing_ok=True)
713714

715+
def report_repos(self, author: str, since: str, util: str) -> str:
716+
"""Generate report of repos.
717+
718+
range e.g.:
719+
git log --since="2023-01-01" --until="2023-12-31"
720+
git log --since="1 month ago" --until="1 day ago"
721+
git log --since="1672531200" --until="1675212800"
722+
"""
723+
exist_repos = self.load_repos()
724+
if len(exist_repos) == 0:
725+
return "No repo(s) managed."
726+
727+
command = f"git log --color=never --oneline"
728+
if author != "":
729+
command += f' --author="{author}"'
730+
if since != "":
731+
command += f' --since="{since}"'
732+
if util != "":
733+
command += f' --grep="{util}"'
734+
if since == "" and util == "":
735+
command += " -30"
736+
737+
report_dict = {}
738+
for repo_name, prop in exist_repos.items():
739+
repo_path = prop["path"]
740+
_, err, resp = self.executor.exec(
741+
command, flags=REPLY | DECODE, cwd=repo_path
742+
)
743+
744+
commits = []
745+
for line in resp.split("\n"):
746+
if line == "":
747+
continue
748+
749+
line = line.split(" ", maxsplit=1)[1]
750+
if line.startswith("Merge branch"):
751+
continue
752+
753+
commits.append(line)
754+
755+
report_dict[repo_name] = commits
756+
pprint.pprint(report_dict)
757+
714758
def ll_repos(self, reverse: bool = False) -> Generator[List[Tuple], None, None]:
715759
exist_repos = self.load_repos()
716760

0 commit comments

Comments
 (0)