コード例 #1
0
ファイル: GitFacade.cs プロジェクト: vladimirdemoshin/GitHelp
        public Repository GetRepository(GitParameters gitParameters)
        {
            using (var libGitRepository = new LibGit2Sharp.Repository(gitParameters.RepositoryPath))
            {
                var localBranches = new List <Branch>();
                foreach (var branch in libGitRepository.Branches)
                {
                    var commits = new List <Commit>();
                    foreach (var commit in branch.Commits)
                    {
                        var commitModel = new Commit
                        {
                            Sha       = commit.Sha,
                            Message   = commit.Message,
                            Author    = _mapSignature(commit.Author),
                            Committer = _mapSignature(commit.Committer)
                        };
                        commits.Add(commitModel);
                    }

                    var branchModel = new Branch
                    {
                        Name     = branch.FriendlyName,
                        Commits  = commits,
                        IsRemote = branch.IsRemote
                    };
                    localBranches.Add(branchModel);
                }

                var repository = new Repository(localBranches);

                return(repository);
            }
        }
コード例 #2
0
        private Uri BuildUri(GitParameters parameters)
        {
            var builder = new UriBuilder();

            builder.Scheme = parameters.Protocol;
            builder.Host   = parameters.Host;
            builder.Path   = parameters.Path;
            return(builder.Uri);
        }
コード例 #3
0
        private string GetRegion(GitParameters parameters)
        {
            var match = RegionRegex.Match(parameters.Host);

            if (match.Success)
            {
                return(match.Groups[3].Value);
            }
            // TODO: Fall back to region global config; can we get this from the SDK?
            return(null);
        }
コード例 #4
0
        public void GitParameters_FromDictionary_throws_on_missing_entry([ValueSourceAttribute("DictionaryKeys")] string missingEntryKey)
        {
            var dictionary = new Dictionary <string, string>
            {
                ["protocol"] = "protocol",
                ["host"]     = "host",
                ["path"]     = "path"
            };

            dictionary.Remove(missingEntryKey);

            Action call = () => GitParameters.FromDictionary(dictionary);

            call.Should().Throw <ArgumentException>();
        }
コード例 #5
0
        public void GitParameters_FromDictionary_initializes_with_data_from_dictionary()
        {
            var dictionary = new Dictionary <string, string>
            {
                ["protocol"] = "ssh",
                ["host"]     = "some-host",
                ["path"]     = "/repo/path"
            };

            var parameters = GitParameters.FromDictionary(dictionary);

            parameters.Protocol.Should().Be(dictionary["protocol"]);
            parameters.Host.Should().Be(dictionary["host"]);
            parameters.Path.Should().Be(dictionary["path"]);
        }
コード例 #6
0
        private static GitParameters ReadParameters()
        {
            var parsed = new Dictionary <string, string>();

            string line;

            while ((line = Console.ReadLine()) != null)
            {
                var tokens = line.Split('=', 2);
                if (tokens.Length != 2)
                {
                    throw new ArgumentException($"Expected input in the form of {{key}}={{value}}, but got: {line}");
                }
                parsed[tokens[0]] = tokens[1];
            }

            return(GitParameters.FromDictionary(parsed));
        }
コード例 #7
0
        public (string username, string password) GenerateCredentials(GitParameters parameters)
        {
            var uri    = BuildUri(parameters);
            var region = GetRegion(parameters);

            var awsCredentials = _awsCredentialProvider.GetCredentials();

            var signature = CalculateSignature(region, uri, awsCredentials.SecretKey);

            var usernameBuilder = new StringBuilder(awsCredentials.AccessKey);

            if (!String.IsNullOrEmpty(awsCredentials.SessionToken))
            {
                usernameBuilder.Append('%').Append(awsCredentials.SessionToken);
            }

            return(usernameBuilder.ToString(), signature);
        }