mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: skip unmodifined files
This commit is contained in:
1 parent
c98c19dc36
commit
d71ea5c383
1 file changed
+38
-4
@@ -11,8 +11,44 @@ export async function commitMultipleFiles(
|
|||||||
repoRaw: string,
|
repoRaw: string,
|
||||||
branch: string,
|
branch: string,
|
||||||
message: string,
|
message: string,
|
||||||
changes: FileChange[],
|
changesRaw: FileChange[],
|
||||||
) {
|
) {
|
||||||
|
const changes: FileChange[] = [];
|
||||||
|
|
||||||
|
await Promise.all(
|
||||||
|
changesRaw.map(async (change) => {
|
||||||
|
const blobPath = `${repoRaw}/${branch}/${change.path}`;
|
||||||
|
const response = await fetch(
|
||||||
|
`https://raw.githubusercontent.com/${blobPath}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.status === 404) {
|
||||||
|
console.log(
|
||||||
|
`🟢 (+${change.content.length.toLocaleString()}B) ${blobPath}`,
|
||||||
|
);
|
||||||
|
changes.push(change);
|
||||||
|
} else if (response.status === 200) {
|
||||||
|
const buffer = Buffer.from(await response.arrayBuffer());
|
||||||
|
|
||||||
|
if (!buffer.equals(change.content)) {
|
||||||
|
const diff = change.content.length - buffer.length;
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`🟡 (${diff > 0 ? '+' : ''}${diff.toLocaleString()}B) ${blobPath}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
changes.push(change);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error(
|
||||||
|
`Unexpected status code ${response.status} for ${blobPath}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (changes.length === 0) return;
|
||||||
|
|
||||||
const [owner, repo] = repoRaw.split('/');
|
const [owner, repo] = repoRaw.split('/');
|
||||||
const latestCommitSha = (
|
const latestCommitSha = (
|
||||||
await octokit.git.getRef({
|
await octokit.git.getRef({
|
||||||
@@ -31,9 +67,7 @@ export async function commitMultipleFiles(
|
|||||||
const blobs: GithubChangeBlob[] = [];
|
const blobs: GithubChangeBlob[] = [];
|
||||||
const bar = new ProgressBar('Blobs :bar', changes.length);
|
const bar = new ProgressBar('Blobs :bar', changes.length);
|
||||||
|
|
||||||
for (const changeIndexString in changes) {
|
for (const change of changes) {
|
||||||
const changeIndex = parseInt(changeIndexString);
|
|
||||||
const change = changes[changeIndex];
|
|
||||||
const createdBlob = await createBlob(owner, repo, change);
|
const createdBlob = await createBlob(owner, repo, change);
|
||||||
blobs.push(createdBlob!);
|
blobs.push(createdBlob!);
|
||||||
bar.tick();
|
bar.tick();
|
||||||
|
|||||||
Reference in new issue
Block a user