Skip to content

Commit 44c3341

Browse files
committed
feat: switched default github auth to ssh
1 parent 4d4d662 commit 44c3341

5 files changed

Lines changed: 14 additions & 16 deletions

File tree

api/prisma/dev.db

64 KB
Binary file not shown.

api/src/webhook/webhook.controller.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,23 @@ export class WebhookController {
3030
@Headers(SIGNATURE_HEADER) signature: string,
3131
): Promise<{ ok: true }> {
3232
const raw = req.rawBody?.toString('utf8');
33+
3334
if (!raw) {
3435
throw new BadRequestException('missing raw body');
3536
}
37+
3638
const valid = verifySignature(this.config.get('GITHUB_WEBHOOK_SECRET'), raw, signature);
39+
3740
if (!valid) {
3841
throw new UnauthorizedException('invalid signature');
3942
}
43+
4044
if (!event || !delivery) {
4145
throw new BadRequestException('missing event or delivery headers');
4246
}
47+
4348
await this.webhooks.handle(event, delivery, raw, req.body as unknown);
49+
4450
return { ok: true };
4551
}
4652
}

api/src/workspace/workspace.module.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { Module } from '@nestjs/common';
2-
import { GithubModule } from '../github/github.module.js';
32
import { WorkspaceService } from './workspace.service.js';
43

54
@Module({
6-
imports: [GithubModule],
5+
imports: [],
76
providers: [WorkspaceService],
87
exports: [WorkspaceService],
98
})

api/src/workspace/workspace.service.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import { mkdir, rm } from 'node:fs/promises';
44
import { Injectable, Logger } from '@nestjs/common';
55
import { simpleGit, type SimpleGit } from 'simple-git';
66
import { AppConfigService } from '../config/config.service.js';
7-
import { GithubService } from '../github/github.service.js';
87
import { type DiffSummary, type Workspace, type WorkspacePrepareInput } from './workspace.model.js';
98
import {
10-
authenticatedRemoteUrl,
9+
sshRemoteUrl,
1110
changedFilesFromStatus,
1211
workspaceDir,
1312
} from './workspace.utility.js';
@@ -21,17 +20,13 @@ import {
2120
export class WorkspaceService {
2221
private readonly logger = new Logger(WorkspaceService.name);
2322

24-
constructor(
25-
private readonly config: AppConfigService,
26-
private readonly app: GithubService,
27-
) {}
23+
constructor(private readonly config: AppConfigService) {}
2824

2925
/** Clone (if needed) and check out the job's branch. Idempotent across attempts. */
3026
async prepare(input: WorkspacePrepareInput): Promise<Workspace> {
3127
const root = this.config.get('WORKSPACE_ROOT');
3228
const dir = workspaceDir(root, input.jobId);
33-
const token = await this.app.getInstallationToken(input.installationId);
34-
const remote = authenticatedRemoteUrl(input.owner, input.repo, token);
29+
const remote = sshRemoteUrl(input.owner, input.repo);
3530

3631
if (existsSync(`${dir}/.git`)) {
3732
const git = simpleGit(dir);
@@ -86,13 +81,11 @@ export class WorkspaceService {
8681
return (await git.revparse(['HEAD'])).trim();
8782
}
8883

89-
/** Push the job branch, refreshing the remote token first (tokens expire ~1h). */
84+
/** Push the job branch using the host machine's SSH credentials. */
9085
async push(input: WorkspacePrepareInput): Promise<string> {
9186
const root = this.config.get('WORKSPACE_ROOT');
9287
const dir = workspaceDir(root, input.jobId);
9388
const git = simpleGit(dir);
94-
const token = await this.app.getInstallationToken(input.installationId);
95-
await git.remote(['set-url', 'origin', authenticatedRemoteUrl(input.owner, input.repo, token)]);
9689
await git.push(['-u', 'origin', input.branchName]);
9790
const sha = (await git.revparse(['HEAD'])).trim();
9891
this.logger.log(`[job ${input.jobId}] pushed ${input.branchName} @ ${sha}`);

api/src/workspace/workspace.utility.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ export function workspaceDir(root: string, jobId: string): string {
55
return resolve(root, jobId);
66
}
77

8-
/** HTTPS remote URL carrying a short-lived installation token. */
9-
export function authenticatedRemoteUrl(owner: string, repo: string, token: string): string {
10-
return `https://x-access-token:${token}@github.com/${owner}/${repo}.git`;
8+
/** SSH remote URL — authentication is handled by the host machine's SSH credentials. */
9+
export function sshRemoteUrl(owner: string, repo: string): string {
10+
return `git@github.com:${owner}/${repo}.git`;
1111
}
1212

1313
/** Files touched in the working tree, from a simple-git StatusResult. */

0 commit comments

Comments
 (0)