From f38e760db113f344fc18b2c55fed4ac483ded9f7 Mon Sep 17 00:00:00 2001 From: Nico Jensch Date: Tue, 5 Nov 2024 19:16:26 +0100 Subject: [PATCH] fix(backend): actually push back changes from Chaotic run --- backend/src/interfaces/repo-manager.ts | 8 +++ .../src/repo-manager/repo-manager.service.ts | 53 ++++++++++++++----- 2 files changed, 49 insertions(+), 12 deletions(-) diff --git a/backend/src/interfaces/repo-manager.ts b/backend/src/interfaces/repo-manager.ts index 7373ebd..7714968 100644 --- a/backend/src/interfaces/repo-manager.ts +++ b/backend/src/interfaces/repo-manager.ts @@ -92,3 +92,11 @@ export enum TriggerType { ARCH = 0, CHAOTIC = 1, } + +export interface BumpLogEntry { + bumpType: BumpType; + pkgname: string; + trigger: string; + triggerFrom: TriggerType; + timestamp: string; +} diff --git a/backend/src/repo-manager/repo-manager.service.ts b/backend/src/repo-manager/repo-manager.service.ts index b73f341..6c12f59 100644 --- a/backend/src/repo-manager/repo-manager.service.ts +++ b/backend/src/repo-manager/repo-manager.service.ts @@ -6,6 +6,7 @@ import { Stats } from "node:fs"; import http from "isomorphic-git/http/node"; import git from "isomorphic-git"; import { + BumpLogEntry, BumpResult, BumpType, PackageBumpEntry, @@ -212,7 +213,7 @@ export class RepoManagerService { /** * Bump packages depending on a single Build output. * @param build The build object - * @returns A promise that resolves when the bumping is done + * @returns A Build object promise that resolves when the bumping is done */ async eventuallyBumpAffected(build: Partial) { const result: BumpResult[] = [await this.repoManager.checkPackageDepsAfterDeployment(build)]; @@ -220,6 +221,42 @@ export class RepoManagerService { this.summarizeChanges(result, this.repoManager); } } + + /** + * Get the bump logs. + * @param options The options for the bump logs, current amount, and skip + * @returns An array of bump log entries + */ + async getBumpLogs(options: { amount: number; skip: number }): Promise { + if (!options.amount) options.amount = 100; + if (!options.skip) options.skip = 0; + + const result: BumpLogEntry[] = []; + const logEntries: PackageBump[] = await this.packageBumpRepository.find({ + take: options.amount, + skip: options.skip, + relations: ["pkg"], + }); + + for (const logEntry of logEntries) { + const entry: Partial = {}; + if (logEntry.triggerFrom === TriggerType.ARCH) { + const trigger = await this.archlinuxPackageRepository.findOne({ where: { id: logEntry.trigger } }); + entry.trigger = trigger.pkgname; + } else if (logEntry.triggerFrom === TriggerType.CHAOTIC) { + const trigger = await this.packageRepository.findOne({ where: { id: logEntry.trigger } }); + entry.trigger = trigger.pkgname; + } + entry.bumpType = logEntry.bumpType; + entry.timestamp = logEntry.timestamp.toISOString(); + entry.triggerFrom = logEntry.triggerFrom; + entry.pkgname = logEntry.pkg.pkgname; + + result.push(entry as BumpLogEntry); + } + + return result; + } } /** @@ -297,8 +334,6 @@ class RepoManager { const bumpedPackages: PackageBumpEntry[] = await this.bumpPackages(needsRebuild, repoDir); Logger.log(`Pushing changes to ${repo.name}`, "RepoManager"); - - // @ts-expect-error I specifically ensured this won't hit any regular packages await this.pushChanges(repoDir, needsRebuild, repo); Logger.debug("Done checking for rebuild triggers, cleaning up", "RepoManager"); @@ -847,15 +882,7 @@ class RepoManager { * @param repo The repository object * @private */ - private async pushChanges( - repoDir: string, - needsRebuild: { - configs: any; - archPkg: ArchlinuxPackage; - pkg: Package; - }[], - repo: Repo, - ): Promise { + async pushChanges(repoDir: string, needsRebuild: RepoUpdateRunParams[], repo: Repo): Promise { Logger.log("Committing changes and pushing back to repo...", "RepoManager"); for (const param of needsRebuild) { try { @@ -1141,6 +1168,8 @@ class RepoManager { } const bumped: PackageBumpEntry[] = await this.bumpPackages(needsRebuild, repoDir); + await this.pushChanges(repoDir, needsRebuild, build.repo); + return { repo: build.repo.name, bumped: bumped,