【问题标题】:azure-devops export work items as csv and include ALL comments/discussionsazure-devops 将工作项导出为 csv 并包含所有评论/讨论
【发布时间】:2022-09-27 15:36:53
【问题描述】:

如果我在 Azure Devops 中查询我的工作项,当我添加要显示的列时,只有 comments countdiscussions,但是有没有什么地方可以在我的输出保存的 csv 文件中包含来自工作项的所有 cmets ?我需要为 csv 中的每个工作项归档 cmets。

我可以通过 azure desktop web ui 以某种方式做到这一点吗?还是我需要使用 azure api 编写自己的脚本来查看 cmets 并将它们添加到工作项

    标签: csv azure-devops export comments


    【解决方案1】:

    我可以通过 azure 桌面 web ui 以某种方式做到这一点吗?还是我需要 使用 azure api 编写我自己的脚本来查看 cmets 并添加 他们到一个工作项

    对于你的第一个问题,答案是.由于您想要一个工作项的所有 cmets,那么内置的 UI 功能将无法满足您的要求。

    对于你的第二个问题,答案是是的.

    from azure.devops.connection import Connection
    from msrest.authentication import BasicAuthentication
    import requests
    import csv
    import os
    #get all the comments of a work item
    def get_work_items_comments(wi_id):
        #get a connection to Azure DevOps
        organization_url = 'https://dev.azure.com/xxx'
        personal_access_token = 'xxx'
        credentials = BasicAuthentication('', personal_access_token)
        connection = Connection(base_url=organization_url, creds=credentials)
        work_item_tracking_client = connection.clients.get_work_item_tracking_client()
        #get the work item
        work_item = work_item_tracking_client.get_work_item(wi_id)
        #get the comments of the work item
        comments_ref = work_item._links.additional_properties['workItemComments']['href']
        #send a request to get the comments
        response = requests.get(comments_ref, auth=('', personal_access_token))
        #get the comments
        comments = response.json()['comments']
        return comments
    
    #return work item id, work item title and related work item comments
    def get_work_items_results(wi_id):
        #get a connection to Azure DevOps
        organization_url = 'https://dev.azure.com/xxx'
        personal_access_token = 'xxx'
        credentials = BasicAuthentication('', personal_access_token)
        connection = Connection(base_url=organization_url, creds=credentials)
        work_item_tracking_client = connection.clients.get_work_item_tracking_client()
        #get the work item
        work_item = work_item_tracking_client.get_work_item(wi_id)
        #get the title of the work item
        title = work_item.fields['System.Title']
        #get the work item id
        id = work_item.id
        #get the comments of the work item
        items = get_work_items_comments(wi_id)
        array_string = []
        for item in items:
            text = item['text']
            array_string.append(text)
            print(item['text'])
        return id, title, array_string
    
    #Save the work item id, work item title and related work item comments to a csv file
    
    #create folder workitemresults if not exist
    if not os.path.exists('workitemresults'):
        os.makedirs('workitemresults')
    
    with open('workitemresults/comments_results.csv', 'w', newline='') as csvfile:
        writer = csv.writer(csvfile)
        writer.writerow(['Workitem ID','Workitem Title','Workitem Comments'])
    
        #===if you want multiple work items, just for loop in this place and replace the value 120 in this place, 120 is the workitem id on my side.=== 
    
        writer.writerow(get_work_items_results(120))
    

    它在我这边工作得很好(我在我的代码中提到的'for循环'的地方):

    【讨论】:

      猜你喜欢
      • 2019-12-17
      • 1970-01-01
      • 1970-01-01
      • 2020-03-21
      • 2023-03-05
      • 1970-01-01
      • 2022-01-19
      • 2020-07-31
      • 2018-12-23
      相关资源
      最近更新 更多