如何使用Azure Devops管道中的git服务连接来访问Github API

问题描述 投票:0回答:1

我有一个 github 服务连接,该连接具有我的企业 git 服务器的权限。然而,我的脚本除了克隆存储库之外,还使用 github API 对 github 更多 gitrepos 进行了一些分析。

我想使用服务连接对 API 进行身份验证,而不是定义一个新的令牌(有效),这样我就可以使用它从 API 获取存储库,例如我正在获取以给定前缀开头的所有存储库并报告一些统计数据

azure azure-devops
1个回答
0
投票

您可以在组织中安装第三方扩展 Github AzureDevOps Rest Api Integration,然后使用 GitHub 服务连接进行身份验证。

例如调用GitHub API创建PR:

- task: azuredevopsgithub@0
  inputs:
    gitHubConnection: '{The GitHub service connection you created}'
    method: 'POST'
    body: |
      {
        "title": "Merging changes from branch1 to main",
        "head": "refs/heads/branch1",
        "base": "refs/heads/main",
        "body": "Test creating PR in Azure pipeline"
      }
    githubrestapiurl: 'https://api.github.com/repos/{GitHubOwner}/{Repo}/pulls'
© www.soinside.com 2019 - 2024. All rights reserved.