LibGit2Sharp是否支持atlassian存储库使用

问题描述 投票:1回答:1

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

        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存储库的简单方法:正如我在上面的代码片段中所使用的那样,并且遍历存储库的所有提交没有克隆,因为当我们有庞大的代码库时会产生问题
  2. 相同的概念是否适用于Atlassian藏匿(因为它也基于GIT概念)
git atlassian-sourcetree libgit2sharp
1个回答
0
投票

(没有克隆 - >使用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;
© www.soinside.com 2019 - 2024. All rights reserved.