feat(web): pull request files can be marked as viewed (#7721)
Signed-off-by: Yordis Prieto <[email protected]> Co-authored-by: maria <[email protected]>
This commit is contained in:
1 parent
8db3c250f4
commit
03950089ff
67 files changed
+9014
-200
No files matched your search
@@ -19,6 +19,7 @@ import type {
|
||||
PullRequestState,
|
||||
} from "@t3tools/contracts";
|
||||
import { TrimmedNonEmptyString } from "@t3tools/contracts";
|
||||
import { quoteGitPatchPath } from "@t3tools/shared/gitPatchPath";
|
||||
import { decodeJsonResult } from "@t3tools/shared/schemaJson";
|
||||
|
||||
/**
|
||||
@@ -680,8 +681,8 @@ function diffHeaderPaths(raw: Schema.Schema.Type<typeof RawDiffSchema>): {
|
||||
readonly to: string;
|
||||
} {
|
||||
return {
|
||||
from: raw.new_file === true ? "/dev/null" : `a/${raw.old_path}`,
|
||||
to: raw.deleted_file === true ? "/dev/null" : `b/${raw.new_path}`,
|
||||
from: raw.new_file === true ? "/dev/null" : quoteGitPatchPath(`a/${raw.old_path}`),
|
||||
to: raw.deleted_file === true ? "/dev/null" : quoteGitPatchPath(`b/${raw.new_path}`),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -718,11 +719,14 @@ export function decodeMergeRequestDiffsJson(
|
||||
}
|
||||
const { from, to } = diffHeaderPaths(value);
|
||||
const header = [
|
||||
`diff --git a/${value.old_path} b/${value.new_path}`,
|
||||
`diff --git ${quoteGitPatchPath(`a/${value.old_path}`)} ${quoteGitPatchPath(`b/${value.new_path}`)}`,
|
||||
...(value.new_file === true ? [`new file mode ${value.b_mode ?? "100644"}`] : []),
|
||||
...(value.deleted_file === true ? [`deleted file mode ${value.a_mode ?? "100644"}`] : []),
|
||||
...(value.renamed_file === true
|
||||
? [`rename from ${value.old_path}`, `rename to ${value.new_path}`]
|
||||
? [
|
||||
`rename from ${quoteGitPatchPath(value.old_path)}`,
|
||||
`rename to ${quoteGitPatchPath(value.new_path)}`,
|
||||
]
|
||||
: []),
|
||||
`--- ${from}`,
|
||||
`+++ ${to}`,
|
||||
@@ -947,3 +951,82 @@ export function decodeOwnAwardIdJson(
|
||||
}
|
||||
return Result.succeed(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* What the given paths are at one revision, as blob ids. Asked for by path rather than by walking
|
||||
* the tree, since GitLab charges this query by how many paths it is given. A path the revision
|
||||
* does not have comes back missing rather than as an error, which is the answer for a deleted file.
|
||||
*/
|
||||
export const REPOSITORY_BLOBS_GRAPHQL_QUERY = `query($fullPath: ID!, $ref: String!, $paths: [String!]!) {
|
||||
project(fullPath: $fullPath) {
|
||||
repository {
|
||||
blobs(ref: $ref, paths: $paths) {
|
||||
nodes { path oid }
|
||||
}
|
||||
}
|
||||
}
|
||||
}`;
|
||||
|
||||
const RawRepositoryBlobsSchema = Schema.Struct({
|
||||
data: Schema.Struct({
|
||||
project: Schema.NullOr(
|
||||
Schema.Struct({
|
||||
repository: Schema.optional(
|
||||
Schema.NullOr(
|
||||
Schema.Struct({
|
||||
blobs: Schema.optional(
|
||||
Schema.NullOr(
|
||||
Schema.Struct({
|
||||
nodes: Schema.optional(
|
||||
Schema.NullOr(
|
||||
Schema.Array(
|
||||
Schema.NullOr(
|
||||
Schema.Struct({
|
||||
path: Schema.optional(Schema.NullOr(Schema.String)),
|
||||
oid: Schema.optional(Schema.NullOr(Schema.String)),
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
}),
|
||||
),
|
||||
),
|
||||
}),
|
||||
),
|
||||
),
|
||||
}),
|
||||
),
|
||||
}),
|
||||
});
|
||||
|
||||
const decodeRepositoryBlobs = decodeJsonResult(RawRepositoryBlobsSchema);
|
||||
|
||||
/**
|
||||
* Blob ids by path, or null where GitLab did not answer the query at all (a project the token
|
||||
* cannot see, or a repository with no blobs connection). That case must be told apart from an
|
||||
* empty answer: read as "the revision has none of these files", it would report every cleared
|
||||
* file as changed again. A node missing either half is left out, since the caller treats an
|
||||
* absent path as one the revision does not carry.
|
||||
*/
|
||||
export function decodeRepositoryBlobsJson(
|
||||
raw: string,
|
||||
): Result.Result<ReadonlyMap<string, string> | null, DecodeFailure> {
|
||||
const decoded = decodeRepositoryBlobs(raw);
|
||||
if (!Result.isSuccess(decoded)) {
|
||||
return Result.fail(decoded.failure);
|
||||
}
|
||||
const nodes = decoded.success.data.project?.repository?.blobs?.nodes;
|
||||
if (nodes === undefined || nodes === null) return Result.succeed(null);
|
||||
const blobs = new Map<string, string>();
|
||||
for (const node of nodes) {
|
||||
// Not trimmed, unlike everything else read out of this payload: a leading or trailing space
|
||||
// is a legal part of a file's name, and trimming it would key this map under a name the
|
||||
// caller's asked-for path never matches.
|
||||
const path = node?.path;
|
||||
const oid = trimmed(node?.oid);
|
||||
if (path === undefined || path === null || path.length === 0 || oid === null) continue;
|
||||
blobs.set(path, oid);
|
||||
}
|
||||
return Result.succeed(blobs);
|
||||
}
|
||||
Reference in new issue
Block a user