如何使用 TFS 客户端库为 PullRequest 获取 Web URL?
How to get a web URL for a PullRequest using TFS client libraries?
有没有办法使用 TFS client libraries?
var prId = 12345;
var tpc = new TfsTeamProjectCollection(new Uri(""));
var git = tpc.GetClient<GitHttpClient>();
// GitHttpClient has no special methods to do it
// and GitPullRequest obtained through GitHttpClient.GetPullRequestByIdAsync contains only the API link
var prWebUrl = git.?????(prId);
也许我错过了类似于 TswaClientHyperlinkService 的内容?
或者我是否必须求助于从 API link/GitPullRequest
属性中推导网络 URL?
无法直接从客户端库中获取 RemoteUrl
,因为值为 null
。查看下面的屏幕截图:
但是您可以获得存储库 (https://tfshost/tfs/Collection/Project/_git/Repository
) 的 RemoteUrl
,因此您可以使用以下代码获取 PR RemoteUrl:
using Microsoft.TeamFoundation.SourceControl.WebApi;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi;
using System;
namespace GetPullRequest
{
class Program
{
static void Main(string[] args)
{
String collectionUri = "https://xxx.visualstudio.com";
VssBasicCredential creds = new VssBasicCredential("", "6ztnrtjdd3i42juchu4xxxxxxxxxaslnseo277tgiuiq");
VssConnection connection = new VssConnection(new Uri(collectionUri), creds);
var git = connection.GetClient<GitHttpClient>();
var prId = 12345;
var pr = git.GetPullRequestByIdAsync(prId).Result;
var RepoUrl = pr.Repository.RemoteUrl;
var prUrl = RepoUrl + "/pullrequest/" + prId;
Console.WriteLine(prUrl);
}
}
}
有没有办法使用 TFS client libraries?
var prId = 12345;
var tpc = new TfsTeamProjectCollection(new Uri(""));
var git = tpc.GetClient<GitHttpClient>();
// GitHttpClient has no special methods to do it
// and GitPullRequest obtained through GitHttpClient.GetPullRequestByIdAsync contains only the API link
var prWebUrl = git.?????(prId);
也许我错过了类似于 TswaClientHyperlinkService 的内容?
或者我是否必须求助于从 API link/GitPullRequest
属性中推导网络 URL?
无法直接从客户端库中获取 RemoteUrl
,因为值为 null
。查看下面的屏幕截图:
但是您可以获得存储库 (https://tfshost/tfs/Collection/Project/_git/Repository
) 的 RemoteUrl
,因此您可以使用以下代码获取 PR RemoteUrl:
using Microsoft.TeamFoundation.SourceControl.WebApi;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi;
using System;
namespace GetPullRequest
{
class Program
{
static void Main(string[] args)
{
String collectionUri = "https://xxx.visualstudio.com";
VssBasicCredential creds = new VssBasicCredential("", "6ztnrtjdd3i42juchu4xxxxxxxxxaslnseo277tgiuiq");
VssConnection connection = new VssConnection(new Uri(collectionUri), creds);
var git = connection.GetClient<GitHttpClient>();
var prId = 12345;
var pr = git.GetPullRequestByIdAsync(prId).Result;
var RepoUrl = pr.Repository.RemoteUrl;
var prUrl = RepoUrl + "/pullrequest/" + prId;
Console.WriteLine(prUrl);
}
}
}