我有一个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;
}
}
我的第一个问题是:
是否有一种简单的方法可以通过提供GIT登录凭据(不克隆->使用Repository.Clone())来连接到GIT存储库:就像我以前使用的那样 在上面的代码段中),并遍历了存储库中的所有提交而不进行克隆,因为当我们拥有巨大的代码库时,它会造成问题
是否适用于Atlassian隐藏的相同概念(因为它也基于GIT概念)
答案 0 :(得分: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;