Skip to content

Commit

Permalink
Merge pull request #84 from chaotic-cx/feat/global-rebuild
Browse files Browse the repository at this point in the history
feat(backend): add being able to specify global bump triggers
  • Loading branch information
dr460nf1r3 authored Nov 3, 2024
2 parents 148acf5 + 7434a9a commit 4645ca8
Show file tree
Hide file tree
Showing 5 changed files with 289 additions and 158 deletions.
2 changes: 1 addition & 1 deletion backend/src/config/repo-manager.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { registerAs } from "@nestjs/config";

export default registerAs("repoMan", () => ({
alwaysRebuild: process.env.REPOMANAGER_ALWAYS_REBUILD ?? "{}",
gitAuthor: process.env.GIT_AUTHOR ?? "Chaotic Temeraire",
gitEmail: process.env.GIT_EMAIL ?? "[email protected]",
gitUsername: process.env.GIT_USERNAME ?? "git",
gitlabToken: process.env.CAUR_GITLAB_TOKEN,
globalTriggers: process.env.REPOMANAGER_ALWAYS_REBUILD ?? "[]",
schedulerInterval: process.env.REPOMANAGER_SCHEDULE ?? "0 * * * *",
}));
21 changes: 14 additions & 7 deletions backend/src/interfaces/repo-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Package } from "../builder/builder.entity";
import { ArchlinuxPackage } from "../repo-manager/repo-manager.entity";

export interface Repo {
name: string;
Expand Down Expand Up @@ -47,18 +48,24 @@ export interface RepoSettings {
gitEmail: string;
gitUsername: string;
gitlabToken: string;
alwaysRebuild: { [key: string]: string };
}

export interface PkgnameVersion {
pkgname: string;
archVersion: string;
globalTriggers: string[];
}

export interface RepoUpdateRunParams {
archPkg: ParsedPackage;
archPkg: ArchlinuxPackage;
configs: CiConfigs;
pkg: Package;
}

export type CiConfigs = { [key: string]: string };

export interface BumpResult {
bumped: Map<string, string>;
repo: string;
}

export interface PackageConfig {
configs: CiConfigs;
pkgInDb: Package;
rebuildTriggers: string[];
}
5 changes: 5 additions & 0 deletions backend/src/repo-manager/repo-manager.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ export class RepoManagerController {
updateChaoticVersions(): void {
void this.repoManager.updateChaoticVersions();
}

@Get("rebuild")
checkGlobalRebuildTriggers(): void {
void this.repoManager.checkGlobalRebuildTriggers();
}
}
32 changes: 32 additions & 0 deletions backend/src/repo-manager/repo-manager.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class RepoManagerSettings {
}

const packageMutex = new Mutex();
const settingsMutex = new Mutex();

/**
* Check if a package exists in the database, if not create a new entry
Expand Down Expand Up @@ -74,3 +75,34 @@ export async function archPkgExists(
}
});
}

/**
* Check if a setting exists in the database, if not create a new entry
* @param key The key to check
* @param connection The repository connection
*/
export function repoSettingsExists(
key: string,
connection: Repository<RepoManagerSettings>,
): Promise<RepoManagerSettings> {
return settingsMutex.runExclusive(async () => {
try {
const settings: RepoManagerSettings[] = await connection.find({ where: { key } });
let settingExists: Partial<RepoManagerSettings> = settings.find((oneSetting) => {
return oneSetting.key === key;
});

if (settingExists === undefined) {
Logger.log(`Setting ${key} not found in database, creating new entry`, "RepoManagerEntity");
settingExists = await connection.save({
key,
value: "",
});
}

return settingExists as RepoManagerSettings;
} catch (err: unknown) {
Logger.error(err, "RepoManagerEntity");
}
});
}
Loading

0 comments on commit 4645ca8

Please sign in to comment.