batches: fix naming of forks created by batch changes (bitbucket server)#43681
Conversation
…o aa/fix-fork-name merge the fork fix into branch
…o aa/fix-fork-name looking for fork fix
|
Codenotify: Notifying subscribers in CODENOTIFY files for diff bde3ece...be7329a.
|
|
Thanks for this!! Did you confirm that this issue isn't a problem for BitBucket Cloud, GitHub, or GitLab? My guess is that they'll probably all have the same or very similarly-behaving issues. |
|
Adeola and I tested the other code hosts together in our 1:1, here are our findings:
Even though GitHub handles the case okay, we agreed that our |
|
I will fix the remaining codehosts in a separate ticket and link it here |
| // If an update is run by someone who's not aharvey, this needs to be a | ||
| // repo that isn't a fork. | ||
| target := newBitbucketServerRepo(urn, "~AHARVEY", "old-talk", 0) | ||
| // This is a repo that isn't a fork. Use credentials in 1Password for "milton" to |
There was a problem hiding this comment.
Are these tests going to our actual Bitbucket instance or is the test data being injected (somehow)?
There was a problem hiding this comment.
@Piszmog actual instance, docs on this process coming soon :)
| fork, err := bbsSrc.GetUserFork(ctx, target) | ||
| assert.Nil(t, fork) | ||
| assert.ErrorIs(t, err, errNotAFork) | ||
| _, err = bbsSrc.GetUserFork(ctx, target) |
There was a problem hiding this comment.
It would still be good to ensure that fork is nil
There was a problem hiding this comment.
i thought thats what this line does? assert.Nil(t, err)
There was a problem hiding this comment.
that's right, but it looks like from the diff that line got deleted, though. I think Randell's saying we should keep it.
There was a problem hiding this comment.
oh i had removed that because 'fork' was undeclared
There was a problem hiding this comment.
yep! If you could re-add it. I like to ensure we cover our bases with outputs
|
2 questions:
Alternative idea:
|
|
(Just jotting down a bunch of passing thoughts, I defer to Adeola's judgment on what to do about this!)
I'd actually push back on that. I think it's a stretch to say most customers would expect something specific to happen when forking two repos with the same name, let alone expect what GitHub is doing, and currently it's non-deterministic which one gets forked first and gets the name
I agree this isn't ideal, but as you point out, this isn't a new problem, it's now just the same problem under a slightly different circumstance. It feels like that problem is adjacent to the one this PR is for, though. Not to say it wouldn't be great to get a 2-for-1, of course. 🙂
"Unexpected" meaning just that generally it's expected that
Wouldn't this also be confusing if only sometimes the fork repo shares the name with the original repo, and sometimes it doesn't? Especially if, again, the only determining factor for which is which is whoever got there first? I also think it'd be hard to manage race conditions here, since all the forking stuff would be happening for multiple changesets in parallel. What if we're publishing changesets for both |
|
thanks @eseliger and @courier-new for your thoughts here.. really helpful. But yeah, I think I prefer to not use numbers in the names, as I do agree that as a user, I would have any expectation of what to expect in this case of forking repos with the same name, and I dont think that I would be shocked to see this name convention |
| fork, err := bbsSrc.GetUserFork(ctx, target) | ||
| assert.Nil(t, fork) | ||
| assert.ErrorIs(t, err, errNotAFork) | ||
| _, err = bbsSrc.GetUserFork(ctx, target) |
There was a problem hiding this comment.
yep! If you could re-add it. I like to ensure we cover our bases with outputs
|
Unfortunately when trying to update the test to ensure the fork is nil by adding:
I'm now getting the following error: I dont know how I've suddenly become unauthenticated, and I've taken a number of troubleshooting steps but im not longer able to update these tests.. when i run I get data back, indicating this is not a token error.. I've spoken to @LawnGnome briefly about this and he isnt sure what can be causing this... @courier-new since I think you were previously authorized to do updates, do you mind helping me add those lines if you dont get an authorization error as well? |
|
I'm happy to try re-recording the test for you, but I think that line can be safely added/modified/removed without affecting the golden test data, since we're not actually changing anything about the request to BitBucket! We have to re-record the tests when we change how (If that's enough to unblock you, we can save figuring out the authentication problem for while we're working on the docs!) |
|
@courier-new yeah agreed, thanks! I do know that it isnt affecting the golden test data, however when I add that line and re run the rest, the test is now failing with that error when it wasnt before..so I think if i push the changes i'll have buildkite issues, or will i not? Im not sure what you mean by re-recording. I think unblocking me here would be adding the line im trying to add so I have the nil fork coverage, and can successfully merge this PR and then figuring out the auth problem as you suggested |
|
Hmm, how are you trying to run the test when you get that failure? If you're running with |
|
@courier-new when i remove the update flag im still getting the same error: can you add the lines? or do you think ill be fine if I just add the lines and push the code since they dont affect test data? Im a little scared too since its in a good state on buildkite now |
|
Do you have a clean working tree beyond these 2 line changes? Is it possible you ran it once with |
|
@courier-new ohh thanks.. that did work, i still dont know why i have the auth error for when i actually do need to update tests, but thanks for pointing out that i can do this process without |
courier-new
left a comment
There was a problem hiding this comment.
Thanks for working through the tests for this one. 🙂 Once you've created the follow-up issue for the other code hosts, do you mind adding a comment to link them from this PR and/or from the initial ticket, for tracing purposes?
This reverts commit 9cdd92e.
|
Fix for Gitlab PR: #44458 |
closes: #41641
When
batchChanges.enforceForksare enabled for batch changes we currently do not handle the case of repos that are not forks yet have the same name. Currently the changeset would fail to be created and the following error would occur:Getting user fork for "{batch_changes_user}": repo was not forked from the given parentThis was fixed by changing the naming convention of the forks to be more unique, updating the name to
parent.Project.Key + "-" + parent.SlugI will file a follow up issue to see if the error that is returned from the "Not a Fork" test could be a little more descriptive in telling the user you are not permitted to create a fork of a repo that is user namespaced. That action currently fails with the following error:
Failed to run operations on changeset Getting user fork: creating user fork for "milton": Bitbucket API HTTP error: code=409 url="https://bitbucket.sgdev.org/rest/api/1.0/projects/~MILTON/repos/vcr-fork-test-repo" body="{"errors":[{"context":"name","message":"This repository URL is already taken.","exceptionName":null}]}"Test plan
tested implementation by creating forks for same name repos, that are no longer failing at changeset creation and no longer mistakenly being detected as forks