Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
314 changes: 230 additions & 84 deletions apps/obsidian/scripts/publish.ts
Comment thread
trangdoan982 marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import path from "path";
import { exec } from "child_process";
import util from "util";
import crypto from "crypto";
// https://linear.app/discourse-graphs/issue/ENG-766/upgrade-all-commonjs-to-esm
// TODO if possible: change apps/obsidian to ESM. Use require until then.
// import { Octokit } from "@octokit/core";
Expand Down Expand Up @@ -47,6 +48,9 @@
"manifest.json",
"styles.css",
] as const;
const BLOB_UPLOAD_BATCH_SIZE = 10;
const MAX_GITHUB_RETRIES = 5;
const BASE_RETRY_DELAY_MS = 2_000;

const TARGET_REPO = "DiscourseGraphs/discourse-graph-obsidian";
const OWNER = "DiscourseGraphs";
Expand All @@ -56,6 +60,96 @@
console.log(`[Obsidian Publisher] ${message}`);
};

const sleep = async (ms: number): Promise<void> =>
new Promise((resolve) => setTimeout(resolve, ms));

const isSecondaryRateLimitError = (error: unknown): boolean => {
const maybeError = error as {
status?: number;
response?: { data?: { message?: string } };
message?: string;
};
const message =
maybeError?.response?.data?.message?.toLowerCase() ??
maybeError?.message?.toLowerCase() ??
"";
return maybeError?.status === 403 && message.includes("secondary rate limit");
};

const getRetryDelayMs = (error: unknown, attempt: number): number => {
const maybeError = error as {
response?: { headers?: Record<string, string | undefined> };
};
const retryAfterHeader = maybeError?.response?.headers?.["retry-after"];
const retryAfterSeconds = Number(retryAfterHeader);
if (Number.isFinite(retryAfterSeconds) && retryAfterSeconds > 0) {
return retryAfterSeconds * 1000;
}
return BASE_RETRY_DELAY_MS * 2 ** attempt;
};

const requestWithRetry = async <T = unknown>(
request: () => Promise<T>,
context: string,
): Promise<T> => {
let attempt = 0;

while (true) {

Check warning on line 97 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L97

Unexpected constant condition no-constant-condition
Raw output
   97:10  warning  Unexpected constant condition                                                                                           no-constant-condition
try {
return await request();
} catch (error) {
if (!isSecondaryRateLimitError(error) || attempt >= MAX_GITHUB_RETRIES) {
throw error;
}

const delayMs = getRetryDelayMs(error, attempt);
log(
`Secondary rate limit hit during ${context}. Retrying in ${Math.ceil(delayMs / 1000)}s (attempt ${attempt + 1}/${MAX_GITHUB_RETRIES})...`,
);
await sleep(delayMs);
attempt += 1;
}
}
};

const getAllFiles = (dir: string, baseDir: string = dir): string[] => {
const files: string[] = [];

fs.readdirSync(dir, { withFileTypes: true }).forEach((entry) => {
const fullPath = path.join(dir, entry.name);
const relativePath = path.relative(baseDir, fullPath);

if (shouldExclude(fullPath, baseDir)) {
log(`Excluding: ${relativePath}`);
return;
}

if (entry.isDirectory()) {
files.push(...getAllFiles(fullPath, baseDir));
} else {
files.push(relativePath);
}
});

return files;
};

const getGitBlobSha = (content: Buffer): string => {
const header = Buffer.from(`blob ${content.length}\0`, "utf8");
return crypto
.createHash("sha1")
.update(Buffer.concat([header, content]))
.digest("hex");
};

const chunk = <T>(items: T[], size: number): T[][] => {
const chunks: T[][] = [];
for (let i = 0; i < items.length; i += size) {
chunks.push(items.slice(i, i + size));
}
return chunks;
};

const getEnvVar = (name: string): string => {
const value = process.env[name];
if (!value) {
Expand Down Expand Up @@ -306,128 +400,180 @@
const repo = REPO;

try {
const { data: ref } = await octokit.request(
"GET /repos/{owner}/{repo}/git/refs/{ref}",
{
owner,
repo,
ref: "heads/main",
},
const { data: ref } = await requestWithRetry<any>(

Check warning on line 403 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L403

Unsafe assignment of an `any` value @typescript-eslint/no-unsafe-assignment
Raw output
  403:11  warning  Unsafe assignment of an `any` value                                                                                     @typescript-eslint/no-unsafe-assignment

Check warning on line 403 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L403

Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
Raw output
  403:50  warning  Unexpected any. Specify a different type                                                                                @typescript-eslint/no-explicit-any
() =>
octokit.request("GET /repos/{owner}/{repo}/git/refs/{ref}", {

Check warning on line 405 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L405

Unsafe return of an `any` typed value @typescript-eslint/no-unsafe-return
Raw output
  405:9   warning  Unsafe return of an `any` typed value                                                                                   @typescript-eslint/no-unsafe-return

Check warning on line 405 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L405

Unsafe call of an `any` typed value @typescript-eslint/no-unsafe-call
Raw output
  405:9   warning  Unsafe call of an `any` typed value                                                                                     @typescript-eslint/no-unsafe-call

Check warning on line 405 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L405

Unsafe member access .request on an `any` value @typescript-eslint/no-unsafe-member-access
Raw output
  405:17  warning  Unsafe member access .request on an `any` value                                                                         @typescript-eslint/no-unsafe-member-access
owner,
repo,
ref: "heads/main",
}),
"fetching main branch ref",
);

if (!ref?.object?.sha) {
throw new Error("Failed to get main branch reference");
}
const currentSha = ref.object.sha;

const { data: currentCommit } = await octokit.request(
"GET /repos/{owner}/{repo}/git/commits/{commit_sha}",
{
owner,
repo,
commit_sha: currentSha,
},
const { data: currentCommit } = await requestWithRetry<any>(

Check warning on line 418 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L418

Unsafe assignment of an `any` value @typescript-eslint/no-unsafe-assignment
Raw output
  418:11  warning  Unsafe assignment of an `any` value                                                                                     @typescript-eslint/no-unsafe-assignment

Check warning on line 418 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L418

Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
Raw output
  418:60  warning  Unexpected any. Specify a different type                                                                                @typescript-eslint/no-explicit-any
() =>
octokit.request("GET /repos/{owner}/{repo}/git/commits/{commit_sha}", {

Check warning on line 420 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L420

Unsafe return of an `any` typed value @typescript-eslint/no-unsafe-return
Raw output
  420:9   warning  Unsafe return of an `any` typed value                                                                                   @typescript-eslint/no-unsafe-return

Check warning on line 420 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L420

Unsafe call of an `any` typed value @typescript-eslint/no-unsafe-call
Raw output
  420:9   warning  Unsafe call of an `any` typed value                                                                                     @typescript-eslint/no-unsafe-call

Check warning on line 420 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L420

Unsafe member access .request on an `any` value @typescript-eslint/no-unsafe-member-access
Raw output
  420:17  warning  Unsafe member access .request on an `any` value                                                                         @typescript-eslint/no-unsafe-member-access
owner,
repo,
commit_sha: currentSha,

Check warning on line 423 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L423

Unsafe assignment of an `any` value @typescript-eslint/no-unsafe-assignment
Raw output
  423:11  warning  Unsafe assignment of an `any` value                                                                                     @typescript-eslint/no-unsafe-assignment
}),
"fetching current main commit",
);

if (!currentCommit?.tree?.sha) {
throw new Error("Failed to get current commit tree");
}
const currentTreeSha = currentCommit.tree.sha;
const { data: existingTree } = await requestWithRetry<any>(

Check warning on line 432 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L432

Unsafe assignment of an `any` value @typescript-eslint/no-unsafe-assignment
Raw output
  432:11  warning  Unsafe assignment of an `any` value                                                                                     @typescript-eslint/no-unsafe-assignment

Check warning on line 432 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L432

Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
Raw output
  432:59  warning  Unexpected any. Specify a different type                                                                                @typescript-eslint/no-explicit-any
() =>
octokit.request("GET /repos/{owner}/{repo}/git/trees/{tree_sha}", {

Check warning on line 434 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L434

Unsafe return of an `any` typed value @typescript-eslint/no-unsafe-return
Raw output
  434:9   warning  Unsafe return of an `any` typed value                                                                                   @typescript-eslint/no-unsafe-return

Check warning on line 434 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L434

Unsafe call of an `any` typed value @typescript-eslint/no-unsafe-call
Raw output
  434:9   warning  Unsafe call of an `any` typed value                                                                                     @typescript-eslint/no-unsafe-call

Check warning on line 434 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L434

Unsafe member access .request on an `any` value @typescript-eslint/no-unsafe-member-access
Raw output
  434:17  warning  Unsafe member access .request on an `any` value                                                                         @typescript-eslint/no-unsafe-member-access
owner,
repo,
tree_sha: currentTreeSha,

Check warning on line 437 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L437

Unsafe assignment of an `any` value @typescript-eslint/no-unsafe-assignment
Raw output
  437:11  warning  Unsafe assignment of an `any` value                                                                                     @typescript-eslint/no-unsafe-assignment
recursive: "1",
}),
"fetching recursive main tree",
);

const getAllFiles = (dir: string, baseDir: string = dir): string[] => {
const files: string[] = [];

fs.readdirSync(dir, { withFileTypes: true }).forEach((entry) => {
const fullPath = path.join(dir, entry.name);
const relativePath = path.relative(baseDir, fullPath);

if (shouldExclude(fullPath, baseDir)) {
log(`Excluding: ${relativePath}`);
return;
}

if (entry.isDirectory()) {
files.push(...getAllFiles(fullPath, baseDir));
} else {
files.push(relativePath);
}
});

return files;
};
const existingBlobShasByPath = new Map<string, string>(
(existingTree.tree ?? [])

Check warning on line 444 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L444

Unsafe argument of type `any` assigned to a parameter of type `Iterable<readonly [string, string]> | null | undefined` @typescript-eslint/no-unsafe-argument
Raw output
  444:7   warning  Unsafe argument of type `any` assigned to a parameter of type `Iterable<readonly [string, string]> | null | undefined`  @typescript-eslint/no-unsafe-argument

Check warning on line 444 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L444

Unsafe call of an `any` typed value @typescript-eslint/no-unsafe-call
Raw output
  444:7   warning  Unsafe call of an `any` typed value                                                                                     @typescript-eslint/no-unsafe-call

Check warning on line 444 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L444

Unsafe call of an `any` typed value @typescript-eslint/no-unsafe-call
Raw output
  444:7   warning  Unsafe call of an `any` typed value                                                                                     @typescript-eslint/no-unsafe-call

Check warning on line 444 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L444

Unsafe member access .tree on an `any` value @typescript-eslint/no-unsafe-member-access
Raw output
  444:21  warning  Unsafe member access .tree on an `any` value                                                                            @typescript-eslint/no-unsafe-member-access
.filter(

Check warning on line 445 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L445

Unsafe member access .filter on an `any` value @typescript-eslint/no-unsafe-member-access
Raw output
  445:10  warning  Unsafe member access .filter on an `any` value                                                                          @typescript-eslint/no-unsafe-member-access
(entry: any): entry is { path: string; sha: string; type: string } =>

Check warning on line 446 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L446

Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
Raw output
  446:19  warning  Unexpected any. Specify a different type                                                                                @typescript-eslint/no-explicit-any
Boolean(entry.path && entry.sha && entry.type === "blob"),

Check warning on line 447 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L447

Unsafe member access .path on an `any` value @typescript-eslint/no-unsafe-member-access
Raw output
  447:27  warning  Unsafe member access .path on an `any` value                                                                            @typescript-eslint/no-unsafe-member-access

Check warning on line 447 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L447

Unsafe member access .sha on an `any` value @typescript-eslint/no-unsafe-member-access
Raw output
  447:41  warning  Unsafe member access .sha on an `any` value                                                                             @typescript-eslint/no-unsafe-member-access

Check warning on line 447 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L447

Unsafe member access .type on an `any` value @typescript-eslint/no-unsafe-member-access
Raw output
  447:54  warning  Unsafe member access .type on an `any` value                                                                            @typescript-eslint/no-unsafe-member-access
)
.map((entry: { path: string; sha: string }) => [entry.path, entry.sha]),

Check warning on line 449 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L449

Unsafe member access .map on an `any` value @typescript-eslint/no-unsafe-member-access
Raw output
  449:10  warning  Unsafe member access .map on an `any` value                                                                             @typescript-eslint/no-unsafe-member-access
);

const allFiles = getAllFiles(tempDir);
log(`Found ${allFiles.length} files to update`);

const blobPromises = allFiles.map(async (filePath) => {
const normalizedAllFiles = allFiles.map((filePath) =>
filePath.replace(/\\/g, "/"),
);
const currentRepoFiles = new Set<string>(existingBlobShasByPath.keys());
const localFiles = new Set<string>(normalizedAllFiles);
const filesToDelete = [...currentRepoFiles].filter(
(repoFilePath) => !localFiles.has(repoFilePath),
);
const filesToUpdate = allFiles.filter((filePath) => {
const fullPath = path.join(tempDir, filePath);
const content = fs.readFileSync(fullPath);
const normalizedPath = filePath.replace(/\\/g, "/");
const existingSha = existingBlobShasByPath.get(normalizedPath);
return getGitBlobSha(content) !== existingSha;
});

const { data: blob } = await octokit.request(
"POST /repos/{owner}/{repo}/git/blobs",
{
owner,
repo,
content: content.toString("base64"),
encoding: "base64",
},
log(
`Detected ${filesToUpdate.length} changed files (${allFiles.length - filesToUpdate.length} unchanged skipped)`,
);
log(`Detected ${filesToDelete.length} files to delete from target repo`);

if (filesToUpdate.length === 0 && filesToDelete.length === 0) {
log("No changes detected on main branch; skipping commit update");
return;
}

const blobBatchChunks = chunk(filesToUpdate, BLOB_UPLOAD_BATCH_SIZE);
const blobs: Array<{ path: string; sha: string }> = [];

for (const [batchIndex, blobBatch] of blobBatchChunks.entries()) {
log(
`Uploading blob batch ${batchIndex + 1}/${blobBatchChunks.length} (${blobBatch.length} files)...`,
);

if (!blob?.sha) {
throw new Error(`Failed to create blob for ${filePath}`);
}
const batchBlobs = await Promise.all(
blobBatch.map(async (filePath) => {
const fullPath = path.join(tempDir, filePath);
const content = fs.readFileSync(fullPath);

const { data: blob } = await requestWithRetry<any>(

Check warning on line 493 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L493

Unsafe assignment of an `any` value @typescript-eslint/no-unsafe-assignment
Raw output
  493:17  warning  Unsafe assignment of an `any` value                                                                                     @typescript-eslint/no-unsafe-assignment

Check warning on line 493 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L493

Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
Raw output
  493:57  warning  Unexpected any. Specify a different type                                                                                @typescript-eslint/no-explicit-any
() =>
octokit.request("POST /repos/{owner}/{repo}/git/blobs", {

Check warning on line 495 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L495

Unsafe return of an `any` typed value @typescript-eslint/no-unsafe-return
Raw output
  495:15  warning  Unsafe return of an `any` typed value                                                                                   @typescript-eslint/no-unsafe-return

Check warning on line 495 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L495

Unsafe call of an `any` typed value @typescript-eslint/no-unsafe-call
Raw output
  495:15  warning  Unsafe call of an `any` typed value                                                                                     @typescript-eslint/no-unsafe-call

Check warning on line 495 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L495

Unsafe member access .request on an `any` value @typescript-eslint/no-unsafe-member-access
Raw output
  495:23  warning  Unsafe member access .request on an `any` value                                                                         @typescript-eslint/no-unsafe-member-access
owner,
repo,
content: content.toString("base64"),
encoding: "base64",
}),
`creating blob for ${filePath}`,
);

return {
path: filePath.replace(/\\/g, "/"), // Normalize path separators for GitHub
sha: blob.sha,
};
});
if (!blob?.sha) {

Check warning on line 504 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L504

Unsafe member access .sha on an `any` value @typescript-eslint/no-unsafe-member-access
Raw output
  504:22  warning  Unsafe member access .sha on an `any` value                                                                             @typescript-eslint/no-unsafe-member-access
throw new Error(`Failed to create blob for ${filePath}`);
}

const blobs = await Promise.all(blobPromises);
return {
path: filePath.replace(/\\/g, "/"), // Normalize path separators for GitHub
sha: blob.sha,

Check warning on line 510 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L510

Unsafe assignment of an `any` value @typescript-eslint/no-unsafe-assignment
Raw output
  510:13  warning  Unsafe assignment of an `any` value                                                                                     @typescript-eslint/no-unsafe-assignment

Check warning on line 510 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L510

Unsafe member access .sha on an `any` value @typescript-eslint/no-unsafe-member-access
Raw output
  510:23  warning  Unsafe member access .sha on an `any` value                                                                             @typescript-eslint/no-unsafe-member-access
};
}),
);

const { data: newTree } = await octokit.request(
"POST /repos/{owner}/{repo}/git/trees",
{
owner,
repo,
base_tree: currentTreeSha,
tree: blobs.map((blob) => ({
path: blob.path,
mode: "100644" as const,
type: "blob" as const,
sha: blob.sha,
})),
},
blobs.push(...batchBlobs);
}

const treeUpdates = blobs.map((blob) => ({
path: blob.path,
mode: "100644" as const,
type: "blob" as const,
sha: blob.sha,
}));
const treeDeletions = filesToDelete.map((filePath) => ({
path: filePath,
mode: "100644" as const,
type: "blob" as const,
sha: null,
}));

const { data: newTree } = await requestWithRetry<any>(

Check warning on line 531 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L531

Unsafe assignment of an `any` value @typescript-eslint/no-unsafe-assignment
Raw output
  531:11  warning  Unsafe assignment of an `any` value                                                                                     @typescript-eslint/no-unsafe-assignment

Check warning on line 531 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L531

Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
Raw output
  531:54  warning  Unexpected any. Specify a different type                                                                                @typescript-eslint/no-explicit-any
() =>
octokit.request("POST /repos/{owner}/{repo}/git/trees", {

Check warning on line 533 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L533

Unsafe return of an `any` typed value @typescript-eslint/no-unsafe-return
Raw output
  533:9   warning  Unsafe return of an `any` typed value                                                                                   @typescript-eslint/no-unsafe-return

Check warning on line 533 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L533

Unsafe call of an `any` typed value @typescript-eslint/no-unsafe-call
Raw output
  533:9   warning  Unsafe call of an `any` typed value                                                                                     @typescript-eslint/no-unsafe-call

Check warning on line 533 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L533

Unsafe member access .request on an `any` value @typescript-eslint/no-unsafe-member-access
Raw output
  533:17  warning  Unsafe member access .request on an `any` value                                                                         @typescript-eslint/no-unsafe-member-access
owner,
repo,
base_tree: currentTreeSha,

Check warning on line 536 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L536

Unsafe assignment of an `any` value @typescript-eslint/no-unsafe-assignment
Raw output
  536:11  warning  Unsafe assignment of an `any` value                                                                                     @typescript-eslint/no-unsafe-assignment
tree: [...treeUpdates, ...treeDeletions],
}),
"creating updated git tree",
);

if (!newTree?.sha) {
throw new Error("Failed to create new tree");
}

const { data: newCommit } = await octokit.request(
"POST /repos/{owner}/{repo}/git/commits",
{
owner,
repo,
message: `Release v${version}`,
tree: newTree.sha,
parents: [currentSha],
},
const { data: newCommit } = await requestWithRetry<any>(

Check warning on line 546 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L546

Unsafe assignment of an `any` value @typescript-eslint/no-unsafe-assignment
Raw output
  546:11  warning  Unsafe assignment of an `any` value                                                                                     @typescript-eslint/no-unsafe-assignment

Check warning on line 546 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L546

Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
Raw output
  546:56  warning  Unexpected any. Specify a different type                                                                                @typescript-eslint/no-explicit-any
() =>
octokit.request("POST /repos/{owner}/{repo}/git/commits", {

Check warning on line 548 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L548

Unsafe return of an `any` typed value @typescript-eslint/no-unsafe-return
Raw output
  548:9   warning  Unsafe return of an `any` typed value                                                                                   @typescript-eslint/no-unsafe-return

Check warning on line 548 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L548

Unsafe call of an `any` typed value @typescript-eslint/no-unsafe-call
Raw output
  548:9   warning  Unsafe call of an `any` typed value                                                                                     @typescript-eslint/no-unsafe-call

Check warning on line 548 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L548

Unsafe member access .request on an `any` value @typescript-eslint/no-unsafe-member-access
Raw output
  548:17  warning  Unsafe member access .request on an `any` value                                                                         @typescript-eslint/no-unsafe-member-access
owner,
repo,
message: `Release v${version}`,
tree: newTree.sha,

Check warning on line 552 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L552

Unsafe assignment of an `any` value @typescript-eslint/no-unsafe-assignment
Raw output
  552:11  warning  Unsafe assignment of an `any` value                                                                                     @typescript-eslint/no-unsafe-assignment

Check warning on line 552 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L552

Unsafe member access .sha on an `any` value @typescript-eslint/no-unsafe-member-access
Raw output
  552:25  warning  Unsafe member access .sha on an `any` value                                                                             @typescript-eslint/no-unsafe-member-access
parents: [currentSha],
}),
"creating release commit",
);

if (!newCommit?.sha) {
throw new Error("Failed to create new commit");
}

await octokit.request("PATCH /repos/{owner}/{repo}/git/refs/{ref}", {
owner,
repo,
ref: "heads/main",
sha: newCommit.sha,
});
await requestWithRetry(
() =>
octokit.request("PATCH /repos/{owner}/{repo}/git/refs/{ref}", {

Check warning on line 564 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L564

Unsafe return of an `any` typed value @typescript-eslint/no-unsafe-return
Raw output
  564:9   warning  Unsafe return of an `any` typed value                                                                                   @typescript-eslint/no-unsafe-return

Check warning on line 564 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L564

Unsafe call of an `any` typed value @typescript-eslint/no-unsafe-call
Raw output
  564:9   warning  Unsafe call of an `any` typed value                                                                                     @typescript-eslint/no-unsafe-call

Check warning on line 564 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L564

Unsafe member access .request on an `any` value @typescript-eslint/no-unsafe-member-access
Raw output
  564:17  warning  Unsafe member access .request on an `any` value                                                                         @typescript-eslint/no-unsafe-member-access
owner,
repo,
ref: "heads/main",
sha: newCommit.sha,

Check warning on line 568 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L568

Unsafe assignment of an `any` value @typescript-eslint/no-unsafe-assignment
Raw output
  568:11  warning  Unsafe assignment of an `any` value                                                                                     @typescript-eslint/no-unsafe-assignment

Check warning on line 568 in apps/obsidian/scripts/publish.ts

View workflow job for this annotation

GitHub Actions / eslint (apps/obsidian)

[eslint (apps/obsidian)] apps/obsidian/scripts/publish.ts#L568

Unsafe member access .sha on an `any` value @typescript-eslint/no-unsafe-member-access
Raw output
  568:26  warning  Unsafe member access .sha on an `any` value                                                                             @typescript-eslint/no-unsafe-member-access
}),
"updating main branch reference",
);

log(`Successfully updated main branch with commit: ${newCommit.sha}`);
log(`Updated ${blobs.length} files`);
log(
`Updated ${blobs.length} files and deleted ${filesToDelete.length} files`,
);
} catch (error) {
log(`Failed to update main branch: ${error}`);
throw error;
Expand All @@ -447,7 +593,7 @@
const octokit = new Octokit({ auth: token });
const owner = OWNER;
const repo = REPO;
const tagName = `v${version}`;
const tagName = `${version}`;
Comment thread
trangdoan982 marked this conversation as resolved.
const releaseTitle = releaseName || `Discourse Graph v${version}`;
const isPrerelease = !isExternalRelease(version);

Expand Down
Loading