[英]Commit and push to GitHub pull request branch from Azure Pipelines
I have an Azure Pipeline [ source , runs ] triggered by pull request.我有一个 Azure Pipeline [ source , runs ] 由 pull request 触发。 I am following this GitHub guide to commit to the contributor's branch used to create the pull request.我正在按照这个 GitHub 指南提交到用于创建拉取请求的贡献者分支。
In order to do that, I have disabled the default Pipelines checkout
step:为此,我禁用了默认的 Pipelines checkout
步骤:
steps:
- checkout: none
I am then trying to clone the contributor's repository and checkout their branch used for the pull request.然后我试图克隆贡献者的存储库并检查他们用于拉取请求的分支。
steps:
...
- script: |
git clone $(System.PullRequest.SourceRepositoryUri) .
git checkout $(System.PullRequest.SourceBranch)
displayName: checkout source branch
However, System.PullRequest.SourceRepositoryUri
is returning the git URI of my repository, not the contributor's.但是, System.PullRequest.SourceRepositoryUri
返回我存储库的 git URI,而不是贡献者的。
My primary repository:我的主要存储库:
https://github.com/collinbarrett/FilterLists.git
Variables I have tried using (see here ):我尝试使用的变量(参见此处):
System.PullRequest.SourceRepositoryURI
: https://github.com/collinbarrett/FilterLists.git
System.PullRequest.SourceRepositoryURI
: https://github.com/collinbarrett/FilterLists.git
Build.Repository.Uri
: https://github.com/collinbarrett/FilterLists
Build.Repository.Uri
: https://github.com/collinbarrett/FilterLists
I think I need a predefined variable in a build Pipeline that can give me either of the following:我想我在构建管道中需要一个预定义的变量,它可以给我以下之一:
https://github.com/<GitHubUsernameOfPrContributor>/FilterLists.git
<GitHubUsernameOfPrContributor>
How can I clone the pull request contributor's repository and checkout their branch used for the pull request?我如何克隆拉取请求贡献者的存储库并检查他们用于拉取请求的分支? An answer may be a solution to any of the following:答案可能是以下任一问题的解决方案:
checkout
task to checkout the branch from the other contributor's repository instead of my own?我可以调整 Azure Pipelines checkout
任务以从其他贡献者的存储库而不是我自己的存储库检出分支吗? In order to configure the fork as a Resource , it seems like I would need the contributor's fork URI or username.为了将 fork 配置为Resource ,我似乎需要贡献者的 fork URI 或用户名。UPDATE : Also requested on Microsoft Developer Community .更新:也在Microsoft Developer Community 上请求。 Upvotes there appreciated.那里的支持表示赞赏。
I am able to get what I need by calling the GitHub API from my Pipeline.我可以通过从我的管道调用 GitHub API 来获得我需要的东西。 A predefined variable from Azure Pipelines would be preferred, but this will work for now.来自 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.