【问题标题】:Does LibGit2Sharp support atlassian stash repositories to work withLibGit2Sharp 是否支持使用 atlassian 存储库
【发布时间】:2019-04-29 00:19:57
【问题描述】:

我有一个 GIT 存储库说“https://github.com/Myname_XXXX/TestGit”。我需要遍历这个存储库的所有提交并获取某些信息,例如提交作者、id、消息等。我使用下面的代码 sn-p 并且它工作正常。

        string repoPath = "https://github.com/Myname_XXXX/TestGit";
        GitRepositoryManager objTest = new GitRepositoryManager("Userid", "Pwd", repoPath, @"C:\ClonedFolder");

        string path = Repository.Clone(objTest._repoSource, objTest._localFolder.ToString());
        using (var repo = new Repository(path))
        {
            int i = 1;
            foreach (var Commit in repo.Commits)
            {
                Console.WriteLine("");
                Console.WriteLine("Number : {0}", i);
                Console.WriteLine("Author: {0}", Commit.Author.Name);
                Console.WriteLine("Message: {0}", Commit.MessageShort);
                Console.WriteLine("Commit Id: {0}", Commit.Id.ToString());
                Console.WriteLine("Commit Date: {0}", Commit.Author.When.DateTime);
                Console.WriteLine("Author Email: {0}", Commit.Committer.ToString());
                i = i + 1;

            }
            Console.WriteLine("Total Commits: {0}", i - 1);
            Console.ReadLine();

        }

    }

}

class GitRepositoryManager
{
    public readonly string _repoSource;
    public readonly UsernamePasswordCredentials _credentials;
    public readonly DirectoryInfo _localFolder;

    public GitRepositoryManager(string username, string password, string gitRepoUrl, string localFolder)
    {
        var folder = new DirectoryInfo(localFolder);

        if (!folder.Exists)
        {
            throw new Exception(string.Format("Source folder '{0}' does not exist.", _localFolder));
        }

        _localFolder = folder;

        _credentials = new UsernamePasswordCredentials
        {
            Username = username,
            Password = password
        };

        _repoSource = gitRepoUrl;
    }
}

我的第一个问题是:

  1. 有没有一种简单的方法可以通过提供 GIT 登录凭据(没有克隆-->使用 Repository.Clone())连接到 GIT 存储库:正如我所使用的 在上面的代码(sn-p)中,并在不克隆的情况下遍历存储库的所有提交,因为当我们拥有庞大的代码库时会产生问题

  2. 相同的概念是否适用于 Atlassian 存储(因为它也基于 GIT 概念)

【问题讨论】:

    标签: git atlassian-sourcetree libgit2sharp


    【解决方案1】:

    (没有克隆-->使用 Repository.Clone())

    那么您需要使用GitHub API,并使用类似“Get github commits on all branches from API ”的方法

    for line in `curl "https://api.github.com/repos/:user/:repo/branches" | \
      grep -o '"name":.*,' | \
      sed 's/"name": "//g' | \
      sed 's/",//g'`; \
      do; \
        curl "https://api.github.com/repos/:user/:repo/commits?sha=$line" >> result.json ; \
      done;
    

    【讨论】:

      猜你喜欢
      • 2012-08-20
      • 1970-01-01
      • 2014-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多