Skip to content

Commit

Permalink
feat(backend): log package bumps for history, improve log output
Browse files Browse the repository at this point in the history
  • Loading branch information
dr460nf1r3 committed Nov 5, 2024
1 parent ef2fb47 commit 14b1ed0
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 38 deletions.
16 changes: 16 additions & 0 deletions backend/src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { CountNameObject, UserAgentList } from "@./shared-lib";
import type { ConfigService } from "@nestjs/config";
import * as bcrypt from "bcrypt";
import { requiredEnvVarsDev, requiredEnvVarsProd } from "./constants";
import { BumpType } from "./interfaces/repo-manager";

/**
* Parse the output of the non-single line metrics.
Expand Down Expand Up @@ -83,3 +84,18 @@ export function isValidUrl(url: string): boolean {
return false;
}
}

export function bumpTypeToText(type: BumpType): string {
switch (type) {
case BumpType.EXPLICIT:
return "explicitly";
case BumpType.GLOBAL:
return "globally";
case BumpType.FROM_DEPS:
return "via Arch dependencies";
case BumpType.FROM_DEPS_CHAOTIC:
return "via Chaotic dependencies";
default:
return "Unknown";
}
}
24 changes: 23 additions & 1 deletion backend/src/interfaces/repo-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ export interface RepoSettings {

export interface RepoUpdateRunParams {
archPkg: ArchlinuxPackage | Package;
bumpType: BumpType;
configs: CiConfigs;
pkg: Package;
triggerFrom: TriggerType;
}

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

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

Expand All @@ -69,3 +71,23 @@ export interface PackageConfig {
pkgInDb: Package;
rebuildTriggers: string[];
}

export interface PackageBumpEntry {
pkg: Package;
bumpType: BumpType;
trigger: number;
triggerName?: string;
triggerFrom: TriggerType;
}

export enum BumpType {
EXPLICIT = 0,
GLOBAL = 1,
FROM_DEPS = 2,
FROM_DEPS_CHAOTIC = 3,
}

export enum TriggerType {
ARCH = 0,
CHAOTIC = 1,
}
27 changes: 26 additions & 1 deletion backend/src/repo-manager/repo-manager.entity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Column, Entity, PrimaryGeneratedColumn, Repository } from "typeorm";
import { Column, CreateDateColumn, Entity, ManyToOne, PrimaryGeneratedColumn, Repository } from "typeorm";
import { Mutex } from "async-mutex";
import { Logger } from "@nestjs/common";
import { BumpType, TriggerType } from "../interfaces/repo-manager";
import { Package } from "../builder/builder.entity";

@Entity()
export class ArchlinuxPackage {
Expand Down Expand Up @@ -41,6 +43,29 @@ export class RepoManagerSettings {
value: string;
}

@Entity()
export class PackageBump {
@PrimaryGeneratedColumn()
id: number;

@Column({ type: "enum", enum: BumpType })
bumpType: BumpType;

@ManyToOne(() => Package, (pkg) => pkg.id, { cascade: true })
pkg: Package

// Reference a pkg.id from the Package or ArchlinuxPackage entities, resolved
// By the triggerFrom field
@Column({ type: "int" })
trigger: number;

@Column({ type: "enum", enum: TriggerType })
triggerFrom: TriggerType;

@CreateDateColumn()
timestamp: Date;
}

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

Expand Down
4 changes: 2 additions & 2 deletions backend/src/repo-manager/repo-manager.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { RepoManagerController } from "./repo-manager.controller";
import { RepoManagerService } from "./repo-manager.service";
import { HttpModule } from "@nestjs/axios";
import { TypeOrmModule } from "@nestjs/typeorm";
import { ArchlinuxPackage, RepoManagerSettings } from "./repo-manager.entity";
import { ArchlinuxPackage, PackageBump, RepoManagerSettings } from "./repo-manager.entity";
import { ConfigModule } from "@nestjs/config";
import repoManagerConfig from "../config/repo-manager.config";
import { BuilderModule } from "../builder/builder.module";
Expand All @@ -15,7 +15,7 @@ import { BuilderModule } from "../builder/builder.module";
forwardRef(() => BuilderModule),
ConfigModule.forFeature(repoManagerConfig),
HttpModule,
TypeOrmModule.forFeature([ArchlinuxPackage, RepoManagerSettings]),
TypeOrmModule.forFeature([ArchlinuxPackage, RepoManagerSettings, PackageBump]),
],
providers: [RepoManagerService],
})
Expand Down
Loading

0 comments on commit 14b1ed0

Please sign in to comment.