Skip to content

Commit 8e5d15c

Browse files
committed
Update commit hash and image tag on webhook event
1 parent 997f015 commit 8e5d15c

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

backend/src/service/githubWebhook.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { db, NotFoundError } from "../db/index.ts";
2-
import { DeploymentRepo } from "../db/repo/deployment.ts";
32
import type { components } from "../generated/openapi.ts";
43
import { type LogStream, type LogType } from "../generated/prisma/enums.ts";
54
import { env } from "../lib/env.ts";
@@ -10,7 +9,7 @@ import {
109
UserNotFoundError,
1110
ValidationError,
1211
} from "./common/errors.ts";
13-
import { deploymentService } from "./helper/index.ts";
12+
import { deploymentConfigService, deploymentService } from "./helper/index.ts";
1413

1514
export async function processGitHubWebhookPayload(
1615
event: string,
@@ -150,11 +149,16 @@ async function handlePush(payload: components["schemas"]["webhook-push"]) {
150149
for (const app of apps) {
151150
const org = await db.org.getById(app.orgId);
152151
const oldConfig = (await db.app.getDeploymentConfig(app.id)).asGitConfig();
152+
const config = deploymentConfigService.populateNewCommit(
153+
oldConfig,
154+
app,
155+
payload.head_commit.id,
156+
);
153157
await deploymentService.create({
154158
org,
155159
app,
156160
commitMessage: payload.head_commit.message,
157-
config: DeploymentRepo.cloneWorkloadConfig(oldConfig),
161+
config,
158162
git: {
159163
checkRun: {
160164
pending: false,
@@ -197,13 +201,20 @@ async function handleWorkflowRun(
197201
if (payload.action === "requested") {
198202
for (const app of apps) {
199203
const org = await db.org.getById(app.orgId);
200-
const config = (await db.app.getDeploymentConfig(app.id)).asGitConfig();
204+
const oldConfig = (
205+
await db.app.getDeploymentConfig(app.id)
206+
).asGitConfig();
207+
const config = deploymentConfigService.populateNewCommit(
208+
oldConfig,
209+
app,
210+
payload.workflow_run.head_commit.id,
211+
);
201212
await deploymentService.create({
202213
org,
203214
app,
204215
commitMessage: payload.workflow_run.head_commit.message,
205216
workflowRunId: payload.workflow_run.id,
206-
config: DeploymentRepo.cloneWorkloadConfig(config),
217+
config,
207218
git: {
208219
checkRun: {
209220
pending: true,

backend/src/service/helper/deploymentConfig.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import { Octokit } from "octokit";
22
import type {
33
App,
44
DeploymentConfig,
5+
GitConfig,
56
GitConfigCreate,
67
HelmConfigCreate,
78
Organization,
89
WorkloadConfig,
910
WorkloadConfigCreate,
1011
} from "../../db/models.ts";
1112
import { AppRepo } from "../../db/repo/app.ts";
13+
import { DeploymentRepo } from "../../db/repo/deployment.ts";
1214
import type { components } from "../../generated/openapi.ts";
1315
import { MAX_SUBDOMAIN_LEN } from "../../lib/cluster/resources.ts";
1416
import { getImageConfig } from "../../lib/cluster/resources/logs.ts";
@@ -136,6 +138,16 @@ export class DeploymentConfigService {
136138
return config;
137139
}
138140

141+
populateNewCommit(config: GitConfig, app: App, commitHash: string) {
142+
return this.populateImageTag(
143+
{
144+
...DeploymentRepo.cloneWorkloadConfig(config),
145+
commitHash,
146+
},
147+
app,
148+
);
149+
}
150+
139151
private createCommonWorkloadConfig(
140152
config: components["schemas"]["WorkloadConfigOptions"],
141153
) {

0 commit comments

Comments
 (0)