我尝试创建一个Azure DevOps扩展,以获取当前的请求请求。但我面临未经授权的例外:
我检查了请求中发送的令牌,这与我得到的相同:
VSS.getAccessToken().then(function(token) {
var authHeader = VSS_Auth_Service.authTokenManager.getAuthorizationHeader(token);
console.log(authHeader);
});
git客户端是这样实例化的:
VSS.require(["VSS/Service", "TFS/VersionControl/GitRestClient"], function (VSS_Service, TFS_Wit_WebApi) {
// Get the REST client
var gitClient = VSS_Service.getCollectionClient(TFS_Wit_WebApi.GitHttpClient2_2);
gitClient.getPullRequest(tabContext.repositoryId, tabContext.pullRequestId)
.thenResolve(pr => {
console.log(pr);
});
});
我也这样尝试过:
VSS.require(["VSS/Service", "TFS/VersionControl/GitRestClient"], function (VSS_Service, TFS_Wit_WebApi) {
// Get the REST client
var gitClient = TFS_Wit_WebApi.getClient();
gitClient.getPullRequest(tabContext.repositoryId, tabContext.pullRequestId)
.thenResolve(pr => {
console.log(pr);
});
});
扩展清单是:
{
"manifestVersion": 1,
"id": "complete-pr-extension",
"publisher": "aguafrommars",
"version": "1.0.8",
"name": "Complete Pull Request",
"description": "Complete a Pull Request with commity zen",
"public": false,
"categories": ["Code"],
"targets": [
{
"id": "Microsoft.VisualStudio.Services"
}
],
"contributions": [
{
"id": "pull-request-details-tab",
"type": "ms.vss-web.tab",
"targets": [
"ms.vss-code-web.pr-tabs"
],
"properties": {
"name": "Complete Pull Request",
"title": "Complete Pull Request",
"uri": "complete-pr.html",
"action": "PR Details Tab"
}
}
],
"files": [
{
"path": "complete-pr.html",
"addressable": true
},
{
"path": "node_modules/vss-web-extension-sdk/lib",
"addressable": true,
"packagePath": "lib"
}
]
}
然后使用以下命令将扩展安装到本地TFS 2018 Update 2:
tfx extension publish --service-url http://localhost:8080/tfs --token {my-token} --rev-version
答案 0 :(得分:1)