-
Notifications
You must be signed in to change notification settings - Fork 1.3k
graphqlbackend: Implement diff and reproducedDiff #47310
Conversation
In this commit we make the following changes to the SiteConfigurationChange API: - Add a new field reproducedDiff to indicate if Sourcegraph was able to generate the diff or not - Make the Diff field nullable - Implement the Diff field which was previously hardcoded to return an empty strings
// One line wrapper to be able to use in tests as well. | ||
func marshalSiteConfigurationChangeID(id int32) graphql.ID { | ||
return relay.MarshalID(siteConfigurationChangeKind, &id) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No change. Just moved it out of the way of the API methods and moved it all the way to the end of the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool!
|
||
// We're not diffing a file, so set an empty string for the URI argument. | ||
edits := myers.ComputeEdits("", prevRedactedContents, r.siteConfig.RedactedContents) | ||
diff := fmt.Sprint(gotextdiff.ToUnified(prettyID(prevID), prettyID(r.siteConfig.ID), prevRedactedContents, edits)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this require a call to fmt.Sprint
or would string()
be enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fmt.Sprint
is required. The return type of gotextdiff.ToUnified
does not have a String
method but has a Format
method: https://sourcegraph.com/github.com/hexops/gotextdiff/-/blob/unified.go?L165&subtree=true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it! (Might be a chance to open a tiny PR on hexops/gotextdiff
and add the String()
method that does exactly this: fmt.Sprint(u)
🙂 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great suggestion! PR filed: hexops/gotextdiff#3
Co-authored-by: Thorsten Ball <[email protected]>
Co-authored-by: Thorsten Ball <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good tests! I think the indentation should be fixed in the GraphQL test though
"author": null | ||
"author": null, | ||
"reproducedDiff": true, | ||
"diff": %[6]q |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the indentation is off for the new lines. Missing some <tab>
s I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh. I think this is what happened. 😂
edit: this image, turns out images are not embedded in comments
} | ||
}, | ||
"reproducedDiff": true, | ||
"diff": %[4]q |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, whitespace is off.
"author": null | ||
"author": null, | ||
"reproducedDiff": true, | ||
"diff": %[4]q |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whitespace is off.
Fixes #46031.
In this commit we make the following changes to the
SiteConfigurationChange API:
generate the diff or not
empty strings
Example API output:
👉🏽 Try it out yourself:
git fetch && git checkout ig/pretty-diff-api
sg start
Test plan