我尝试创建一个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年更新2的扩展:
tfx extension publish --service-url http://localhost:8080/tfs --token {my-token} --rev-version发布于 2019-03-29 09:21:32
我发现我的问题在哪里,我错过了在我的清单中添加范围:
{
"manifestVersion": 1,
...
"scopes": [
"vso.code_full"
],
...
}您可以在扩展清单参考文档中找到所有可用的范围。
https://stackoverflow.com/questions/55413079
复制相似问题