Skip to content

Commit 6b395b8

Browse files
authored
fix(cli): Fix remove the ref from the repository and get the repo name from it. (#2784)
* Fix remove the ref from the repository and get the repo name from it. * Split the orgs and repo name * Assign the repo name * Should throw a error.
1 parent 46abe7d commit 6b395b8

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

packages/cli/src/cli/github/github.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import { execFileSync } from 'child_process';
44
export 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
}

packages/cli/src/cli/github/make.cog.pr.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class MakeCogGithub extends Github {
2222

2323
// Prepare new aerial tileset config
2424
this.logger.info({ imagery: this.imagery }, 'GitHub: Get the master TileSet config file');
25-
const path = `${this.repo}/config/tileset/${filename}.json`;
25+
const path = `${this.repoName}/config/tileset/${filename}.json`;
2626
const tileSet = await fsa.readJson<ConfigTileSetRaster>(path);
2727
const newTileSet = await this.prepareRasterTileSetConfig(layer, tileSet, category);
2828

@@ -116,7 +116,7 @@ export class MakeCogGithub extends Github {
116116

117117
// Prepare new aerial tileset config
118118
this.logger.info({ imagery: this.imagery }, 'GitHub: Get the master TileSet config file');
119-
const path = `${this.repo}/config/tileset/${filename}.json`;
119+
const path = `${this.repoName}/config/tileset/${filename}.json`;
120120
const tileSet = await fsa.readJson<ConfigTileSetVector>(path);
121121
const newTileSet = await this.prepareVectorTileSetConfig(layer, tileSet);
122122

0 commit comments

Comments
 (0)