Skip to content

Commit 5f0f8b3

Browse files
committed
fix: reverted github pem auth
1 parent 44c3341 commit 5f0f8b3

5 files changed

Lines changed: 32 additions & 9 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ logs/
2626

2727
# isolated, project-local Hermes home (config/credentials/sessions/state)
2828
.hermes/
29+
30+
# generated files
31+
api/prisma/dev.db

api/src/orchestrator/orchestrator.service.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export class OrchestratorService {
8484
});
8585
await this.queue.enqueue({ jobId: job.id, kind: 'PLAN' });
8686
const ref = this.refFor(job, installation);
87-
await this.github.createIssueReaction(ref, evt.issueNumber, 'eyes');
87+
await this.safeReaction(ref, evt.issueNumber, 'eyes');
8888
await this.safeComment(
8989
ref,
9090
evt.issueNumber,
@@ -656,4 +656,16 @@ export class OrchestratorService {
656656
this.logger.warn(`failed to post comment: ${(e as Error).message}`);
657657
}
658658
}
659+
660+
private async safeReaction(
661+
ref: RepoRef,
662+
issueNumber: number,
663+
content: Parameters<GithubService['createIssueReaction']>[2],
664+
): Promise<void> {
665+
try {
666+
await this.github.createIssueReaction(ref, issueNumber, content);
667+
} catch (e) {
668+
this.logger.warn(`failed to add reaction: ${(e as Error).message}`);
669+
}
670+
}
659671
}

api/src/workspace/workspace.module.ts

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

45
@Module({
5-
imports: [],
6+
imports: [GithubModule],
67
providers: [WorkspaceService],
78
exports: [WorkspaceService],
89
})

api/src/workspace/workspace.service.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ 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';
78
import { type DiffSummary, type Workspace, type WorkspacePrepareInput } from './workspace.model.js';
89
import {
9-
sshRemoteUrl,
10+
authenticatedRemoteUrl,
1011
changedFilesFromStatus,
1112
workspaceDir,
1213
} from './workspace.utility.js';
@@ -20,13 +21,17 @@ import {
2021
export class WorkspaceService {
2122
private readonly logger = new Logger(WorkspaceService.name);
2223

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

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

3136
if (existsSync(`${dir}/.git`)) {
3237
const git = simpleGit(dir);
@@ -81,11 +86,13 @@ export class WorkspaceService {
8186
return (await git.revparse(['HEAD'])).trim();
8287
}
8388

84-
/** Push the job branch using the host machine's SSH credentials. */
89+
/** Push the job branch, refreshing the remote token first (tokens expire ~1h). */
8590
async push(input: WorkspacePrepareInput): Promise<string> {
8691
const root = this.config.get('WORKSPACE_ROOT');
8792
const dir = workspaceDir(root, input.jobId);
8893
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)]);
8996
await git.push(['-u', 'origin', input.branchName]);
9097
const sha = (await git.revparse(['HEAD'])).trim();
9198
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-
/** 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`;
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`;
1111
}
1212

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

0 commit comments

Comments
 (0)