【问题标题】:How to fetch info from TFS REST API using Python?如何使用 Python 从 TFS REST API 获取信息?
【发布时间】:2019-07-19 15:51:51
【问题描述】:

我已经设法通过以下方式获取项目名称:

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

def get_project_names(token):
   # Fill in with your personal access token and org URL
   personal_access_token = token
   organization_url = '<url>'

   # Create a connection to the org
   credentials = BasicAuthentication('', personal_access_token)
   connection = Connection(base_url=organization_url, creds=credentials)

   # Get a client (the "core" client provides access to projects, teams, etc)
   core_client = connection.clients.get_core_client()

   # Get the list of projects in the org
   projects = core_client.get_projects()

   # Get Project names
   names = []

   for project in projects:
      projects_names = project.__dict__["name"]
      names.append(projects)

   return names

幸运的是,https://github.com/Microsoft/azure-devops-python-api 的示例几乎为此提供了一切。

他们的文档非常好:https://docs.microsoft.com/en-us/rest/api/azure/devops/testplan/test%20%20plans/get?view=azure-devops-rest-5.1

现在我需要获取有关我们的测试计划的信息。我已经搜索了文档并在他们的 Github 上查看了示例,但我无法弄清楚。谁能指出我正确的方向?

谢谢!

【问题讨论】:

  • 您是否收到任何特定的错误消息?你试过什么?

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


【解决方案1】:

我没有使用过这个库,但是查看示例并快速浏览一下源代码,您似乎需要使用connection.clients.get_test_client(),然后使用TestClient 类上的方法。

但请确保针对您尝试访问的正确 API 版本定位正确的类。我看到有 3 个不同的命名空间:releasedv5_0v5_1。每个都有ClientFactory 类。

除此之外,我认为您几乎可以使用任何通用 http 库来发出 REST 请求,只要您在 Authentication 标头中提供 PAT。

【讨论】:

  • 谢谢乔希。看起来我需要对他们的代码进行很多逆向工程,如果我能够从一个简单的脚本中做到这一点。对装饰器不太熟悉。我试图将所有依赖的东西放在一个文件中。你能看看这个吗? pastebin.com/bZAH4unf
  • 我的 python 技能不是很老练,但如果你使用的客户端库对于你正在谈论的逆向工程来说太多了,你可以使用@987654323 @ 和 editor.swagger.io 修剪客户端以仅包含您想要的内容。生成的 Readme.md 文件对我很有帮助。这篇文章不错getting started
猜你喜欢
  • 1970-01-01
  • 2013-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-12
  • 2020-09-22
  • 2015-10-11
相关资源
最近更新 更多