Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Gerrit Batch Changes#52647

Merged
varsanojidan merged 29 commits into
mainfrom
iv/gitserver-support-gerrit-bc
Jun 5, 2023
Merged

Gerrit Batch Changes#52647
varsanojidan merged 29 commits into
mainfrom
iv/gitserver-support-gerrit-bc

Conversation

@varsanojidan

@varsanojidan varsanojidan commented May 30, 2023

Copy link
Copy Markdown
Contributor

Closes https://github.com/sourcegraph/sourcegraph/issues/50867
Closes https://github.com/sourcegraph/sourcegraph/issues/51929

📺 Loom: https://www.loom.com/share/31d7bdace69d4a5ab8c732339f0a4950

I decided to just close the Reviews PR, and open this up instead because as I was connecting everything I noticed quite a few things that weren't right and I thought it would make more sense to just merge the thing that works directly instead of making it a 2-step process.

This includes basically everything needed for Gerrit Batch Changes, but not webhooks (we don't know if that will be supported yet).

Test plan

Added tests

@cla-bot cla-bot Bot added the cla-signed label May 30, 2023
@varsanojidan varsanojidan changed the title Iv/gitserver support gerrit bc Gerrit Batch Changes May 30, 2023

// Gerrit publishes the Change at push time, and therefore
if e.ch.ExternalServiceType == extsvc.TypeGerrit {
exists = false

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Wanted to call special attention to this "workaround" here, the Changeset "exists" at this point because it gets created at push time, therefore exists would always return true, and we would always enquere a ChangesetUpdate webhook event instead of the regular publish event.

TBH I'm not sure what ramifications this workaround may cause and wanted to point it out, because as far as I can tell everything works well.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

could we move this into the changeset layer and return false for the exists flag from CreateChangeset / CreateDraftChangeset instead? That way, this loop would stay free of implementation details. Also, the description in this comment is clearer to me than the code comment so maybe copy that into the code as well? :)

@varsanojidan varsanojidan requested review from a team May 30, 2023 20:39
@varsanojidan varsanojidan added team/repo-management gerrit-bc Gerrit Batch Changes work labels May 30, 2023
@varsanojidan varsanojidan marked this pull request as ready for review May 30, 2023 20:39
@sourcegraph-bot

sourcegraph-bot commented May 30, 2023

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff c8f9efa...ab79214.

Notify File(s)
@BolajiOlajide client/web/src/enterprise/batches/settings/AddCredentialModal.tsx
@courier-new client/web/src/enterprise/batches/settings/AddCredentialModal.tsx
@eseliger client/web/src/enterprise/batches/settings/AddCredentialModal.tsx
enterprise/internal/batches/reconciler/BUILD.bazel
enterprise/internal/batches/reconciler/executor.go
enterprise/internal/batches/sources/BUILD.bazel
enterprise/internal/batches/sources/azuredevops.go
enterprise/internal/batches/sources/bitbucketcloud.go
enterprise/internal/batches/sources/bitbucketserver.go
enterprise/internal/batches/sources/common.go
enterprise/internal/batches/sources/gerrit.go
enterprise/internal/batches/sources/gerrit/types.go
enterprise/internal/batches/sources/gerrit_test.go
enterprise/internal/batches/sources/github.go
enterprise/internal/batches/sources/gitlab.go
enterprise/internal/batches/sources/mocks_test.go
enterprise/internal/batches/sources/testing/fake.go
enterprise/internal/batches/state/changeset_history.go
enterprise/internal/batches/state/state.go
enterprise/internal/batches/store/BUILD.bazel
enterprise/internal/batches/store/changesets.go
enterprise/internal/batches/types/BUILD.bazel
enterprise/internal/batches/types/changeset.go
enterprise/internal/batches/types/changeset_event.go
enterprise/internal/batches/types/changeset_event_test.go
enterprise/internal/batches/types/changeset_test.go
enterprise/internal/batches/webhooks/changeset.go
internal/extsvc/gerrit/changes.go
internal/extsvc/gerrit/changes_test.go
internal/extsvc/gerrit/client.go
internal/extsvc/gerrit/testdata/golden/GetChangeReviews.json
internal/extsvc/gerrit/testdata/vcr/GetChangeReviews.yaml
internal/extsvc/gerrit/testdata/vcr/SetReadyForReview.yaml
internal/extsvc/gerrit/testdata/vcr/SetWIP.yaml
internal/extsvc/gerrit/types.go
@indradhanush cmd/gitserver/server/patch.go
@sashaostrikov cmd/gitserver/server/patch.go
internal/extsvc/gerrit/changes.go
internal/extsvc/gerrit/changes_test.go
internal/extsvc/gerrit/client.go
internal/extsvc/gerrit/testdata/golden/GetChangeReviews.json
internal/extsvc/gerrit/testdata/vcr/GetChangeReviews.yaml
internal/extsvc/gerrit/testdata/vcr/SetReadyForReview.yaml
internal/extsvc/gerrit/testdata/vcr/SetWIP.yaml
internal/extsvc/gerrit/types.go
@sourcegraph/delivery doc/admin/external_service/index.md
@unknwon enterprise/internal/authz/gerrit/mocks_test.go

Comment thread enterprise/internal/batches/reconciler/executor.go Outdated
@varsanojidan

varsanojidan commented May 30, 2023

Copy link
Copy Markdown
Contributor Author

I ran through all of the scenarios here, and all of them seem good (with the exception of forks because Gerrit doesn't support it).

@eseliger eseliger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I ran through all of the scenarios https://github.com/sourcegraph/sourcegraph/pull/47913#issuecomment-1439155858, and all of them seem good (with the exception of forks because Gerrit doesn't support it).

If forks aren't supported, what happens when the flag is set? Does it error, or just ignore the flag?


// Gerrit publishes the Change at push time, and therefore
if e.ch.ExternalServiceType == extsvc.TypeGerrit {
exists = false

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

could we move this into the changeset layer and return false for the exists flag from CreateChangeset / CreateDraftChangeset instead? That way, this loop would stay free of implementation details. Also, the description in this comment is clearer to me than the code comment so maybe copy that into the code as well? :)

Comment thread enterprise/internal/batches/reconciler/executor.go Outdated
@varsanojidan

Copy link
Copy Markdown
Contributor Author

could we move this into the changeset layer and return false for the exists flag from CreateChangeset / CreateDraftChangeset instead? That way, this loop would stay free of implementation details. Also, the description in this comment is clearer to me than the code comment so maybe copy that into the code as well? :)

I think my brain must have lagged and not actually finished the comment lol, yeah I'll update it. I can give it a shot for sure, the reason I was hesitant was because the Change technically exists at the time you call CreateChangeset, so I wasn't sure if it might mess with some other logic, but I'll try it out and validate that everything behaves as expected.

@sourcegraph-buildkite

sourcegraph-buildkite commented Jun 1, 2023

Copy link
Copy Markdown
Collaborator

Bundle size report 📦

Initial size Total size Async size Modules
0.00% (0.00 kb) -0.00% (-0.31 kb) -0.00% (-0.31 kb) 0.00% (0)

Look at the Statoscope report for a full comparison between the commits 2d3021b and aa7cc2e or learn more.

Open explanation
  • Initial size is the size of the initial bundle (the one that is loaded when you open the page)
  • Total size is the size of the initial bundle + all the async loaded chunks
  • Async size is the size of all the async loaded chunks
  • Modules is the number of modules in the initial bundle

@sourcegraph-bot

sourcegraph-bot commented Jun 1, 2023

Copy link
Copy Markdown
Contributor

📖 Storybook live preview

@courier-new courier-new left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍👍👍👍
Thank you for adding all the tests here too!!!

Comment thread client/web/src/enterprise/batches/settings/AddCredentialModal.tsx
Comment thread cmd/gitserver/server/patch.go Outdated
Comment thread cmd/gitserver/server/patch.go Outdated
Comment thread doc/admin/external_service/index.md
Comment thread enterprise/internal/batches/reconciler/executor.go Outdated
Comment thread enterprise/internal/batches/sources/gerrit.go Outdated
Comment thread enterprise/internal/batches/state/state.go
Comment thread enterprise/internal/batches/types/changeset.go
Comment thread enterprise/internal/batches/types/changeset_event.go
Comment thread internal/extsvc/gerrit/testdata/golden/GetChangeReviews.json
@varsanojidan

varsanojidan commented Jun 2, 2023

Copy link
Copy Markdown
Contributor Author

@courier-new thank you for the amazing feedback, I believe I should've addressed all of your suggestions in my most recent commit.

@courier-new courier-new left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great changes, left a couple more minor comments.

Another question, since you didn't go this far in your Loom recording: What is the behavior for updating a changeset, like when you go back and execute an updated batch spec that changes the title or produces a different diff and you need to commit and push the new changes? My impression is that it would create a brand new Change on Gerrit, since GenerateGerritChangeID would produce a different ID now. Do we update the tracking okay, i.e. is there still only one Change associated with the batch change after that update? Do we do anything with the old Change on Gerrit/should we?

Comment thread cmd/gitserver/server/patch.go Outdated
Comment thread enterprise/internal/batches/sources/gerrit.go
Comment thread cmd/gitserver/server/patch.go Outdated
Comment thread cmd/gitserver/server/patch.go Outdated
Comment thread cmd/gitserver/server/patch.go Outdated
Comment thread enterprise/internal/batches/sources/common.go Outdated
@varsanojidan

Copy link
Copy Markdown
Contributor Author

@courier-new I believe I should have addressed all of the comments, the last thing I need to do is validate the scenario when updating the Changeset now that we use the deterministic Change ID approach. I'll update here tomorrow when I look into it.

@varsanojidan

varsanojidan commented Jun 5, 2023

Copy link
Copy Markdown
Contributor Author

@courier-new now that we do the deterministic ChangeID, updating the Batch Change (title and script), as you predicted, does create a new Change on the Gerrit code host, but the tracking is not updated locally, so the Batch Change still has the old Change.

As you called out, the creation of the new Change is happening because of the deterministic ChangeID generation. My question is, what behavior do we want here? Are we ok with it just creating a new change and we update the Changeset to point to the new Change? Do we want it to still be attached to the old change in which case the deterministic Change ID might be an issue here? I ask because I see for other code hosts we just update the existing PR.

@varsanojidan

Copy link
Copy Markdown
Contributor Author

@courier-new I got it to work almost as expected here, it just required messing around a bit with Gerrit's BuildCommitOpts func to use an existing ChangeID instead of generating one if ti exists 😄.

@varsanojidan varsanojidan enabled auto-merge (squash) June 5, 2023 18:30
@varsanojidan varsanojidan merged commit be61c04 into main Jun 5, 2023
@varsanojidan varsanojidan deleted the iv/gitserver-support-gerrit-bc branch June 5, 2023 18:51
ErikaRS pushed a commit that referenced this pull request Jun 22, 2023
Closes https://github.com/sourcegraph/sourcegraph/issues/50867

📺 Loom: https://www.loom.com/share/31d7bdace69d4a5ab8c732339f0a4950

I decided to just close the [Reviews
PR](https://github.com/sourcegraph/sourcegraph/pull/52470), and open
this up instead because as I was connecting everything I noticed quite a
few things that weren't right and I thought it would make more sense to
just merge the thing that works directly instead of making it a 2-step
process.

This includes basically everything needed for Gerrit Batch Changes, but
not webhooks (we don't know if that will be supported yet).

## Test plan

Added tests
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed gerrit-bc Gerrit Batch Changes work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Modify /create-commit-from-patch-binary in Gitserver to support Gerrit BC. Add Gerrit support for Batch Changes

5 participants