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

Updating a PR metadata before git-push is not possible in some cases #395

Open
draftcode opened this issue Aug 14, 2024 · 6 comments
Open

Comments

@draftcode
Copy link
Contributor

draftcode commented Aug 14, 2024

In #352, we switched to call GitHub API to update the PR metadata first, then doing a git-push. This is to make sure that a CI service sees the base branch data correctly.

However, if a branch order is swapped, the PR metadata cannot be updated. When a stack is like main <- feature1 <- feature2 originally, and then swapped the feature1 and feature2 (main <- feature2 <- feature1), without a git-push beforehand, GitHub recognizes that there's no new commit between feature2 and feature1 (because GH is still recognizing them based on the pre-reorder state), rejecting the API request.

@draftcode
Copy link
Contributor Author

I guess we can check if the branch order is the same as the current local branch order. This won't detect all the cases that GH would recognize there's no new commit, but should cover some.

@wahyudibo
Copy link

Hi @draftcode, i'm pleased to meet you. I've been assigned to this issue by @jainankit and trying to replicate the issue on my end. I have followed the video in https://docs.aviator.co/aviator-cli and here's the result by running av stack tree

$ av stack tree

  * frontend-change
  │ https://github.com/wahyudibo/test-aviator-av/pull/2
  │
  * backend-1 (HEAD)
  │ https://github.com/wahyudibo/test-aviator-av/pull/1
  │
  * main

I run these commands to swap the branches order

$ av stack reorder
Starting branch frontend-change at c8ba99a
  - applied commit 50332e7 without conflict (HEAD is now at 2dd3ce4)
Starting branch backend-1 at 2dd3ce4
  - applied commit c54ea93 without conflict (HEAD is now at 1fbbf80)
  - applied commit 934a4d3 without conflict (HEAD is now at 8d8b41d)
Reorder complete!

The stack was reordered successfully.

$ av stack tree

  * backend-1 (HEAD)
  │ https://github.com/wahyudibo/test-aviator-av/pull/1
  │
  * frontend-change
  │ https://github.com/wahyudibo/test-aviator-av/pull/2
  │
  * main

Then i run av stack sync and choose Yes when it asked me to push to github and i got this result

$ av stack sync



  ✓ GitHub fetch is done
  ✓ Restack is done

    * ✓ backend-1 80669e1
    │
    * frontend-change eb81b3e
    │
    * main 312a571

  ⡿ Pushing to GitHub...

    Following branches are being pushed...

      frontend-change
        Remote: 8c68447 frontend change 2024-10-06 05:06:31 +0700 +0700 (3 minutes ago)
        Local:  eb81b3e frontend change 2024-10-06 05:09:15 +0700 +0700 (53 seconds ago)
        PR:     https://github.com/wahyudibo/test-aviator-av/pull/2

      backend-1
        Remote: 376f2d8 more backend changes 2024-10-06 05:06:15 +0700 +0700 (3 minutes ago)
        Local:  80669e1 more backend changes 2024-10-06 05:09:15 +0700 +0700 (53 seconds ago)
        PR:     https://github.com/wahyudibo/test-aviator-av/pull/1


error: failed to update pull request: github error: There are no new commits between base branch 'frontend-change' and head branch 'backend-1'

Please kindly confirm if i reproduce the issue correctly. Thanks!

@draftcode
Copy link
Contributor Author

Yeah. That's the issue.

@wahyudibo
Copy link

Thank you for your confirmation @draftcode. I have working on the solution but i just want to confirm if my approach is correct. In your comment above

I guess we can check if the branch order is the same as the current local branch order. This won't detect all the cases that GH would recognize there's no new commit, but should cover some.

I wonder if after we find out that the orders are different between local and remote, then what is the suggested next step?

My thought based on my experiment at wahyudibo/test-aviator-av#1: since we're updating PR before pushing it to github,

  • Catch error: failed to update pull request: github error: There are no new commits between base branch 'frontend-change' and head branch 'backend-1' error using conditional if
  • append the branch with those error to a temporary array
  • iterate the temporary array to fix the PR after vm.runGitPush() is executed.

In my testing repo, i create 2 branch stack (main > backend-1 > frontend-change), reorder them using av stack reorder so the order changes (main > frontend-change > backend-1) then run av stack sync using modified binary where the above error is skipped so the cli is not stopped. The result is both frontend-change and backend-1 base branches in the PR are pointed to main. This condition can be fixed if we run av stack sync once again. This time backend-1 branch in the PR correctly points to frontend-change instead of main.

Please let me know if this makes sense or not and if you have further suggestion.

@jainankit
Copy link
Contributor

Hi @wahyudibo your strategy sounds good to me. I suspect that this will be a very rare scenario, so handling the failure gracefully, and fixing the PR metadata after push is a decent fallback.

Just want to make sure that you are not expecting the user to run av stack sync twice? We should fix the PR metadata in the same command execution.

@wahyudibo
Copy link

Thank you @jainankit for your feedback.

Just want to make sure that you are not expecting the user to run av stack sync twice? We should fix the PR metadata in the same command execution.

Yes, i just want to highlight that the process of running av stack sync twice can actually fix it but in the implementation, I'll make it run in the same command execution.

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

No branches or pull requests

3 participants