使用LibGit2Sharp库,我试图在repo的主分支上列出所有pull请求的作者。我没有在docs,intellisense或通过搜索中看到任何有此例子的内容。任何指针?
我已经构建了下面的代码,但是我收到以下错误消息An unhandled exception of type 'LibGit2Sharp.RepositoryNotFoundException' occurred in LibGit2Sharp.dll
。浏览时,我发现的引用似乎是本地克隆的repos而不是远程存储库。
static void Main(string[] args)
{
var co = new CloneOptions();
co.CredentialsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials
{
Username = "username",
Password = "password"
};
var clonedRepoPath = Repository.Clone(url, "path/to/clone", co);
using (var repo = new Repository(clonedRepoPath))
{
foreach (Commit commit in repo.Commits)
{
Console.WriteLine(commit.Author.Name);
}
Console.WriteLine("Press any key to continue...");
Console.ReadLine();
}
}
}
}
答案 0 :(得分:1)
...列出所有拉动请求......
首先,“pull requests”是DVCS工作流方法,并非git
的功能。大多数人本身,并且错误地认为它是git
的一部分。 Github.com(和其他人)有一个pull request
工作流系统,其中包括git merge
,主题讨论,持续集成(CI)挂钩,问题引用,用户权限等项目。仅限于git merge
实际上来自git
DVCS。
也就是说,在git存储库中,Github样式的pull请求是两个commit-ishs之间的合并(通常从主题分支合并到主分支,但这不是必需的)和因此& #39;拉请求'承诺有两个父母。
仅供参考:对于有三(+)个父母的合并,请参阅此answer
回到你的问题:
列出回购的主分支上所有拉取请求的作者
该声明成为以下git
cmd:
git log master --merges --pretty=format:"%an %s"
变为:
将其翻译为libgit2sharp
:
// find the master branch in the repo
var masterBranch = repo.Branches.Single (branch => branch.FriendlyName == "master");
// Filter the branch's commits to ones that are merges
var mergeList = masterBranch.Commits.Where (p => p.Parents.Count () >= 2);
// Display the merge commits (pull requests)
foreach (Commit commit in mergeList)
{
Console.WriteLine("{0}\t{1}", commit.Author.Name, commit.MessageShort);
}
使用拉取请求的github仓库的输出示例:
João Matos Merge pull request #1966 from angeloc/master
Zoltan Varga Merge pull request #1965 from akoeplinger/fix-flaky-test
João Matos Merge pull request #1963 from angeloc/patch-1
Rodrigo Kumpera Merge pull request #1912 from ludovic-henry/threadpool-managed-asyncresult
Zoltan Varga Merge pull request #1959 from alexrp/master
Zoltan Varga Merge pull request #1958 from rolfbjarne/aot-error-reporting
Marek Safar Merge pull request #1955 from LogosBible/servicepoint_nre
...
<强>更新强>
根据评论,libgit2sharp
不会向用户提供他们想要的内容,您需要使用Github api。
通过Octokit库使用Github Api(您可以直接进行Github REST调用或使用其他库。),您可以非常轻松地请求所有打开拉取请求:
public static async Task getPullRequests ()
{
var client = new GitHubClient (new ProductHeaderValue ("PlayScript"));
// Login Credentials if you need them for an enterprise acct/repo
// client.Credentials = GithubHelper.Credentials;
var connection = new Connection (new ProductHeaderValue ("PlayScript"));
var api = new ApiConnection (connection);
var pullrequests = new PullRequestsClient (api);
pulls = await pullrequests.GetAllForRepository ("PlayScriptRedux", "playscript");
}
....
Task.WaitAll(getPullRequests());
foreach (var pullrequest in pulls) {
Console.WriteLine (pullrequest.IssueUrl);
}
那将在PlayScriptRedux组织下列出我的playcript repo的一个开放拉取请求,即控制台输出:
https://api.github.com/repos/PlayScriptRedux/playscript/issues/89
查看Octokit pull request test fixture了解更多信息
同时查看Github pull requests api信息