Skip to content

Commit

Permalink
fix(backend): actually push back changes from Chaotic run
Browse files Browse the repository at this point in the history
  • Loading branch information
dr460nf1r3 committed Nov 5, 2024
1 parent 411d8d3 commit f38e760
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 12 deletions.
8 changes: 8 additions & 0 deletions backend/src/interfaces/repo-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,11 @@ export enum TriggerType {
ARCH = 0,
CHAOTIC = 1,
}

export interface BumpLogEntry {
bumpType: BumpType;
pkgname: string;
trigger: string;
triggerFrom: TriggerType;
timestamp: string;
}
53 changes: 41 additions & 12 deletions backend/src/repo-manager/repo-manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -212,14 +213,50 @@ 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<Build>) {
const result: BumpResult[] = [await this.repoManager.checkPackageDepsAfterDeployment(build)];
if (result.length > 0) {
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<BumpLogEntry[]> {
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<BumpLogEntry> = {};
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;
}
}

/**
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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<void> {
async pushChanges(repoDir: string, needsRebuild: RepoUpdateRunParams[], repo: Repo): Promise<void> {
Logger.log("Committing changes and pushing back to repo...", "RepoManager");
for (const param of needsRebuild) {
try {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f38e760

Please sign in to comment.