mirror of
https://github.com/shimataro/ssh-key-action.git
synced 2025-06-19 22:52:10 +10:00
Change code style to 1TBS
This commit is contained in:
parent
b38d88da8a
commit
37d0a89301
4 changed files with 186 additions and 207 deletions
|
@ -25,6 +25,13 @@ spaces_around_brackets = none
|
|||
indent_brace_style = allman
|
||||
|
||||
|
||||
# JavaScript/TypeScript
|
||||
[*.{js,ts}]
|
||||
indent_style = space
|
||||
curly_bracket_next_line = false
|
||||
indent_brace_style = K&R
|
||||
|
||||
|
||||
# JSON/YAML
|
||||
[*.{json,babelrc,code-workspace,yml,yaml}]
|
||||
indent_style = space
|
||||
|
|
|
@ -31,7 +31,7 @@ rules: # https://eslint.org/docs/rules/
|
|||
block-spacing: error
|
||||
brace-style:
|
||||
- error
|
||||
- allman
|
||||
- 1tbs
|
||||
callback-return: error
|
||||
capitalized-comments: 'off'
|
||||
class-methods-use-this: error
|
||||
|
@ -87,26 +87,14 @@ rules: # https://eslint.org/docs/rules/
|
|||
- below
|
||||
indent:
|
||||
- error
|
||||
- tab
|
||||
- 4
|
||||
- SwitchCase: 1
|
||||
indent-legacy: 'off'
|
||||
init-declarations: error
|
||||
jsx-quotes: error
|
||||
key-spacing: error
|
||||
keyword-spacing:
|
||||
- error
|
||||
- overrides:
|
||||
catch:
|
||||
after: false
|
||||
for:
|
||||
after: false
|
||||
if:
|
||||
after: false
|
||||
switch:
|
||||
after: false
|
||||
while:
|
||||
after: false
|
||||
with:
|
||||
after: false
|
||||
line-comment-position: 'off'
|
||||
linebreak-style:
|
||||
- error
|
||||
|
@ -309,6 +297,7 @@ rules: # https://eslint.org/docs/rules/
|
|||
# @typescript-eslint plugin
|
||||
"@typescript-eslint/ban-ts-ignore": 'off'
|
||||
"@typescript-eslint/no-empty-interface": 'off'
|
||||
"@typescript-eslint/no-floating-promises": error
|
||||
"@typescript-eslint/no-use-before-define":
|
||||
- error
|
||||
- functions: false
|
||||
|
|
14
lib/index.js
14
lib/index.js
|
@ -590,7 +590,6 @@ __nccwpck_require__.r(__webpack_exports__);
|
|||
* main function
|
||||
*/
|
||||
function main() {
|
||||
try {
|
||||
// parameters
|
||||
const key = _actions_core__WEBPACK_IMPORTED_MODULE_2__.getInput("key", {
|
||||
required: true,
|
||||
|
@ -646,10 +645,6 @@ function main() {
|
|||
fs__WEBPACK_IMPORTED_MODULE_0___default().writeFileSync(fileName, file.contents, file.options);
|
||||
}
|
||||
console.log(`SSH key has been stored to ${dirName} successfully.`);
|
||||
}
|
||||
catch (err) {
|
||||
_actions_core__WEBPACK_IMPORTED_MODULE_2__.setFailed(err.message);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* get home directory
|
||||
|
@ -724,7 +719,14 @@ function shouldCreateKeyFile(keyFilePath, ifKeyExists) {
|
|||
throw new Error(`SSH key is already installed. Set "if_key_exists" to "replace" or "ignore" in order to avoid this error.`);
|
||||
}
|
||||
}
|
||||
main();
|
||||
try {
|
||||
main();
|
||||
}
|
||||
catch (err) {
|
||||
if (err instanceof Error) {
|
||||
_actions_core__WEBPACK_IMPORTED_MODULE_2__.setFailed(err);
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
|
|
69
src/main.ts
69
src/main.ts
|
@ -3,8 +3,7 @@ import path from "path";
|
|||
|
||||
import * as core from "@actions/core";
|
||||
|
||||
interface FileInfo
|
||||
{
|
||||
interface FileInfo {
|
||||
name: string;
|
||||
contents: string;
|
||||
options: fs.WriteFileOptions;
|
||||
|
@ -13,10 +12,7 @@ interface FileInfo
|
|||
/**
|
||||
* main function
|
||||
*/
|
||||
function main(): void
|
||||
{
|
||||
try
|
||||
{
|
||||
function main(): void {
|
||||
// parameters
|
||||
const key = core.getInput("key", {
|
||||
required: true,
|
||||
|
@ -38,8 +34,7 @@ function main(): void
|
|||
|
||||
// files to be created
|
||||
const files: FileInfo[] = [];
|
||||
if(shouldCreateKeyFile(path.join(dirName, name), ifKeyExists))
|
||||
{
|
||||
if (shouldCreateKeyFile(path.join(dirName, name), ifKeyExists)) {
|
||||
files.push({
|
||||
name: name,
|
||||
contents: insertLf(key, false, true),
|
||||
|
@ -49,8 +44,7 @@ function main(): void
|
|||
},
|
||||
});
|
||||
}
|
||||
if(knownHosts !== "unnecessary")
|
||||
{
|
||||
if (knownHosts !== "unnecessary") {
|
||||
files.push({
|
||||
name: "known_hosts",
|
||||
contents: insertLf(knownHosts, true, true),
|
||||
|
@ -60,8 +54,7 @@ function main(): void
|
|||
},
|
||||
});
|
||||
}
|
||||
if(config !== "")
|
||||
{
|
||||
if (config !== "") {
|
||||
files.push({
|
||||
name: "config",
|
||||
contents: insertLf(config, true, true),
|
||||
|
@ -73,35 +66,26 @@ function main(): void
|
|||
}
|
||||
|
||||
// create files
|
||||
for(const file of files)
|
||||
{
|
||||
for (const file of files) {
|
||||
const fileName = path.join(dirName, file.name);
|
||||
fs.writeFileSync(fileName, file.contents, file.options);
|
||||
}
|
||||
|
||||
console.log(`SSH key has been stored to ${dirName} successfully.`);
|
||||
}
|
||||
catch(err)
|
||||
{
|
||||
core.setFailed(err.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get home directory
|
||||
* @returns home directory
|
||||
*/
|
||||
function getHomeDirectory(): string
|
||||
{
|
||||
function getHomeDirectory(): string {
|
||||
const homeEnv = getHomeEnv();
|
||||
const home = process.env[homeEnv];
|
||||
if(home === undefined)
|
||||
{
|
||||
if (home === undefined) {
|
||||
throw Error(`${homeEnv} is not defined`);
|
||||
}
|
||||
|
||||
if(home === "/github/home")
|
||||
{
|
||||
if (home === "/github/home") {
|
||||
// Docker container
|
||||
return "/root";
|
||||
}
|
||||
|
@ -113,10 +97,8 @@ function getHomeDirectory(): string
|
|||
* get HOME environment name
|
||||
* @returns HOME environment name
|
||||
*/
|
||||
function getHomeEnv(): string
|
||||
{
|
||||
if(process.platform === "win32")
|
||||
{
|
||||
function getHomeEnv(): string {
|
||||
if (process.platform === "win32") {
|
||||
// Windows
|
||||
return "USERPROFILE";
|
||||
}
|
||||
|
@ -132,21 +114,17 @@ function getHomeEnv(): string
|
|||
* @param append true to append
|
||||
* @returns new value
|
||||
*/
|
||||
function insertLf(value: string, prepend: boolean, append: boolean): string
|
||||
{
|
||||
function insertLf(value: string, prepend: boolean, append: boolean): string {
|
||||
let affectedValue = value;
|
||||
|
||||
if(value.length === 0)
|
||||
{
|
||||
if (value.length === 0) {
|
||||
// do nothing if empty
|
||||
return "";
|
||||
}
|
||||
if(prepend && !affectedValue.startsWith("\n"))
|
||||
{
|
||||
if (prepend && !affectedValue.startsWith("\n")) {
|
||||
affectedValue = `\n${affectedValue}`;
|
||||
}
|
||||
if(append && !affectedValue.endsWith("\n"))
|
||||
{
|
||||
if (append && !affectedValue.endsWith("\n")) {
|
||||
affectedValue = `${affectedValue}\n`;
|
||||
}
|
||||
|
||||
|
@ -159,16 +137,13 @@ function insertLf(value: string, prepend: boolean, append: boolean): string
|
|||
* @param ifKeyExists action if SSH key exists
|
||||
* @returns Yes/No
|
||||
*/
|
||||
function shouldCreateKeyFile(keyFilePath: string, ifKeyExists: string): boolean
|
||||
{
|
||||
if(!fs.existsSync(keyFilePath))
|
||||
{
|
||||
function shouldCreateKeyFile(keyFilePath: string, ifKeyExists: string): boolean {
|
||||
if (!fs.existsSync(keyFilePath)) {
|
||||
// should create if file does not exist
|
||||
return true;
|
||||
}
|
||||
|
||||
switch(ifKeyExists)
|
||||
{
|
||||
switch (ifKeyExists) {
|
||||
case "replace":
|
||||
// remove file and should create if replace
|
||||
fs.unlinkSync(keyFilePath);
|
||||
|
@ -184,4 +159,10 @@ function shouldCreateKeyFile(keyFilePath: string, ifKeyExists: string): boolean
|
|||
}
|
||||
}
|
||||
|
||||
main();
|
||||
try {
|
||||
main();
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
core.setFailed(err);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue