From 4d89a385db8421a90a755e655201bfbb8e037f7d Mon Sep 17 00:00:00 2001 From: Shohei Ueda <30958501+peaceiris@users.noreply.github.com> Date: Mon, 22 Jun 2020 05:40:26 +0900 Subject: [PATCH] chore: change printWidth from 80 to 100 (#362) --- .prettierrc.json | 2 +- __tests__/get-inputs.test.ts | 8 ++---- __tests__/git-utils.test.ts | 23 +++-------------- __tests__/set-tokens.test.ts | 28 +++++--------------- package.json | 2 +- src/get-inputs.ts | 9 +++---- src/git-utils.ts | 50 +++++++----------------------------- src/main.ts | 13 ++-------- src/set-tokens.ts | 20 +++------------ src/utils.ts | 5 +--- 10 files changed, 32 insertions(+), 128 deletions(-) diff --git a/.prettierrc.json b/.prettierrc.json index 0f75650..05b31a8 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,5 +1,5 @@ { - "printWidth": 80, + "printWidth": 100, "tabWidth": 2, "useTabs": false, "semi": true, diff --git a/__tests__/get-inputs.test.ts b/__tests__/get-inputs.test.ts index 648bc86..43d8e9b 100644 --- a/__tests__/get-inputs.test.ts +++ b/__tests__/get-inputs.test.ts @@ -9,9 +9,7 @@ beforeEach(() => { jest.resetModules(); process.stdout.write = jest.fn(); - const doc = yaml.safeLoad( - fs.readFileSync(__dirname + '/../action.yml', 'utf8') - ); + const doc = yaml.safeLoad(fs.readFileSync(__dirname + '/../action.yml', 'utf8')); Object.keys(doc.inputs).forEach(name => { const envVar = `INPUT_${name.replace(/ /g, '_').toUpperCase()}`; process.env[envVar] = doc.inputs[name]['default']; @@ -19,9 +17,7 @@ beforeEach(() => { }); afterEach(() => { - const doc = yaml.safeLoad( - fs.readFileSync(__dirname + '/../action.yml', 'utf8') - ); + const doc = yaml.safeLoad(fs.readFileSync(__dirname + '/../action.yml', 'utf8')); Object.keys(doc.inputs).forEach(name => { const envVar = `INPUT_${name.replace(/ /g, '_').toUpperCase()}`; console.debug(`delete ${envVar}\t${process.env[envVar]}`); diff --git a/__tests__/git-utils.test.ts b/__tests__/git-utils.test.ts index 5fd3af4..1cda5e4 100644 --- a/__tests__/git-utils.test.ts +++ b/__tests__/git-utils.test.ts @@ -1,9 +1,4 @@ -import { - getUserName, - getUserEmail, - setCommitAuthor, - getCommitMessage -} from '../src/git-utils'; +import {getUserName, getUserEmail, setCommitAuthor, getCommitMessage} from '../src/git-utils'; import {getWorkDirName, createWorkDir} from '../src/utils'; import {CmdResult} from '../src/interfaces'; import * as exec from '@actions/exec'; @@ -138,13 +133,7 @@ describe('getCommitMessage()', () => { }); test('get custom message', () => { - const test = getCommitMessage( - 'Custom msg', - '', - '', - 'actions/pages', - 'commit_hash' - ); + const test = getCommitMessage('Custom msg', '', '', 'actions/pages', 'commit_hash'); expect(test).toMatch('Custom msg commit_hash'); }); @@ -160,13 +149,7 @@ describe('getCommitMessage()', () => { }); test('get full custom message', () => { - const test = getCommitMessage( - '', - 'Full custom msg', - '', - 'actions/pages', - 'commit_hash' - ); + const test = getCommitMessage('', 'Full custom msg', '', 'actions/pages', 'commit_hash'); expect(test).toMatch('Full custom msg'); }); diff --git a/__tests__/set-tokens.test.ts b/__tests__/set-tokens.test.ts index 7780c92..1a7a743 100644 --- a/__tests__/set-tokens.test.ts +++ b/__tests__/set-tokens.test.ts @@ -1,8 +1,4 @@ -import { - getPublishRepo, - setPersonalToken, - setGithubToken -} from '../src/set-tokens'; +import {getPublishRepo, setPersonalToken, setGithubToken} from '../src/set-tokens'; beforeEach(() => { jest.resetModules(); @@ -26,8 +22,7 @@ describe('getPublishRepo()', () => { describe('setGithubToken()', () => { test('return remote url with GITHUB_TOKEN gh-pages', () => { - const expected = - 'https://x-access-token:GITHUB_TOKEN@github.com/owner/repo.git'; + const expected = 'https://x-access-token:GITHUB_TOKEN@github.com/owner/repo.git'; const test = setGithubToken( 'GITHUB_TOKEN', 'owner/repo', @@ -40,8 +35,7 @@ describe('setGithubToken()', () => { }); test('return remote url with GITHUB_TOKEN master', () => { - const expected = - 'https://x-access-token:GITHUB_TOKEN@github.com/owner/repo.git'; + const expected = 'https://x-access-token:GITHUB_TOKEN@github.com/owner/repo.git'; const test = setGithubToken( 'GITHUB_TOKEN', 'owner/repo', @@ -55,14 +49,7 @@ describe('setGithubToken()', () => { test('throw error master to master', () => { expect(() => { - setGithubToken( - 'GITHUB_TOKEN', - 'owner/repo', - 'master', - '', - 'refs/heads/master', - 'push' - ); + setGithubToken('GITHUB_TOKEN', 'owner/repo', 'master', '', 'refs/heads/master', 'push'); }).toThrowError('You deploy from master to master'); }); @@ -76,14 +63,11 @@ describe('setGithubToken()', () => { 'refs/heads/master', 'push' ); - }).toThrowError( - 'GITHUB_TOKEN does not support to push to an external repository' - ); + }).toThrowError('GITHUB_TOKEN does not support to push to an external repository'); }); test('return remote url with GITHUB_TOKEN pull_request', () => { - const expected = - 'https://x-access-token:GITHUB_TOKEN@github.com/owner/repo.git'; + const expected = 'https://x-access-token:GITHUB_TOKEN@github.com/owner/repo.git'; const test = setGithubToken( 'GITHUB_TOKEN', 'owner/repo', diff --git a/package.json b/package.json index 7b2f6b4..8a1cc8b 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ } }, "lint-staged": { - "src/**/*.ts": [ + "{src,__tests__}/**/*.ts": [ "prettier --check", "eslint" ], diff --git a/src/get-inputs.ts b/src/get-inputs.ts index 7eec4ba..1c4b5ac 100644 --- a/src/get-inputs.ts +++ b/src/get-inputs.ts @@ -53,12 +53,9 @@ export function getInputs(): Inputs { PublishBranch: core.getInput('publish_branch'), PublishDir: core.getInput('publish_dir'), ExternalRepository: core.getInput('external_repository'), - AllowEmptyCommit: - (core.getInput('allow_empty_commit') || 'false').toUpperCase() === 'TRUE', - KeepFiles: - (core.getInput('keep_files') || 'false').toUpperCase() === 'TRUE', - ForceOrphan: - (core.getInput('force_orphan') || 'false').toUpperCase() === 'TRUE', + AllowEmptyCommit: (core.getInput('allow_empty_commit') || 'false').toUpperCase() === 'TRUE', + KeepFiles: (core.getInput('keep_files') || 'false').toUpperCase() === 'TRUE', + ForceOrphan: (core.getInput('force_orphan') || 'false').toUpperCase() === 'TRUE', UserName: core.getInput('user_name'), UserEmail: core.getInput('user_email'), CommitMessage: core.getInput('commit_message'), diff --git a/src/git-utils.ts b/src/git-utils.ts index 3e45873..513bb84 100644 --- a/src/git-utils.ts +++ b/src/git-utils.ts @@ -12,10 +12,7 @@ export async function createBranchForce(branch: string): Promise { return; } -export async function copyAssets( - publishDir: string, - workDir: string -): Promise { +export async function copyAssets(publishDir: string, workDir: string): Promise { const copyOpts = {recursive: true, force: true}; const files = fs.readdirSync(publishDir); core.debug(`${files}`); @@ -31,15 +28,8 @@ export async function copyAssets( return; } -export async function setRepo( - inps: Inputs, - remoteURL: string, - workDir: string -): Promise { - const publishDir = path.join( - `${process.env.GITHUB_WORKSPACE}`, - inps.PublishDir - ); +export async function setRepo(inps: Inputs, remoteURL: string, workDir: string): Promise { + const publishDir = path.join(`${process.env.GITHUB_WORKSPACE}`, inps.PublishDir); core.info(`[INFO] ForceOrphan: ${inps.ForceOrphan}`); if (inps.ForceOrphan) { @@ -65,15 +55,7 @@ export async function setRepo( try { result.exitcode = await exec.exec( 'git', - [ - 'clone', - '--depth=1', - '--single-branch', - '--branch', - inps.PublishBranch, - remoteURL, - workDir - ], + ['clone', '--depth=1', '--single-branch', '--branch', inps.PublishBranch, remoteURL, workDir], options ); if (result.exitcode === 0) { @@ -90,9 +72,7 @@ export async function setRepo( throw new Error(`Failed to clone remote branch ${inps.PublishBranch}`); } } catch (e) { - core.info( - `[INFO] first deployment, create new branch ${inps.PublishBranch}` - ); + core.info(`[INFO] first deployment, create new branch ${inps.PublishBranch}`); core.info(e.message); await createWorkDir(workDir); process.chdir(workDir); @@ -118,10 +98,7 @@ export function getUserEmail(userEmail: string): string { } } -export async function setCommitAuthor( - userName: string, - userEmail: string -): Promise { +export async function setCommitAuthor(userName: string, userEmail: string): Promise { if (userName && !userEmail) { throw new Error('user_email is undefined'); } @@ -160,10 +137,7 @@ export function getCommitMessage( return subject; } -export async function commit( - allowEmptyCommit: boolean, - msg: string -): Promise { +export async function commit(allowEmptyCommit: boolean, msg: string): Promise { try { if (allowEmptyCommit) { await exec.exec('git', ['commit', '--allow-empty', '-m', `${msg}`]); @@ -176,10 +150,7 @@ export async function commit( } } -export async function push( - branch: string, - forceOrphan: boolean -): Promise { +export async function push(branch: string, forceOrphan: boolean): Promise { if (forceOrphan) { await exec.exec('git', ['push', 'origin', '--force', branch]); } else { @@ -187,10 +158,7 @@ export async function push( } } -export async function pushTag( - tagName: string, - tagMessage: string -): Promise { +export async function pushTag(tagName: string, tagMessage: string): Promise { if (tagName === '') { return; } diff --git a/src/main.ts b/src/main.ts index e9e965c..2688531 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,14 +5,7 @@ import * as github from '@actions/github'; import {Inputs} from './interfaces'; import {showInputs, getInputs} from './get-inputs'; import {setTokens} from './set-tokens'; -import { - setRepo, - setCommitAuthor, - getCommitMessage, - commit, - push, - pushTag -} from './git-utils'; +import {setRepo, setCommitAuthor, getCommitMessage, commit, push, pushTag} from './git-utils'; import {getWorkDirName, addNoJekyll, addCNAME, skipOnFork} from './utils'; export async function run(): Promise { @@ -39,9 +32,7 @@ export async function run(): Promise { inps.PersonalToken ); if (isSkipOnFork) { - core.warning( - 'This action runs on a fork and not found auth token, Skip deployment' - ); + core.warning('This action runs on a fork and not found auth token, Skip deployment'); core.setOutput('skip', 'true'); return; } diff --git a/src/set-tokens.ts b/src/set-tokens.ts index f9d9219..bbb397f 100644 --- a/src/set-tokens.ts +++ b/src/set-tokens.ts @@ -9,10 +9,7 @@ const cpexec = require('child_process').execFileSync; import {Inputs} from './interfaces'; import {getHomeDir} from './utils'; -export async function setSSHKey( - inps: Inputs, - publishRepo: string -): Promise { +export async function setSSHKey(inps: Inputs, publishRepo: string): Promise { core.info('[INFO] setup SSH deploy key'); const homeDir = await getHomeDir(); @@ -81,27 +78,18 @@ export function setGithubToken( } if (externalRepository) { - throw new Error( - 'GITHUB_TOKEN does not support to push to an external repository' - ); + throw new Error('GITHUB_TOKEN does not support to push to an external repository'); } return `https://x-access-token:${githubToken}@github.com/${publishRepo}.git`; } -export function setPersonalToken( - personalToken: string, - publishRepo: string -): string { +export function setPersonalToken(personalToken: string, publishRepo: string): string { core.info('[INFO] setup personal access token'); return `https://x-access-token:${personalToken}@github.com/${publishRepo}.git`; } -export function getPublishRepo( - externalRepository: string, - owner: string, - repo: string -): string { +export function getPublishRepo(externalRepository: string, owner: string, repo: string): string { if (externalRepository) { return externalRepository; } diff --git a/src/utils.ts b/src/utils.ts index 433fe8c..7a1d8d1 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -47,10 +47,7 @@ export async function addNoJekyll( } } -export async function addCNAME( - workDir: string, - content: string -): Promise { +export async function addCNAME(workDir: string, content: string): Promise { if (content === '') { return; }