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

graphqlbackend: Implement diff and reproducedDiff #47310

Merged
merged 7 commits into from
Feb 2, 2023

Conversation

indradhanush
Copy link
Contributor

@indradhanush indradhanush commented Feb 2, 2023

Fixes #46031.

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

Example API output:

image

👉🏽 Try it out yourself:

  1. git fetch && git checkout ig/pretty-diff-api
  2. sg start
  3. Make a change to the site configuration from the UI
  4. Run the query by clicking here.

Test plan

  • Tested locally
  • Added tests
  • Build should pass

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
@cla-bot cla-bot bot added the cla-signed label Feb 2, 2023
@indradhanush indradhanush requested a review from a team February 2, 2023 11:13
@indradhanush indradhanush marked this pull request as ready for review February 2, 2023 11:13
@indradhanush indradhanush added feature Tracking issues for a feature site-admin-ux Issues related to site-admin UX: bugs, papercuts, design, ... labels Feb 2, 2023
@indradhanush indradhanush self-assigned this Feb 2, 2023
Comment on lines -24 to -28
// One line wrapper to be able to use in tests as well.
func marshalSiteConfigurationChangeID(id int32) graphql.ID {
return relay.MarshalID(siteConfigurationChangeKind, &id)
}

Copy link
Contributor Author

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.

Copy link
Contributor

@mrnugget mrnugget left a 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))
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

@mrnugget mrnugget Feb 2, 2023

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) 🙂 )

Copy link
Contributor Author

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

Copy link
Contributor

@mrnugget mrnugget left a 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
Copy link
Contributor

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

Copy link
Contributor Author

@indradhanush indradhanush Feb 2, 2023

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
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Whitespace is off.

@indradhanush indradhanush merged commit 603ff84 into main Feb 2, 2023
@indradhanush indradhanush deleted the ig/pretty-diff-api branch February 2, 2023 14:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed feature Tracking issues for a feature site-admin-ux Issues related to site-admin UX: bugs, papercuts, design, ...
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Persist edit history for site configuration including author and expose via GraphQL
2 participants