@@ -4,10 +4,14 @@ import { execFileSync } from 'child_process';
44export class Github {
55 repo : string ;
66 logger : LogType ;
7+ repoName : string ;
78
89 constructor ( repo : string , logger : LogType ) {
910 this . repo = repo ;
1011 this . logger = logger ;
12+ const [ org , repoName ] = repo . split ( '/' ) ;
13+ if ( org == null || repoName == null ) throw new Error ( `Badly formatted repo name: ${ repo } ` ) ;
14+ this . repoName = repoName ;
1115 }
1216
1317 /**
@@ -28,12 +32,12 @@ export class Github {
2832 getBranch ( branch : string ) : string {
2933 this . logger . info ( { branch } , 'GitHub: Get branch' ) ;
3034 try {
31- execFileSync ( 'git' , [ 'checkout' , branch ] , { cwd : this . repo } ) . toString ( ) . trim ( ) ;
35+ execFileSync ( 'git' , [ 'checkout' , branch ] , { cwd : this . repoName } ) . toString ( ) . trim ( ) ;
3236 this . logger . info ( { branch } , 'GitHub: Branch Checkout' ) ;
3337 return branch ;
3438 } catch {
3539 this . logger . info ( { branch } , 'GitHub: Create New Branch' ) ;
36- execFileSync ( 'git' , [ 'checkout' , '-b' , branch ] , { cwd : this . repo } ) . toString ( ) . trim ( ) ;
40+ execFileSync ( 'git' , [ 'checkout' , '-b' , branch ] , { cwd : this . repoName } ) . toString ( ) . trim ( ) ;
3741 return branch ;
3842 }
3943 }
@@ -46,9 +50,9 @@ export class Github {
4650 const email = Env . get ( 'GIT_USER_EMAIL' ) ?? 'basemaps@linz.govt.nz' ;
4751 const name = Env . get ( 'GIT_USER_NAME' ) ?? 'basemaps[bot]' ;
4852 this . logger . info ( { repository : this . repo } , 'GitHub: Config User Email' ) ;
49- execFileSync ( 'git' , [ 'config' , 'user.email' , email ] , { cwd : this . repo } ) . toString ( ) . trim ( ) ;
53+ execFileSync ( 'git' , [ 'config' , 'user.email' , email ] , { cwd : this . repoName } ) . toString ( ) . trim ( ) ;
5054 this . logger . info ( { repository : this . repo } , 'GitHub: Config User Name' ) ;
51- execFileSync ( 'git' , [ 'config' , 'user.name' , name ] , { cwd : this . repo } ) . toString ( ) . trim ( ) ;
55+ execFileSync ( 'git' , [ 'config' , 'user.name' , name ] , { cwd : this . repoName } ) . toString ( ) . trim ( ) ;
5256 }
5357
5458 /**
@@ -57,7 +61,7 @@ export class Github {
5761 */
5862 commit ( message : string ) : void {
5963 this . logger . info ( { repository : this . repo } , 'GitHub: Commit all' ) ;
60- execFileSync ( 'git' , [ 'commit' , '-am' , `"${ JSON . stringify ( message ) } "` ] , { cwd : this . repo } )
64+ execFileSync ( 'git' , [ 'commit' , '-am' , `"${ JSON . stringify ( message ) } "` ] , { cwd : this . repoName } )
6165 . toString ( )
6266 . trim ( ) ;
6367 }
@@ -68,6 +72,6 @@ export class Github {
6872 */
6973 push ( ) : void {
7074 this . logger . info ( { repository : this . repo } , 'GitHub: Push' ) ;
71- execFileSync ( 'git' , [ 'push' , 'origin' , 'HEAD' ] , { cwd : this . repo } ) . toString ( ) . trim ( ) ;
75+ execFileSync ( 'git' , [ 'push' , 'origin' , 'HEAD' ] , { cwd : this . repoName } ) . toString ( ) . trim ( ) ;
7276 }
7377}
0 commit comments