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

feat(gha): github app name update #44

Merged
merged 1 commit into from
Oct 8, 2024
Merged
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
2 changes: 1 addition & 1 deletion setup-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ inputs:
github-app:
description: 'BrowserStack Github App'
required: false
default: 'browserstack[bot]'
default: 'browserstack-integrations[bot]'
runs:
using: 'node20'
main: 'dist/index.js'
9 changes: 5 additions & 4 deletions setup-env/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9597,18 +9597,19 @@ class InputValidator {

/**
* Validates the app name input to ensure it is a valid non-empty string.
* If the input is 'none' or not provided, it returns 'browserstack[bot]'.
* If the input is 'none' or not provided, it returns 'browserstack-integrations[bot]'.
* @param {string} githubAppName Input for 'github-app'
* @returns {string} Validated app name, or 'browserstack[bot]' if input is 'none' or invalid
* @returns {string} Validated app name, or 'browserstack-integrations[bot]'
* if input is 'none' or invalid
* @throws {Error} If the input is not a valid non-empty string
*/
static validateGithubAppName(githubAppName) {
if (typeof githubAppName !== 'string') {
throw new Error("Invalid input for 'github-app'. Must be a valid string.");
}

if (githubAppName.toLowerCase() === 'browserstack[bot]') {
return 'browserstack[bot]';
if (githubAppName.toLowerCase() === 'browserstack-integrations[bot]') {
return 'browserstack-integrations[bot]';
}

if (githubAppName.trim().length > 0) {
Expand Down
9 changes: 5 additions & 4 deletions setup-env/src/actionInput/inputValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,19 @@ class InputValidator {

/**
* Validates the app name input to ensure it is a valid non-empty string.
* If the input is 'none' or not provided, it returns 'browserstack[bot]'.
* If the input is 'none' or not provided, it returns 'browserstack-integrations[bot]'.
* @param {string} githubAppName Input for 'github-app'
* @returns {string} Validated app name, or 'browserstack[bot]' if input is 'none' or invalid
* @returns {string} Validated app name, or 'browserstack-integrations[bot]'
* if input is 'none' or invalid
* @throws {Error} If the input is not a valid non-empty string
*/
static validateGithubAppName(githubAppName) {
if (typeof githubAppName !== 'string') {
throw new Error("Invalid input for 'github-app'. Must be a valid string.");
}

if (githubAppName.toLowerCase() === 'browserstack[bot]') {
return 'browserstack[bot]';
if (githubAppName.toLowerCase() === 'browserstack-integrations[bot]') {
return 'browserstack-integrations[bot]';
}

if (githubAppName.trim().length > 0) {
Expand Down
8 changes: 4 additions & 4 deletions setup-env/test/actionInput/inputValidator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ describe('InputValidator class to validate individual fields of the action input
});

context('Validates GitHub App Name', () => {
it("Returns 'browserstack[bot]' if the app name is not provided", () => {
it("Returns 'browserstack-integrations[bot]' if the app name is not provided", () => {
expect(() => InputValidator.validateGithubAppName()).to.throw("Invalid input for 'github-app'. Must be a valid string.");
});

it("Returns 'browserstack[bot]' if the app name is 'browserstack[bot]' (case insensitive)", () => {
expect(InputValidator.validateGithubAppName('BrowserStack[BOT]')).to.eq('browserstack[bot]');
it("Returns 'browserstack-integrations[bot]' if the app name is 'browserstack-integrations[bot]' (case insensitive)", () => {
expect(InputValidator.validateGithubAppName('BrowserStack-integrations[BOT]')).to.eq('browserstack-integrations[bot]');
});

it('Throws an error if the app name is an empty string', () => {
Expand All @@ -170,7 +170,7 @@ describe('InputValidator class to validate individual fields of the action input
expect(() => InputValidator.validateGithubAppName(123)).to.throw("Invalid input for 'github-app'. Must be a valid string.");
});

it('Returns the app name if it is a valid non-empty string and not "browserstack[bot]"', () => {
it('Returns the app name if it is a valid non-empty string and not "browserstack-integrations[bot]"', () => {
const validAppName = 'someValidAppName';
expect(InputValidator.validateGithubAppName(validAppName)).to.eq(validAppName);
});
Expand Down
Loading