Skip to content

Commit 235cf3a

Browse files
committed
Fix invalid url when being referenced by project id alias
Closes FirebaseExtended#213
1 parent 120e124 commit 235cf3a

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { readFileSync } from "fs";
2+
3+
export function getProjectIdByAlias(alias: string): string {
4+
try {
5+
const firebaserc = JSON.parse(readFileSync(".firebaserc", { encoding: 'utf-8' }));
6+
return firebaserc.projects[alias];
7+
} catch (e) {
8+
return undefined;
9+
}
10+
}

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
getURLsMarkdownFromChannelDeployResult,
3737
postChannelSuccessComment,
3838
} from "./postOrUpdateComment";
39+
import { getProjectIdByAlias } from "./getProjectIdByAlias";
3940

4041
// Inputs defined in action.yml
4142
const expires = getInput("expires");
@@ -99,8 +100,11 @@ async function run() {
99100
}
100101
endGroup();
101102

102-
const hostname = target ? `${target}.web.app` : `${projectId}.web.app`;
103+
// Try to get the project id from an project alias
104+
const parsedProjectId = getProjectIdByAlias(projectId) || projectId;
105+
const hostname = target ? `${target}.web.app` : `${parsedProjectId}.web.app`;
103106
const url = `https://${hostname}/`;
107+
104108
await finish({
105109
details_url: url,
106110
conclusion: "success",

0 commit comments

Comments
 (0)