Advertisement
Guest User

Untitled

a guest
Apr 14th, 2017
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.63 KB | None | 0 0
  1. namespace _05.Commits
  2. {
  3.     public class Commit
  4.     {
  5.         public string CommitHash { get; set; }
  6.         public string Message { get; set; }
  7.         public int Additions { get; set; }
  8.         public int Deletions { get; set; }
  9.     }
  10.     class Commits
  11.     {
  12.         static void Main()
  13.         {
  14.             var users = new Dictionary<string,Dictionary<string,List<Commit>>>();
  15.             var input = Console.ReadLine();
  16.  
  17.             var pattern = @"https:\/\/github\.com\/([A-z\d\-]+)\/([A-z\-_]+)\/commit\/([a-f\d]{40})\,(.*?[^\n])\,(\d+)\,(\d+)";
  18.             var regex = new Regex(pattern);
  19.            
  20.             while (input != "git push")
  21.             {
  22.                 var matches = regex.Matches(input);
  23.                 var username = string.Empty;
  24.                 var repository = string.Empty;
  25.                 var commitHash = string.Empty;
  26.                 var message = string.Empty;
  27.                 var additions = 0;
  28.                 var deletions = 0;
  29.                
  30.                 var isMatch = regex.IsMatch(input);
  31.                
  32.                 if (isMatch)
  33.                 {
  34.                     foreach (Match match in matches)
  35.                     {
  36.                         username = match.Groups[1].Value;
  37.                         repository = match.Groups[2].Value;
  38.                         commitHash = match.Groups[3].Value;
  39.                         message = match.Groups[4].Value;
  40.                         additions = int.Parse(match.Groups[5].Value);
  41.                         deletions = int.Parse(match.Groups[6].Value);
  42.                     }
  43.                    
  44.                     if (!users.ContainsKey(username))
  45.                     {
  46.                         users[username] = new Dictionary<string, List<Commit>>();
  47.                     }
  48.                    
  49.                     if (!users[username].ContainsKey(repository))
  50.                     {
  51.                         users[username][repository] = new List<Commit>();
  52.                         var newCommit = new Commit
  53.                         {
  54.                             CommitHash = commitHash,
  55.                             Message = message,
  56.                             Additions = additions,
  57.                             Deletions = deletions
  58.                         };
  59.                         users[username][repository].Add(newCommit);
  60.                     }
  61.                     else
  62.                     {
  63.                         var newCommit = new Commit
  64.                         {
  65.                             CommitHash = commitHash,
  66.                             Message = message,
  67.                             Additions = additions,
  68.                             Deletions = deletions
  69.                         };
  70.                         users[username][repository].Add(newCommit);
  71.                     }
  72.                 }
  73.                 input = Console.ReadLine();
  74.             }
  75.            
  76.             foreach (var user in users.OrderBy(x => x.Key))
  77.             {
  78.                 Console.WriteLine($"{user.Key}:");
  79.                 var repos = user.Value;
  80.                 foreach (var repo in repos.OrderBy(x => x.Key))
  81.                 {
  82.                     Console.WriteLine($"  {repo.Key}:");
  83.                     var commits = repos.Values;
  84.                     var totalAdd = 0;
  85.                     var totalDelete = 0;
  86.                     foreach (var commit in commits)
  87.                     {
  88.                         foreach (var element in commit)
  89.                         {
  90.                             totalAdd += element.Additions;
  91.                             totalDelete += element.Deletions;
  92.                            
  93.                             Console.WriteLine($"    commit {element.CommitHash}: {element.Message} ({element.Additions} additions, {element.Deletions} deletions)");
  94.                             }
  95.                     }
  96.                     Console.WriteLine($"    Total: {totalAdd} additions, {totalDelete} deletions");
  97.                 }
  98.              }
  99.         }
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement