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

[MER-3309] Add an extra merge commit detection based on commit messages #218

Merged
merged 2 commits into from
Jan 3, 2024

Conversation

draftcode
Copy link
Contributor

@draftcode draftcode commented Dec 20, 2023

When a PR gets closed by "Close #123", usually GitHub marks the PR to be
closed by certain commit. However, this mechanism is not reliable, and
sometimes GitHub doesn't mark it so and just close it. This breaks the
merge commit detection since av-cli doesn't have a way to know it from
GitHub API.

By using git-log, we can figure out whether there's actually a commit
that closes the PRs with this comment. This adds that extra detection
method.

In order to make this work, it moves the timing of git-fetch. This is
needed in order for a local repository to have commits in the upstream
to check the commit messages.

Copy link
Contributor

aviator-app bot commented Dec 20, 2023

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes.
Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

This PR was merged using Aviator.


See the real-time status of this PR on the Aviator webapp.

Use the Aviator Chrome Extension to see the status of your PR within GitHub.

@draftcode
Copy link
Contributor Author

Tested with a repository in this way.

  1. Create a commit with "Close #..." but specify the PR number that hasn't yet created. We can easily predict what's next.
  2. Push that to main.
  3. Create a new branch off of older commit than (1). Create a random change.
  4. av pr create on that new branch. This creates a new PR with the PR number specified in (1).
  5. Close the newly created PR.
  6. Run av stack sync --trunk. This fetches the main branch and it will see the "Closed #..." message, while the PR created in (4) is closed at (5). This makes av-cli believe that the PR was closed in the commit created in (1).

@twavv twavv self-requested a review January 3, 2024 21:04
internal/actions/sync_branch.go Outdated Show resolved Hide resolved
if _, err := repo.Git("fetch", "origin", parent.Name); err != nil {
return "", errors.WrapIff(err, "failed to fetch %q from origin", parent.Name)
}
commitHash, err := repo.RevParse(&git.RevParse{Rev: "FETCH_HEAD"})
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can you just make this remotes/origin/{parent.Name} instead of FETCH_HEAD? it's hypothetical but FETCH_HEAD could change out from underneath us in a race condition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Depending on the fetch spec, the name of the local remote tracking branch can be different, or it doesn't exist at all. While the race condition does exist, the chance it hits that condition is narrow. vs. this local remote tracking branch not existing can happen permanently (namely GitHub Actions' checkout doesn't have it). So, this is intentionally FETCH_HEAD.

internal/git/log.go Outdated Show resolved Hide resolved
@@ -61,6 +61,10 @@ func SyncBranch(
}
} else {
if opts.Fetch {
fetchHead, err := fetchUpstreamCommits(repo, tx, branch)
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: you can move this into the else if below since we're not using it except in that case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. This is actually used outside of that case.

Without this upstream fetch, the merge commit won't exist locally. This makes the rebase process in syncBranchRebase unable to rebase on top of the merged commit.

internal/actions/sync_branch.go Outdated Show resolved Hide resolved
internal/git/log.go Outdated Show resolved Hide resolved
internal/git/log.go Outdated Show resolved Hide resolved
internal/actions/sync_branch.go Outdated Show resolved Hide resolved
@draftcode draftcode force-pushed the git-log-merge-commit-detection branch from 4da24a5 to cf853ed Compare January 3, 2024 22:51
When a PR gets closed by "Close #123", usually GitHub marks the PR to be
closed by certain commit. However, this mechanism is not reliable, and
sometimes GitHub doesn't mark it so and just close it. This breaks the
merge commit detection since av-cli doesn't have a way to know it from
GitHub API.

By using git-log, we can figure out whether there's actually a commit
that closes the PRs with this comment. This adds that extra detection
method.

In order to make this work, it moves the timing of git-fetch. This is
needed in order for a local repository to have commits in the upstream
to check the commit messages.
@draftcode draftcode force-pushed the git-log-merge-commit-detection branch from cf853ed to 48e1f3e Compare January 3, 2024 23:03
@aviator-app aviator-app bot merged commit 0b947a3 into master Jan 3, 2024
3 checks passed
@aviator-app aviator-app bot deleted the git-log-merge-commit-detection branch January 3, 2024 23:05
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