到目前为止,我已经能够在C#中配置一个方法,该方法能够在Azure DevOps中对新存储库进行硬编码,但是我的真正目标是创建一个用户界面,允许用户指定包含以下内容的请求正文:以下:
name:“ nameOfRepository”, 项目:{ id:'projectId' }
用户将使用新存储库的所需名称填写第一个输入字段。第二个输入字段应使用GET请求,该请求会在下拉列表中显示组织中所有可用的项目。 我也在使用.NET Core 3.0,并且相信这可能也必须使用API控制器来完成,但是我不确定。
我几乎没有使用React的经验,也不知道我将如何以及在何处指定请求主体和个人访问令牌来创建存储库。我希望能对它的工作方式进行解释,也希望能有一个可以指导我朝正确方向发展的解决方案。
答案 0 :(得分:0)
Azure DevOps Rest API文档将使您可以访问平台。如果您决定完全使用React js开发。我想建议您使用入门套件,其中大部分内容将涵盖您对React的所有基本设置。
按照以下步骤了解如何使用react js实现
需要在天蓝色的Deops中设置OAuth。下面的链接将给出一个想法。在回调页面中,您需要存储访问令牌存储
https://docs.microsoft.com/en-us/azure/devops/integrate/get-started/authentication/oauth?view=azure-devops。如果您有个人身份验证令牌,则不需要
使用fetch或Axios API获取所有存储库列表 Axios示例:
const headers = {
'Content-Type': 'application/json',
'Authorization': 'bearer token' or 'basic personalaccesstoken'
}
axios.get('https://dev.azure.com/{organization}/{project}/_apis/git/repositories', {
headers: headers,
params: {
'api-version':'5.1'
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
Axios示例
const headers = {
'Content-Type': 'application/json',
'Authorization': 'bearer token'
}
const data = {
name: ''
parentRepository: {id: '', ....}
project: {id: '', ...}
}
axios.post('https://dev.azure.com/{organization}/{project}/_apis/git/repositories', JSON.stringify(data),
{
headers: headers,
params: {
'api-version':'5.1'
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
类似地,您可以访问Microsoft提及的所有API REST API文档。 link