【问题标题】:How to access azure Dev Ops data such as Changeset between dates using python?如何使用 python 在日期之间访问 azure Dev Ops 数据,例如 Changeset?
【发布时间】:2020-03-10 09:37:27
【问题描述】:

我正在尝试连接到 AZURE Dev-Ops 并获取变更集信息,以使用 PYTHON 自动准备发行说明。

阅读github链接中提供的文档和流程后,我使用了以下内容:

from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
import pprint

# Fill in with your personal access token and org URL
personal_access_token = 'mypattokenvalue'
organization_url = 'https://dev.azure.com/myorg'

# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)
tfsv_client = connection.clients.get_tfvc_client()
project_name="myprojname"
search_criteria=".item_path='$/myprojname/Trunk/Main',.fromDate:'01-01-2019',.toDate:'11-13-2019-2:00PM'"

changeset_info = tfvcclient.get_changesets(project=project_name,search_criteria=search_criteria)

在执行代码时抛出错误:

'str' object has no attribute 'item_path' in following line of code of the package eventhoughi provided Item_path value:

   255         if search_criteria is not None:
--> 256             if search_criteria.item_path is not None:
    257                 query_parameters['searchCriteria.itemPath'] = search_criteria.item_path

我试图以字典的形式给出搜索条件,这也给出了同样的错误。如果根本不提供项目路径,则会引发相同的错误。

因此我不确定如何将数据提供给 get_changesets 方法的搜索条件参数。

我请求任何人提供有关如何提供数据的帮助,以便我可以使用 PYTHON 从 AZURE Dev Ops 的给定项目的主分支下使用日期范围查询变更集的信息?

在 2019 年 11 月 15 日的现有更新后添加额外查询:

这是包中的缺陷/错误,因为它没有采用我尝试提供的值,还是我提供搜索条件的方式错误? 如果这是一个合法的问题,你能告诉我我在哪里可以记录一个缺陷吗? 如果提供的值或我提供值的方式是错误的,您能告诉我/解释一下正确的方式吗?

提前致谢

问候

柴塔扬

【问题讨论】:

  • 根据您的错误信息,它不是包中的缺陷/错误。您的search_criteria 变量类型不支持search_criteria.item_path 这种获取值的方式。我认为您应该更改search_criteria 类型,以确保您可以成功获得item_path,fromDate,toDate

标签: python azure azure-devops azure-devops-rest-api


【解决方案1】:

由于错误表明str' object has no attribute 'item_path'。您定义的变量 search_criteriastr 类型。您无法获取 str search_criteria 不存在的属性 item_path

您应该定义一个 search_criteria 的对象类型例如请检查下面的代码。

  search_criteria = type('',(object,),{"item_path":'$/myprojname/Trunk/Main',"fromDate":'01-01-2019', "toDate":'11-13-2019-2:00PM'})

【讨论】:

  • 正如我在上面试图解释的,如果我在表单字典中创建搜索条件,我也会得到相同类型的错误说明:“dict”对象没有属性“item_path”并且在同一行代码中。事实上,我试图通过提供您定义的搜索条件来按原样执行代码,方法是用实际项目名称替换项目名称,但我得到了同样的错误。您能否再次提供输入?提前感谢您的帮助和时间。
  • 我更新了上面的答案,将搜索条件定义为一个对象。现在 item_path 可以被search_criteria.item_path引用。
  • 感谢 Levi 的快速解决方案和时间。它在我的最后工作。但是您能否让我知道您是如何得出结论的,或者您如何推断搜索条件应该作为对象类型传递?我只是想知道这些信息以提高我的知识,以便在需要时我也可以在其他领域使用这种方法。
  • 从你贴的错误中我们可以知道代码把item_path当作search_criteria的属性。如果我们将搜索条件定义为 str 或 dict。那么 item_path 不是它的属性。我还检查了source code,以确保应该将搜索条件定义为具有 item_path 属性的对象
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-12-19
  • 2016-11-12
  • 1970-01-01
  • 2019-07-31
  • 1970-01-01
  • 1970-01-01
  • 2019-11-25
相关资源
最近更新 更多