From 9e4a2eb24ad1882cee1cc9d43f0af0faff2ba861 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Thu, 10 Sep 2020 14:30:00 +0300 Subject: Working on Tango.Git and Tag creation upon release. --- Software/Visual_Studio/Tango.Git/GitCommit.cs | 13 ++ Software/Visual_Studio/Tango.Git/GitFile.cs | 14 +++ Software/Visual_Studio/Tango.Git/GitFileState.cs | 14 +++ .../Tango.Git/GitRepositoryManager.cs | 132 +++++++++++++++++++++ .../Tango.Git/Properties/AssemblyInfo.cs | 36 ++++++ Software/Visual_Studio/Tango.Git/Tango.Git.csproj | 72 +++++++++++ Software/Visual_Studio/Tango.Git/packages.config | 5 + 7 files changed, 286 insertions(+) create mode 100644 Software/Visual_Studio/Tango.Git/GitCommit.cs create mode 100644 Software/Visual_Studio/Tango.Git/GitFile.cs create mode 100644 Software/Visual_Studio/Tango.Git/GitFileState.cs create mode 100644 Software/Visual_Studio/Tango.Git/GitRepositoryManager.cs create mode 100644 Software/Visual_Studio/Tango.Git/Properties/AssemblyInfo.cs create mode 100644 Software/Visual_Studio/Tango.Git/Tango.Git.csproj create mode 100644 Software/Visual_Studio/Tango.Git/packages.config (limited to 'Software/Visual_Studio/Tango.Git') diff --git a/Software/Visual_Studio/Tango.Git/GitCommit.cs b/Software/Visual_Studio/Tango.Git/GitCommit.cs new file mode 100644 index 000000000..fc388176b --- /dev/null +++ b/Software/Visual_Studio/Tango.Git/GitCommit.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Git +{ + public class GitCommit + { + public String Message { get; set; } + } +} diff --git a/Software/Visual_Studio/Tango.Git/GitFile.cs b/Software/Visual_Studio/Tango.Git/GitFile.cs new file mode 100644 index 000000000..899fa839e --- /dev/null +++ b/Software/Visual_Studio/Tango.Git/GitFile.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Git +{ + public class GitFile + { + public String File { get; set; } + public GitFileState State { get; set; } + } +} diff --git a/Software/Visual_Studio/Tango.Git/GitFileState.cs b/Software/Visual_Studio/Tango.Git/GitFileState.cs new file mode 100644 index 000000000..4c8bb6c14 --- /dev/null +++ b/Software/Visual_Studio/Tango.Git/GitFileState.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Git +{ + public enum GitFileState + { + Added, + Modified + } +} diff --git a/Software/Visual_Studio/Tango.Git/GitRepositoryManager.cs b/Software/Visual_Studio/Tango.Git/GitRepositoryManager.cs new file mode 100644 index 000000000..e7fdf8e32 --- /dev/null +++ b/Software/Visual_Studio/Tango.Git/GitRepositoryManager.cs @@ -0,0 +1,132 @@ +using LibGit2Sharp; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; + +namespace Tango.Git +{ + public class GitRepositoryManager : IDisposable + { + private Repository _repo; + private String _pat; + private String _userEmail; + + public event EventHandler> Progress; + + public GitRepositoryManager(String localFolder, String userEmail, String personalAccessToken) + { + _pat = personalAccessToken; + _userEmail = userEmail; + _repo = new Repository(localFolder); + } + + public void CreatePushTag(String name, String description, String userName) + { + var tag = _repo.ApplyTag(name, new Signature(userName, _userEmail, DateTime.Now), description); + + _repo.Network.Push(_repo.Network.Remotes.First(), tag.CanonicalName, new PushOptions() + { + CredentialsProvider = new LibGit2Sharp.Handlers.CredentialsHandler(CredentialsHandlerMethod), + OnPushTransferProgress = new LibGit2Sharp.Handlers.PushTransferProgressHandler(PushTagProgressHandlerMethod) + }); + } + + private bool PushTagProgressHandlerMethod(int current, int total, long bytes) + { + //TODO: Implement via TangoProgress & event... + RaiseProgress("Pushing Tag...", false, 0, total); + return true; + } + + public List GetOutgoingCommits(String branchName = "master") + { + List commits = new List(); + + var branch = _repo.Branches.FirstOrDefault(x => x.FriendlyName == branchName); + + if (branch.TrackingDetails.AheadBy != null) + { + foreach (var commit in _repo.Commits.Take(branch.TrackingDetails.AheadBy.Value)) + { + commits.Add(new GitCommit() + { + Message = commit.Message + }); + } + } + + return commits; + } + + public List GetIncomingCommits() + { + List commits = new List(); + + var trackingBranch = _repo.Head.TrackedBranch; + var log = _repo.Commits.QueryBy(new CommitFilter { IncludeReachableFrom = trackingBranch.Tip.Id, ExcludeReachableFrom = _repo.Head.Tip.Id }); + + var count = log.Count(); + + foreach (var commit in log) + { + commits.Add(new GitCommit() + { + Message = commit.Message + }); + } + + return commits; + } + + public List GetChanges() + { + List files = new List(); + + var status = _repo.RetrieveStatus(); + + foreach (var file in status.Added) + { + files.Add(new GitFile() + { + File = file.FilePath, + State = GitFileState.Added + }); + } + + foreach (var file in status.Modified) + { + files.Add(new GitFile() + { + File = file.FilePath, + State = GitFileState.Modified + }); + } + + return files; + } + + private Credentials CredentialsHandlerMethod(string url, string usernameFromUrl, SupportedCredentialTypes types) + { + return new UsernamePasswordCredentials { Username = _userEmail, Password = _pat }; + } + + protected virtual void RaiseProgress(String message, bool isIndeterminate = true, double value = 0, double maximum = 100) + { + Progress?.Invoke(this, new TangoProgressChangedEventArgs(new TangoProgress() + { + IsIndeterminate = isIndeterminate, + Message = message, + Value = value, + Maximum = maximum + })); + } + + public void Dispose() + { + _repo.Dispose(); + } + } +} diff --git a/Software/Visual_Studio/Tango.Git/Properties/AssemblyInfo.cs b/Software/Visual_Studio/Tango.Git/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..4e07415b3 --- /dev/null +++ b/Software/Visual_Studio/Tango.Git/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Tango.Git")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Tango.Git")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("99081c0e-065c-4d68-bf60-f82330cca02d")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Software/Visual_Studio/Tango.Git/Tango.Git.csproj b/Software/Visual_Studio/Tango.Git/Tango.Git.csproj new file mode 100644 index 000000000..8bbf79eea --- /dev/null +++ b/Software/Visual_Studio/Tango.Git/Tango.Git.csproj @@ -0,0 +1,72 @@ + + + + + + Debug + AnyCPU + {99081C0E-065C-4D68-BF60-F82330CCA02D} + Library + Properties + Tango.Git + Tango.Git + v4.6.1 + 512 + true + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\LibGit2Sharp.0.26.2\lib\net46\LibGit2Sharp.dll + + + + + + + + + + + + + + + + + + + + + + + {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} + Tango.Core + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Git/packages.config b/Software/Visual_Studio/Tango.Git/packages.config new file mode 100644 index 000000000..576f27245 --- /dev/null +++ b/Software/Visual_Studio/Tango.Git/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file -- cgit v1.3.1