Skip to content

a8n: Introduce PreviewDiff to simplify CampaignPlan diffs

Warren Gifford requested to merge a8n/campaign-job-diffs into master

Created by: mrnugget

This solves the problem discussed in this comment chain and on the Zoom call.

It splits up ChangesetPlan and ExternalChangeset into two different types that do not implement the same interface in order to give ChangesetPlan a new diff type: PreviewRepositoryDiff

The difference between PreviewRepositoryDiff and the type we had before is that this new one doesn't rely on FileDiff.

The problem with FileDiff was that it requires a newFile: File2 field and that was/is too much effort to implement now.

The reason why it's hard to implement: in the backend we only have the "old" file at hand and a patch to generate a new file. We don't have a new file, especially not one that could easily satisfy the File2 interface , due to its url, canonicalURL, externalURLs fields. And even if we take these out of the File2 interface we'd still have to implement content, richHTML, highlight for a file that does not exist yet.

Theoretically we could return the content (and richHTML and highlight) by computing the new file content in memory, as if the diff we have at hand was applied. But not only is that computation heavy (we'd have to fetch the old file from gitserver, load it into memory, apply the diff in memory and then send the file down the wire — potentially for every file in campaign plan's diff), it's also a lot of effort to implement in this iteration.

So instead, we decided to introduce a new type in which we don't have to represent the new file in memory, but only the old file, which already exists on gitserver and for which we can use the already existing *gitTreeEntryResolver to fulfill the File2 interface.

Merge request reports

Loading