feat: generalized asset repo

This commit is contained in:
TrèsAbhi committed 2024-04-20 12:08:43 -05:00
1 parent 0f7d682782
commit 4a04f8a8f3
5 files changed
+14 -9

No files matched your search

+1
View File
@@ -0,0 +1 @@
export const ASSETS_REPO = 'blitzkrieg-assets';
+2 -1
View File
@@ -1,5 +1,6 @@
import { ASSETS_REPO } from '../../constants/assets';
import isDev from './isDev'; import isDev from './isDev';
export function asset(path: string) { export function asset(path: string) {
return `https://raw.githubusercontent.com/tresabhi/blitzkrieg-assets/${isDev() ? 'dev' : 'main'}/${path}`; return `https://raw.githubusercontent.com/tresabhi/${ASSETS_REPO}/${isDev() ? 'dev' : 'main'}/${path}`;
} }
+2 -1
View File
@@ -1,3 +1,4 @@
import { ASSETS_REPO } from '../../constants/assets';
import commitMultipleFiles, { FileChange } from './commitMultipleFiles'; import commitMultipleFiles, { FileChange } from './commitMultipleFiles';
export async function commitAssets( export async function commitAssets(
@@ -12,7 +13,7 @@ export async function commitAssets(
await commitMultipleFiles( await commitMultipleFiles(
'tresabhi', 'tresabhi',
'blitzkrieg-assets', ASSETS_REPO,
production ? 'main' : 'dev', production ? 'main' : 'dev',
`${message} - ${new Date().toDateString()}`, `${message} - ${new Date().toDateString()}`,
changes, changes,
@@ -1,3 +1,4 @@
import { ASSETS_REPO } from '../../constants/assets';
import getRatingInfo from '../blitz/getRatingInfo'; import getRatingInfo from '../blitz/getRatingInfo';
interface GitHubTrees { interface GitHubTrees {
@@ -16,7 +17,7 @@ export async function getArchivedLatestSeasonNumber() {
if (ratingInfo.detail) { if (ratingInfo.detail) {
const regionsURL = ( const regionsURL = (
(await fetch( (await fetch(
'https://api.github.com/repos/tresabhi/blitzkrieg-assets/git/trees/main', `https://api.github.com/repos/tresabhi/${ASSETS_REPO}/git/trees/main`,
).then((response) => response.json())) as GitHubTrees ).then((response) => response.json())) as GitHubTrees
).tree.find(({ path }) => path === 'regions')!.url; ).tree.find(({ path }) => path === 'regions')!.url;
const comURL = ( const comURL = (
+7 -6
View File
@@ -1,3 +1,4 @@
import { ASSETS_REPO } from '../../constants/assets';
import { GithubChangeBlob, createBlob } from '../blitzrinth/createBlob'; import { GithubChangeBlob, createBlob } from '../blitzrinth/createBlob';
import { octokit } from '../blitzrinth/octokit'; import { octokit } from '../blitzrinth/octokit';
@@ -11,7 +12,7 @@ export class AssetCommit {
async add(path: string, content: string, encoding: 'utf-8' | 'base64') { async add(path: string, content: string, encoding: 'utf-8' | 'base64') {
console.log(`Blob: adding ${path}...`); console.log(`Blob: adding ${path}...`);
const blob = await createBlob('tresabhi', 'blitzkrieg-assets', { const blob = await createBlob('tresabhi', ASSETS_REPO, {
content, content,
encoding, encoding,
path, path,
@@ -26,14 +27,14 @@ export class AssetCommit {
const latestCommitSha = ( const latestCommitSha = (
await octokit.git.getRef({ await octokit.git.getRef({
owner: 'tresabhi', owner: 'tresabhi',
repo: 'blitzkrieg-assets', repo: ASSETS_REPO,
ref: `heads/${this.production ? 'main' : 'dev'}`, ref: `heads/${this.production ? 'main' : 'dev'}`,
}) })
).data.object.sha; ).data.object.sha;
const treeSha = ( const treeSha = (
await octokit.git.getCommit({ await octokit.git.getCommit({
owner: 'tresabhi', owner: 'tresabhi',
repo: 'blitzkrieg-assets', repo: ASSETS_REPO,
commit_sha: latestCommitSha, commit_sha: latestCommitSha,
}) })
).data.tree.sha; ).data.tree.sha;
@@ -41,20 +42,20 @@ export class AssetCommit {
const { data: treeData } = await octokit.git.createTree({ const { data: treeData } = await octokit.git.createTree({
owner: 'tresabhi', owner: 'tresabhi',
repo: 'blitzkrieg-assets', repo: ASSETS_REPO,
base_tree: treeSha, base_tree: treeSha,
tree: blobs, tree: blobs,
}); });
const { data: newCommitData } = await octokit.git.createCommit({ const { data: newCommitData } = await octokit.git.createCommit({
owner: 'tresabhi', owner: 'tresabhi',
repo: 'blitzkrieg-assets', repo: ASSETS_REPO,
message: this.message, message: this.message,
tree: treeData.sha, tree: treeData.sha,
parents: [latestCommitSha], parents: [latestCommitSha],
}); });
await octokit.git.updateRef({ await octokit.git.updateRef({
owner: 'tresabhi', owner: 'tresabhi',
repo: 'blitzkrieg-assets', repo: ASSETS_REPO,
ref: `heads/${this.production ? 'main' : 'dev'}`, ref: `heads/${this.production ? 'main' : 'dev'}`,
sha: newCommitData.sha, sha: newCommitData.sha,
}); });