-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblob-creator.ts
More file actions
69 lines (60 loc) · 2.14 KB
/
blob-creator.ts
File metadata and controls
69 lines (60 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import * as core from '@actions/core';
import type * as github from '@actions/github';
import type { FileChange } from './types.js';
type Octokit = ReturnType<typeof github.getOctokit>;
/**
* Tree item for GitHub API
*/
interface TreeItem {
path: string;
mode: '100644' | '100755';
type: 'blob';
sha: string;
}
/**
* Create blobs in batches to avoid overwhelming the API
* @param files Array of file changes to create blobs for
* @param octokit GitHub API client
* @param owner Repository owner
* @param repo Repository name
* @param batchSize Number of blobs to create concurrently (default: 10)
* @returns Array of tree items
*/
export async function createBlobsInBatches(
files: FileChange[],
octokit: Octokit,
owner: string,
repo: string,
batchSize = 10,
): Promise<TreeItem[]> {
const treeItems: TreeItem[] = [];
const totalFiles = files.length;
core.debug(`Creating ${totalFiles} blob(s) in batches of ${batchSize}`);
for (let i = 0; i < totalFiles; i += batchSize) {
const batch = files.slice(i, i + batchSize);
const batchNumber = Math.floor(i / batchSize) + 1;
const totalBatches = Math.ceil(totalFiles / batchSize);
core.debug(`Processing batch ${batchNumber}/${totalBatches} (${batch.length} file(s))`);
const batchResults = await Promise.all(
batch.map(async (file) => {
core.debug(`Creating blob for: ${file.path} (mode: ${file.mode})`);
const blobResponse = await octokit.rest.git.createBlob({
owner,
repo,
content: file.content,
encoding: 'utf-8',
});
core.debug(`Blob created: ${blobResponse.data.sha}`);
return {
path: file.path,
mode: file.mode as '100644' | '100755',
type: 'blob' as const,
sha: blobResponse.data.sha,
};
}),
);
treeItems.push(...batchResults);
}
core.debug(`✓ Successfully created ${treeItems.length} blob(s)`);
return treeItems;
}