简体   繁体   English

如何使用 Python 从 TFS REST API 获取信息?

[英]How to fetch info from TFS REST API using Python?

I've manage to fetch Project names with:我设法通过以下方式获取项目名称:

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

Luckily the sample at https://github.com/Microsoft/azure-devops-python-api provided almost everything for that.幸运的是, https://github.com/Microsoft/azure-devops-python-api 上的示例几乎提供了一切。

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

Now I need to fetch info about our Test Plans.现在我需要获取有关我们的测试计划的信息。 I've searched through the docs and looked at samles at their Github, but I can't figure it out.我搜索了文档并查看了他们 Github 上的示例,但我无法弄清楚。 Can anyone point me in the right direction?任何人都可以指出我正确的方向吗?

Thanks!谢谢!

I haven't used this library, but looking at the example and taking a quick glance at the source it seems as though you would need to use the connection.clients.get_test_client() and then use the methods on that TestClient class.我没有使用过这个库,但是查看示例并快速浏览一下源代码,似乎您需要使用connection.clients.get_test_client()然后使用该TestClient类上的方法。

But be sure to target the correct classes for the correct API version you're trying to access.但一定要针对您尝试访问的正确 API 版本定位正确的类。 I see there are 3 different namespaces: released , v5_0 , v5_1 .我看到有 3 个不同的命名空间: releasedv5_0v5_1 There are ClientFactory classes in each of them.它们中的每一个都有ClientFactory类。

Other than this, I think you can use just about any generic http library to make the REST requests as long as you're providing the PAT in the Authentication header.除此之外,我认为您几乎可以使用任何通用 http 库来发出 REST 请求,只要您在 Authentication 标头中提供 PAT。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM