@@ -4,10 +4,9 @@ import { mkdir, rm } from 'node:fs/promises';
44import { Injectable , Logger } from '@nestjs/common' ;
55import { simpleGit , type SimpleGit } from 'simple-git' ;
66import { AppConfigService } from '../config/config.service.js' ;
7- import { GithubService } from '../github/github.service.js' ;
87import { type DiffSummary , type Workspace , type WorkspacePrepareInput } from './workspace.model.js' ;
98import {
10- authenticatedRemoteUrl ,
9+ sshRemoteUrl ,
1110 changedFilesFromStatus ,
1211 workspaceDir ,
1312} from './workspace.utility.js' ;
@@ -21,17 +20,13 @@ import {
2120export 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 } ` ) ;
0 commit comments