Skip to content

Commit bb16864

Browse files
committed
Fix invalid url when being referenced by project id alias
Closes FirebaseExtended#213
1 parent 25a9b83 commit bb16864

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

bin/action.min.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93151,6 +93151,17 @@ async function postChannelSuccessComment(github, context, result, commit) {
9315193151
core.endGroup();
9315293152
}
9315393153

93154+
function getProjectIdByAlias(alias) {
93155+
try {
93156+
const firebaserc = JSON.parse(fs.readFileSync(".firebaserc", {
93157+
encoding: 'utf-8'
93158+
}));
93159+
return firebaserc.projects[alias];
93160+
} catch (e) {
93161+
return undefined;
93162+
}
93163+
}
93164+
9315493165
/**
9315593166
* Copyright 2020 Google LLC
9315693167
*
@@ -93216,7 +93227,9 @@ async function run() {
9321693227
throw Error(deployment.error);
9321793228
}
9321893229
core.endGroup();
93219-
const hostname = target ? `${target}.web.app` : `${projectId}.web.app`;
93230+
// Try to get the project id from an project alias
93231+
const parsedProjectId = getProjectIdByAlias(projectId) || projectId;
93232+
const hostname = target ? `${target}.web.app` : `${parsedProjectId}.web.app`;
9322093233
const url = `https://${hostname}/`;
9322193234
await finish({
9322293235
details_url: url,

src/getProjectIdByAlias.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { readFileSync } from "fs";
22

33
export function getProjectIdByAlias(alias: string): string {
4-
const firebaserc = JSON.parse(readFileSync(".firebaserc", { encoding: 'utf-8' }));
5-
return firebaserc.projects[alias];
4+
try {
5+
const firebaserc = JSON.parse(readFileSync(".firebaserc", { encoding: 'utf-8' }));
6+
return firebaserc.projects[alias];
7+
} catch (e) {
8+
return undefined;
9+
}
610
}

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ async function run() {
100100
}
101101
endGroup();
102102

103+
// Try to get the project id from an project alias
103104
const parsedProjectId = getProjectIdByAlias(projectId) || projectId;
104105
const hostname = target ? `${target}.web.app` : `${parsedProjectId}.web.app`;
105106
const url = `https://${hostname}/`;
107+
106108
await finish({
107109
details_url: url,
108110
conclusion: "success",

0 commit comments

Comments
 (0)