Advertisement
Danny_Berova

08.Commits

Aug 11th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.36 KB | None | 0 0
  1. namespace _08.Commits
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.     using System.Text.RegularExpressions;
  7.  
  8.     public class Comites
  9.     {
  10.         public string Hash { get; set; }
  11.         public string Message { get; set; }
  12.         public decimal Additions { get; set; }
  13.         public decimal Deletions { get; set; }
  14.  
  15.         public Comites(string hash, string message, decimal additions, decimal deletions)
  16.         {
  17.             this.Hash = hash;
  18.             this.Message = message;
  19.             this.Additions = additions;
  20.             this.Deletions = deletions;
  21.         }
  22.     }
  23.  
  24.     public class Commits
  25.     {
  26.  
  27.         public static void Main()
  28.         {
  29.             SortedDictionary<string, SortedDictionary<string, List<Comites>>> usersInfo = new SortedDictionary<string, SortedDictionary<string, List<Comites>>>();
  30.  
  31.             string inputLine = Console.ReadLine();
  32.  
  33.             while (inputLine != "git push")
  34.             {
  35.                 Regex parts = new Regex(@"^https:\/\/github.com\/(?<ussername>[A-Za-z0-9\-]+)\/(?<repoName>[A-Za-z\-_]+)\/commit\/(?<hash>[0-9a-f]{40}),(?<message>[^\n]*),(?<additions>[0-9]*),(?<deletions>[0-9]*)$");
  36.  
  37.                 var allParts = parts.Match(inputLine);
  38.  
  39.                 if (allParts.Success)
  40.                 {
  41.  
  42.                     string userName = allParts.Groups["ussername"].Value;
  43.                     string repoName = allParts.Groups["repoName"].Value;
  44.                     string hash = allParts.Groups["hash"].Value;
  45.                     string message = allParts.Groups["message"].Value;
  46.                     decimal additions = decimal.Parse(allParts.Groups["additions"].Value);
  47.                     decimal deletions = decimal.Parse(allParts.Groups["deletions"].Value);
  48.  
  49.                     Comites commitInfo = new Comites(hash, message, additions, deletions);
  50.  
  51.                     if (!usersInfo.ContainsKey(userName))
  52.                     {
  53.                         usersInfo[userName] = new SortedDictionary<string, List<Comites>>();
  54.                     }
  55.                     if (!usersInfo[userName].ContainsKey(repoName))
  56.                     {
  57.                         usersInfo[userName][repoName] = new List<Comites>();
  58.                     }
  59.  
  60.                     usersInfo[userName][repoName].Add(commitInfo);
  61.                 }
  62.  
  63.                 inputLine = Console.ReadLine();
  64.             }
  65.  
  66.             decimal totalAdditions = 0m;
  67.             decimal totalDeletions = 0m;
  68.  
  69.             foreach (var person in usersInfo)
  70.             {
  71.                 Console.WriteLine($"{person.Key}:");
  72.                
  73.  
  74.                 foreach (var repo in person.Value)
  75.                 {
  76.                     Console.WriteLine($"{repo.Key}:");
  77.  
  78.                     foreach (var commit in repo.Value)
  79.                     {
  80.                         totalAdditions += commit.Additions;
  81.                         totalDeletions += commit.Deletions;
  82.  
  83.                         Console.WriteLine($"    commit {commit.Hash}: {commit.Message} ({commit.Additions} additions, {commit.Deletions} deletions)");
  84.                     }
  85.  
  86.                     Console.WriteLine($"    Total: {totalAdditions} additions, {totalDeletions} deletions");
  87.  
  88.                     totalAdditions = 0m;
  89.                     totalDeletions = 0m;
  90.                 }
  91.             }
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement