Advertisement
Guest User

Untitled

a guest
Apr 1st, 2023
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.96 KB | None | 0 0
  1. import re
  2.  
  3.  
  4. class Commits:
  5.     def __init__(self, hash, message, additions, deletions, insert_order):
  6.         self.hash = hash
  7.         self.message = message
  8.         self.additions = additions
  9.         self.deletions = deletions
  10.         self.insert_order = insert_order
  11.  
  12.  
  13. pattern = re.compile(r"^https://github\.com/(?P<name>[A-Za-z\d\-]+)/"
  14.                      r"(?P<repo>[A-Za-z_\-]+)/commit/(?P<hash>[A-Fa-f\d]{40}),(?P<message>.+),"
  15.                      r"(?P<additions>\d+),(?P<deletions>\d+)$")
  16.  
  17. commits = {}
  18. insert_order = 0
  19. while True:
  20.     line = input()
  21.  
  22.     if line == "git push":
  23.         break
  24.  
  25.     match = re.fullmatch(pattern, line)
  26.     if not match:
  27.         continue
  28.  
  29.     user = match.group(1)
  30.     repo = match.group(2)
  31.     hash = match.group(3)
  32.     message = match.group(4)
  33.     additions = int(match.group(5))
  34.     deletions = int(match.group(6))
  35.  
  36.     if user not in commits:
  37.         commits[user] = {}
  38.     if repo not in commits[user]:
  39.         commits[user][repo] = []
  40.  
  41.     insert_order += 1
  42.     commit = Commits(hash, message, additions, deletions, insert_order)
  43.     commits[user][repo].append(commit)
  44.  
  45. sorted_users = dict(sorted(commits.items(), key=lambda x: x[0]))        # change
  46. for user in sorted_users:
  47.     print(f"{user}:")
  48.     sorted_repos = dict(sorted(sorted_users[user].items(), key=lambda x: x[0]))     # change
  49.     for repo in sorted_repos:
  50.         total_additions = 0     # change
  51.         total_deletions = 0     # change
  52.         print(f"  {repo}:")
  53.         sorted_commits = sorted(sorted_repos[repo], key=lambda c: c.insert_order)
  54.         for commit in sorted_repos[repo]:
  55.             print(
  56.                 f"    commit {commit.hash}: {commit.message} ({commit.additions} additions, {commit.deletions} deletions)")
  57.             total_additions += commit.additions
  58.             total_deletions += commit.deletions
  59.         print(f"    Total: {total_additions} additions, {total_deletions} deletions")       # change
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement