Azure DevOps WebAPI

2024/10/14に公開

やりたいこと

WorkItemsの取得

- Wiql:

https://learn.microsoft.com/ja-jp/rest/api/azure/devops/wit/wiql/query-by-wiql?view=azure-devops-rest-7.0&tabs=HTTP

- Work Items:

https://learn.microsoft.com/ja-jp/rest/api/azure/devops/wit/work-items?view=azure-devops-rest-7.0

Pull Requestの取得

#公式サンプル
https://github.com/microsoft/azure-devops-python-api

#公式WebAPI
https://learn.microsoft.com/ja-jp/rest/api/azure/devops/wit/work-items?view=azure-devops-rest-7.0

WorkItemsの取得

Python

import requests
import base64
import config

authorization = str(base64.b64encode(bytes(':'+ config.personal_access_token, 'ascii')), 'ascii')

headers = {
    'Accept': 'application/json',
    'Authorization': 'Basic '+authorization
}
ids='200,201,202'
response = requests.get(
    url=f'https://dev.azure.com/{config.organization}/{config.project}/_apis/wit/workitems?ids={ids}&api-version=7.0&$expand=all', headers=headers)
print(response.text)
import requests
import base64
import config


contents = {
  "query": "Select [System.Id], [System.Title], [System.State] " \
            "From WorkItems " \
            "Where [System.WorkItemType] = 'Task' AND [State] <> 'Closed' AND [State] <> 'Removed' " \
            "order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc"
}

url=f'https://dev.azure.com/{config.organization}/{config.project}/_apis/wit/wiql?api-version=7.0&$top=9999'

authorization = str(base64.b64encode(bytes(':'+ config.personal_access_token, 'ascii')), 'ascii')

headers = {
    'Accept': 'application/json',
    'Authorization': 'Basic '+authorization
}
response = requests.post(url=url, headers=headers, json=contents)

print(response.text)

Discussion