Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: empty channelId in test environment #405

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bin/action.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -92976,7 +92976,6 @@ async function execWithCredentials(args, projectId, gacFilename, opts) {
}
return deployOutputBuf.length ? deployOutputBuf[deployOutputBuf.length - 1].toString("utf-8") : ""; // output from the CLI
}

async function deployPreview(gacFilename, deployConfig) {
const {
projectId,
Expand Down Expand Up @@ -93026,6 +93025,8 @@ function getChannelId(configuredChannelId, ghContext) {
} else if (ghContext.payload.pull_request) {
const branchName = ghContext.payload.pull_request.head.ref.substr(0, 20);
tmpChannelId = `pr${ghContext.payload.pull_request.number}-${branchName}`;
} else {
throw Error(`ChannelId is empty. No branch was found in the current context. Please provide a channelId for test environments.`);
}
// Channel IDs can only include letters, numbers, underscores, hyphens, and periods.
const invalidCharactersRegex = /[^a-zA-Z0-9_\-\.]/g;
Expand Down
5 changes: 5 additions & 0 deletions src/getChannelId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ export function getChannelId(configuredChannelId: string, ghContext: Context) {
} else if (ghContext.payload.pull_request) {
const branchName = ghContext.payload.pull_request.head.ref.substr(0, 20);
tmpChannelId = `pr${ghContext.payload.pull_request.number}-${branchName}`;
} else {
throw Error(
`ChannelId is empty. No branch was found in the current context. Please provide a channelId for test environments.`
);
}

// Channel IDs can only include letters, numbers, underscores, hyphens, and periods.
const invalidCharactersRegex = /[^a-zA-Z0-9_\-\.]/g;
const correctedChannelId = tmpChannelId.replace(invalidCharactersRegex, "_");

if (correctedChannelId !== tmpChannelId) {
console.log(
`ChannelId "${tmpChannelId}" contains unsupported characters. Using "${correctedChannelId}" instead.`
Expand Down