Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for pending merge refs #208

Merged
merged 26 commits into from
Mar 17, 2023
Merged

Conversation

ofalvai
Copy link
Contributor

@ofalvai ofalvai commented Feb 24, 2023

Checklist

  • I've read and followed the Contribution Guidelines
  • step.yml and README.md is updated with the changes (if needed)

Version

Requires a MAJOR/MINOR/PATCH version update

Context

Related webhook processor PR: bitrise-io/bitrise-webhooks#128

This PR adds support for handling pending merge refs, which need to be verified before using for the checkout.

Changes

  • Add a new "internal" input: pull_request_unverified_merge_branch. This is automatically filled by the environment just like pull_request_merge_branch.
  • Create MergeRefChecker that polls the Bitrise API a few times, which in turn asks/triggers the git provider to refresh the merge ref. If the merge ref is up-to-date, we use it for checkouts just like before. If the checker times out, or there is an error, we use the usual fallback checkout methods (most of the time it's fetching the PR source and destination branch and doing the merge manually)
  • Create a new bitriseapi package for Bitrise API specific stuff, such as this new merge ref checker and the PR patch file downloader.
  • Log a new event with the result of the merge ref checking

Investigation details

Decisions

@@ -67,24 +62,3 @@ func (c checkoutPRDiffFile) do(gitCmd git.Git, fetchOptions fetchOptions, fallba
func (c checkoutPRDiffFile) getBuildTriggerRef() string {
return ""
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to bitriseapi package

@@ -374,6 +374,7 @@ workflows:
envman add --key TEST_DIFF_REPO_URL --value ${GIT_DIR}
envman add --key TEST_DIFF_PR_REPOSITORY_URL --value ${PR_GIT_DIR}
envman add --key BITRISE_BUILD_URL --value "file://${DIFF_DIR}"
envman add --key BITRISE_BUILD_API_TOKEN --value "dummy token"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BITRISE_BUILD_URL and BITRISE_BUILD_API_TOKEN should both be defined or none of them

@@ -1,4 +1,4 @@
package gitclone
package tracker
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to move this to its own subpackage because I introduced an import cycle (by using the tracker not only in gitclone, but in gitclone/bitriseapi too)

PRHeadBranch string

ResetRepository bool
BuildURL string
BuildAPIToken string
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are no longer needed here in the Config struct because we have instances of bitriseapi.PatchSource and bitriseapi.MergeRefChecker that contain these params.

Copy link
Contributor

@godrei godrei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it so far

gitclone/bitriseapi/pr_merge_ref.go Show resolved Hide resolved
gitclone/bitriseapi/pr_merge_ref.go Outdated Show resolved Hide resolved
@ofalvai ofalvai marked this pull request as ready for review March 7, 2023 15:37
gitclone/bitriseapi/pr_merge_ref.go Show resolved Hide resolved
gitclone/bitriseapi/pr_merge_ref.go Show resolved Hide resolved
}

func (s apiPatchSource) GetPRPatch() (string, error) {
if s.buildURL == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above shouldn't we do the validation in the constructor?

@ofalvai ofalvai merged commit d03a3a0 into master Mar 17, 2023
@ofalvai ofalvai deleted the ACI-386-pending-merge-ref branch March 17, 2023 09:30
@ofalvai ofalvai restored the ACI-386-pending-merge-ref branch March 17, 2023 09:30
@lpusok lpusok deleted the ACI-386-pending-merge-ref branch August 10, 2023 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants