github-pages-deploy-action/lib/util.js
James Ives 71b19fd2fb
Package Exporting (#181)
* Corrects exporting

* README Changes

* Forgot the compiled code.

* Configuration changes

* Moving action package

* Update README.md

* Update README.md

* Improving example

* Update README.md

* Update src/lib.ts

Co-Authored-By: XAMPPRocky <4464295+XAMPPRocky@users.noreply.github.com>

* Correctly building types

* Update README.md

* Configuration update

* Update README.md

* Re-assigning

* Missing chnage

* More changes

* Some more information

* Setting changes to repositoryPath and tokenType

* Compiling

* Update package.json

* Token hiding

* Package Exporting Changes (#185)

* Initiial Changes

* Changes to action

* Compiled

* Added better logging for when debug is off...

* Removing base branch logging as it's not really required

* throw new Error -> throw

* Debug flag as an variable

* Update README.md

* More README Changes

* Update README.md

* Update README.md

* Update README.md

* error.message

* Fixes the debug flag

* Changing the directory routing for shell scripting

* Tidying!

* Changing to const

* Promotion

Co-authored-by: XAMPPRocky <4464295+XAMPPRocky@users.noreply.github.com>
2020-03-02 07:52:38 -05:00

55 lines
2.5 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@actions/core");
/* Utility function that checks to see if a value is undefined or not. */
exports.isNullOrUndefined = (value) => typeof value === "undefined" || value === null || value === "";
/* Generates a token type used for the action. */
exports.generateTokenType = (action) => action.ssh
? "SSH Deploy Key"
: action.accessToken
? "Access Token"
: action.gitHubToken
? "GitHub Token"
: "...";
/* Generates a the repository path used to make the commits. */
exports.generateRepositoryPath = (action) => action.ssh
? `git@github.com:${action.gitHubRepository}`
: `https://${action.accessToken ||
`x-access-token:${action.gitHubToken}`}@github.com/${action.gitHubRepository}.git`;
/* Checks for the required tokens and formatting. Throws an error if any case is matched. */
exports.hasRequiredParameters = (action) => {
if ((exports.isNullOrUndefined(action.accessToken) &&
exports.isNullOrUndefined(action.gitHubToken) &&
exports.isNullOrUndefined(action.ssh)) ||
exports.isNullOrUndefined(action.repositoryPath)) {
throw new Error("No deployment token/method was provided. You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy. If you wish to use an ssh deploy token then you must set SSH to true.");
}
if (exports.isNullOrUndefined(action.branch)) {
throw new Error("Branch is required.");
}
if (!action.folder || exports.isNullOrUndefined(action.folder)) {
throw new Error("You must provide the action with a folder to deploy.");
}
if (action.folder.startsWith("/") || action.folder.startsWith("./")) {
throw new Error("Incorrectly formatted build folder. The deployment folder cannot be prefixed with '/' or './'. Instead reference the folder name directly.");
}
};
/* Suppresses sensitive information from being exposed in error messages. */
exports.suppressSensitiveInformation = (str, action) => {
let value = str;
if (core_1.getInput("DEBUG")) {
// Data is unmasked in debug mode.
return value;
}
if (action.accessToken) {
value = value.replace(action.accessToken, "***");
}
if (action.gitHubToken) {
value = value.replace(action.gitHubToken, "***");
}
if (action.repositoryPath) {
value = value.replace(action.repositoryPath, "***");
}
return value;
};