From adc159a71eeea09c82ebfcd74a2684126cbcacbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Thu, 29 Dec 2022 15:12:11 +0100 Subject: [PATCH] Fix regression in patches feature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rūdolfs Ošiņš --- src/components/Authorship.svelte | 14 +++++--- src/lib/patch.ts | 55 ++++++++++++++++++++++++++++---- 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/src/components/Authorship.svelte b/src/components/Authorship.svelte index 3dbd4c30e..70cf25360 100644 --- a/src/components/Authorship.svelte +++ b/src/components/Authorship.svelte @@ -17,11 +17,15 @@ onMount(async () => { if (author.profile?.ens?.name) { - profile = await Profile.get( - author.profile.ens.name, - ProfileType.Minimal, - wallet, - ); + try { + profile = await Profile.get( + author.profile.ens.name, + ProfileType.Minimal, + wallet, + ); + } catch { + // Ignore profile not found. + } } }); diff --git a/src/lib/patch.ts b/src/lib/patch.ts index 926f73c1c..e3bd5da9c 100644 --- a/src/lib/patch.ts +++ b/src/lib/patch.ts @@ -143,18 +143,61 @@ export class Patch implements IPatch { } static async getPatches(id: string, host: Host): Promise { - const response: IPatch[] = await new Request( - `projects/${id}/patches`, - host, - ).get(); - return response.map(patch => new Patch(patch)); + const response = await new Request(`projects/${id}/patches`, host).get(); + for (const patch of response) { + patch.author["id"] = patch.author["urn"]; + delete patch.author["urn"]; + } + + return response.map((patch: IPatch) => new Patch(patch)); } static async getPatch(id: string, patch: string, host: Host): Promise { - const response: IPatch = await new Request( + const response = await new Request( `projects/${id}/patches/${patch}`, host, ).get(); + + response.author["id"] = response.author["urn"]; + delete response.author["urn"]; + + for (const revision of response.revisions) { + if (revision.changeset?.diff) { + revision.changeset.diff["added"] = revision.changeset.diff["created"]; + delete revision.changeset.diff["created"]; + + revision.comment.author["id"] = revision.comment.author["urn"]; + delete revision.comment.author["urn"]; + + revision.changeset.stats["insertions"] = + revision.changeset.stats["additions"]; + delete revision.changeset.stats["additions"]; + + for (const kind of ["added", "deleted", "modified"]) { + for (const file of revision.changeset.diff[kind]) { + for (const hunk of file.diff.hunks) { + for (const line of hunk.lines) { + if (line["lineNumOld"]) { + line["lineNoOld"] = line["lineNumOld"]; + delete line["lineNumOld"]; + } + + if (line["lineNumNew"]) { + line["lineNoNew"] = line["lineNumNew"]; + delete line["lineNumNew"]; + } + + if (line["lineNum"]) { + line["lineNo"] = line["lineNum"]; + delete line["lineNum"]; + } + } + } + } + } + } + } + return new Patch(response); } }