从 Azure Pipelines 提交并推送到 GitHub 拉取请求分支
Commit and push to GitHub pull request branch from Azure Pipelines
我有一个 Azure Pipeline [source, runs] triggered by pull request. I am following this GitHub guide 提交到用于创建拉取请求的贡献者分支。
为了做到这一点,我禁用了默认管道 checkout
步骤:
steps:
- checkout: none
然后我尝试克隆贡献者的存储库并检查他们用于拉取请求的分支。
steps:
...
- script: |
git clone $(System.PullRequest.SourceRepositoryUri) .
git checkout $(System.PullRequest.SourceBranch)
displayName: checkout source branch
但是,System.PullRequest.SourceRepositoryUri
返回 my 存储库的 git URI,而不是贡献者的。
我的主要存储库:
https://github.com/collinbarrett/FilterLists.git
我尝试使用的变量(参见 here):
System.PullRequest.SourceRepositoryURI
:
https://github.com/collinbarrett/FilterLists.git
Build.Repository.Uri
: https://github.com/collinbarrett/FilterLists
我想我需要在构建管道中有一个预定义的变量,它可以给我以下之一:
https://github.com/<GitHubUsernameOfPrContributor>/FilterLists.git
<GitHubUsernameOfPrContributor>
如何克隆拉取请求贡献者的存储库并检查他们用于拉取请求的分支?答案可能是以下任一问题的解决方案:
- 是否还有另一个我遗漏的 predefined variable 包含贡献者的存储库 URI 或 GitHub 用户名?
- 我可以调整 Azure Pipelines
checkout
task to checkout the branch from the other contributor's repository instead of my own? In order to configure the fork as a Resource,看来我需要贡献者的 fork URI 或用户名。
- 我能以某种方式直接从 GitHub API 获取这个 URI 吗?
- 还有其他解决办法吗?看来我让这件事变得比应该的更难了......
更新:还有requested on Microsoft Developer Community。在那里赞成。
我可以通过从我的管道调用 GitHub API 来获得我需要的东西。来自 Azure Pipelines 的预定义变量将是首选,但现在可以使用。
- bash: |
FORKURI=$(curl -X GET "https://api.github.com/repos/$BUILD_REPOSITORY_NAME/pulls/$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER" | jq -r '.head.repo.clone_url')
git clone "$FORKURI" .
git checkout "$SYSTEM_PULLREQUEST_SOURCEBRANCH"
displayName: checkout source branch
我有一个 Azure Pipeline [source, runs] triggered by pull request. I am following this GitHub guide 提交到用于创建拉取请求的贡献者分支。
为了做到这一点,我禁用了默认管道 checkout
步骤:
steps:
- checkout: none
然后我尝试克隆贡献者的存储库并检查他们用于拉取请求的分支。
steps:
...
- script: |
git clone $(System.PullRequest.SourceRepositoryUri) .
git checkout $(System.PullRequest.SourceBranch)
displayName: checkout source branch
但是,System.PullRequest.SourceRepositoryUri
返回 my 存储库的 git URI,而不是贡献者的。
我的主要存储库:
https://github.com/collinbarrett/FilterLists.git
我尝试使用的变量(参见 here):
System.PullRequest.SourceRepositoryURI
:https://github.com/collinbarrett/FilterLists.git
Build.Repository.Uri
:https://github.com/collinbarrett/FilterLists
我想我需要在构建管道中有一个预定义的变量,它可以给我以下之一:
https://github.com/<GitHubUsernameOfPrContributor>/FilterLists.git
<GitHubUsernameOfPrContributor>
如何克隆拉取请求贡献者的存储库并检查他们用于拉取请求的分支?答案可能是以下任一问题的解决方案:
- 是否还有另一个我遗漏的 predefined variable 包含贡献者的存储库 URI 或 GitHub 用户名?
- 我可以调整 Azure Pipelines
checkout
task to checkout the branch from the other contributor's repository instead of my own? In order to configure the fork as a Resource,看来我需要贡献者的 fork URI 或用户名。 - 我能以某种方式直接从 GitHub API 获取这个 URI 吗?
- 还有其他解决办法吗?看来我让这件事变得比应该的更难了......
更新:还有requested on Microsoft Developer Community。在那里赞成。
我可以通过从我的管道调用 GitHub API 来获得我需要的东西。来自 Azure Pipelines 的预定义变量将是首选,但现在可以使用。
- bash: |
FORKURI=$(curl -X GET "https://api.github.com/repos/$BUILD_REPOSITORY_NAME/pulls/$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER" | jq -r '.head.repo.clone_url')
git clone "$FORKURI" .
git checkout "$SYSTEM_PULLREQUEST_SOURCEBRANCH"
displayName: checkout source branch