batches: construct webhook payload via GraphQL request - #46967
Conversation
|
Codenotify: Notifying subscribers in CODENOTIFY files for diff 7e39581...9e78379.
|
|
Hmm, y'know, this is cool and all, but I admit when Erik first suggested the idea, I guess imagined this looking a bit different. 😅 I was kinda hoping that would mean a net reduction of lines of code, maybe that was naive of me... 😂 It's also kinda unfortunate now that there's three places you would have to update the next time we add another field on a batch change. But I'd love to understand better! So the main benefit we're getting here is that we no longer have to duplicate the namespace marshaling logic or any of the other little things to marshal values into JSON-friendly format? Are there other benefits? 🙂 |
| SyncerError *string `json:"syncer_error"` | ||
| } | ||
|
|
||
| func MarshalChangeset(ctx context.Context, db basestore.ShareableStore, cs *types.Changeset) ([]byte, error) { |
There was a problem hiding this comment.
Am I missing something here? It looks like MarshalChangeset is still just creating the changeset body payload manually, not with an internal GraphQL request.
There was a problem hiding this comment.
@BolajiOlajide would we be able to do the same internal GraphQL query thing for MarshalChangeset, too?
There was a problem hiding this comment.
Yes, I can do that.
How about another approach? Since we can depend on the GraphQL schema to construct the webhook payload, how about we change the signature of the MarshalX method to take in a graphql.ID as the last parameter instead of the full struct. That way func MarshalChangeset(ctx context.Context, cs *types.Changeset) ([]byte, error) becomes func MarshalChangeset(ctx context.Context, id graphql.ID) ([]byte, error) {
There was a problem hiding this comment.
What do you think @courier-new @eseliger ?
There was a problem hiding this comment.
I think we talked about this in Barcelona but just wanted to put it on the record here, too -- that sounds good to me!
I think it has a bunch of benefits actually IMO:
How do you feel about that? |
|
Could you elaborate a bit more on,
I thought webhooks are configured with just a secret at the site admin level. |
Ah, I guess that doesn't give us a lot of benefit then today :D when we start allowing webhooks on the user-level as well (site-admin is pretty clunky imo and puts a lot of config burden on often a single individual) it'll help 🤷 |
Yeah, I misunderstood the secrets aspect, also. Let's close this Pull Request and the associated issue. |
|
I didn't mean to say this doesn't have other benefits, it just doesn't give the benefit of the deduplication of security today. I still think this is a valid approach overall to computing these payloads 🤷 |
Yeah, I 💯 agree with that.. |
|
Yes, that does feel like a good set of benefits. 🙂
I am just a bit concerned about this one, though -- I agree, I like the intentionality behind it, but I worry it'll be very easy to forget to make changes over here when the primary GraphQL type changes, especially if someone other than the 4 of us in this discussion is making the change. It's probably worth us adding some inline comments to the |
|
We could also argue that it gives stability to the payload and that we intentionally expose new fields, and also get alerted (because the query would fail) if a field would be not available anymore which would break the webhook payload API contract. I'm not feeling super strongly about this, but figured I'd leave a note on that here :) |
This is a part of #46967. `ForkName` is one of the fields on the webhook payload for a changeset, we don't currently expose `ForkName` via the GraphQL API, this PR fixes that. ## Test plan <!-- All pull requests REQUIRE a test plan: https://docs.sourcegraph.com/dev/background-information/testing_principles --> * Manually tested * Update unit tests for forked changesets <img width="1199" alt="CleanShot 2023-02-20 at 19 30 43@2x" src="https://user-images.githubusercontent.com/25608335/220178496-7f7a19b6-4c85-4714-8f13-2aceab9cc1dc.png"> --------- Co-authored-by: Kelli Rockwell <kelli@sourcegraph.com>
This is a part of #46967. `ForkName` is one of the fields on the webhook payload for a changeset, we don't currently expose `ForkName` via the GraphQL API, this PR fixes that. ## Test plan <!-- All pull requests REQUIRE a test plan: https://docs.sourcegraph.com/dev/background-information/testing_principles --> * Manually tested * Update unit tests for forked changesets <img width="1199" alt="CleanShot 2023-02-20 at 19 30 43@2x" src="https://user-images.githubusercontent.com/25608335/220178496-7f7a19b6-4c85-4714-8f13-2aceab9cc1dc.png"> --------- Co-authored-by: Kelli Rockwell <kelli@sourcegraph.com>
This is also a part of https://github.com/sourcegraph/sourcegraph/pull/46967. We need to expose the id of the batch change that owns a changeset. ## Test plan <!-- All pull requests REQUIRE a test plan: https://docs.sourcegraph.com/dev/background-information/testing_principles --> * Manually tested * Add unit tests
5accb01 to
fa7cd6e
Compare
courier-new
left a comment
There was a problem hiding this comment.
Looks great, thanks Bolaji! Just had 2 minor nits and a field name change suggestion.
| ID graphql.ID `json:"id"` | ||
| Name string `json:"name"` | ||
| Description string `json:"description"` | ||
| State string `json:"state"` | ||
| URL string `json:"url"` | ||
| CreatedAt time.Time `json:"createdAt"` | ||
| UpdatedAt time.Time `json:"updatedAt"` | ||
| LastAppliedAt *time.Time `json:"lastAppliedAt"` | ||
| ClosedAt *time.Time `json:"closedAt"` | ||
| Namespace struct { | ||
| ID graphql.ID `json:"id"` | ||
| } `json:"namespace"` | ||
| Creator struct { | ||
| ID graphql.ID `json:"id"` | ||
| } `json:"creator"` | ||
| LastApplier struct { | ||
| ID *graphql.ID `json:"id"` | ||
| } `json:"lastApplier"` |
There was a problem hiding this comment.
Nittiest of nits: Would it be possible to order these fields in the same way that they're ordered in the corresponding GraphQL query string? Might make it 10% easier to add additional fields in the future.
| externalURL = &node.ExternalURL.URL | ||
| } | ||
|
|
||
| return json.Marshal(changeset{ |
There was a problem hiding this comment.
Same ordering ask about these fields.
|
|
||
| return json.Marshal(&payload) | ||
| ForkName: node.ForkName, | ||
| OwningBatchChangeID: node.OwnedByBatchChange, |
There was a problem hiding this comment.
I just noticed, shouldn't these field names match?
| OwningBatchChangeID: node.OwnedByBatchChange, | |
| OwnedByBatchChange: node.OwnedByBatchChange, |
Closes #46989
Test plan
Tested locally using
webhook.site, and it looks good.