Skip to content

Commit

Permalink
chore: change printWidth from 80 to 100 (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceiris authored Jun 21, 2020
1 parent b6801e6 commit 4d89a38
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 128 deletions.
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"printWidth": 80,
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"semi": true,
Expand Down
8 changes: 2 additions & 6 deletions __tests__/get-inputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@ 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'];
});
});

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]}`);
Expand Down
23 changes: 3 additions & 20 deletions __tests__/git-utils.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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');
});

Expand All @@ -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');
});

Expand Down
28 changes: 6 additions & 22 deletions __tests__/set-tokens.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
getPublishRepo,
setPersonalToken,
setGithubToken
} from '../src/set-tokens';
import {getPublishRepo, setPersonalToken, setGithubToken} from '../src/set-tokens';

beforeEach(() => {
jest.resetModules();
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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');
});

Expand All @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
}
},
"lint-staged": {
"src/**/*.ts": [
"{src,__tests__}/**/*.ts": [
"prettier --check",
"eslint"
],
Expand Down
9 changes: 3 additions & 6 deletions src/get-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
50 changes: 9 additions & 41 deletions src/git-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ export async function createBranchForce(branch: string): Promise<void> {
return;
}

export async function copyAssets(
publishDir: string,
workDir: string
): Promise<void> {
export async function copyAssets(publishDir: string, workDir: string): Promise<void> {
const copyOpts = {recursive: true, force: true};
const files = fs.readdirSync(publishDir);
core.debug(`${files}`);
Expand All @@ -31,15 +28,8 @@ export async function copyAssets(
return;
}

export async function setRepo(
inps: Inputs,
remoteURL: string,
workDir: string
): Promise<void> {
const publishDir = path.join(
`${process.env.GITHUB_WORKSPACE}`,
inps.PublishDir
);
export async function setRepo(inps: Inputs, remoteURL: string, workDir: string): Promise<void> {
const publishDir = path.join(`${process.env.GITHUB_WORKSPACE}`, inps.PublishDir);

core.info(`[INFO] ForceOrphan: ${inps.ForceOrphan}`);
if (inps.ForceOrphan) {
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -118,10 +98,7 @@ export function getUserEmail(userEmail: string): string {
}
}

export async function setCommitAuthor(
userName: string,
userEmail: string
): Promise<void> {
export async function setCommitAuthor(userName: string, userEmail: string): Promise<void> {
if (userName && !userEmail) {
throw new Error('user_email is undefined');
}
Expand Down Expand Up @@ -160,10 +137,7 @@ export function getCommitMessage(
return subject;
}

export async function commit(
allowEmptyCommit: boolean,
msg: string
): Promise<void> {
export async function commit(allowEmptyCommit: boolean, msg: string): Promise<void> {
try {
if (allowEmptyCommit) {
await exec.exec('git', ['commit', '--allow-empty', '-m', `${msg}`]);
Expand All @@ -176,21 +150,15 @@ export async function commit(
}
}

export async function push(
branch: string,
forceOrphan: boolean
): Promise<void> {
export async function push(branch: string, forceOrphan: boolean): Promise<void> {
if (forceOrphan) {
await exec.exec('git', ['push', 'origin', '--force', branch]);
} else {
await exec.exec('git', ['push', 'origin', branch]);
}
}

export async function pushTag(
tagName: string,
tagMessage: string
): Promise<void> {
export async function pushTag(tagName: string, tagMessage: string): Promise<void> {
if (tagName === '') {
return;
}
Expand Down
13 changes: 2 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand All @@ -39,9 +32,7 @@ export async function run(): Promise<void> {
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;
}
Expand Down
20 changes: 4 additions & 16 deletions src/set-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
export async function setSSHKey(inps: Inputs, publishRepo: string): Promise<string> {
core.info('[INFO] setup SSH deploy key');

const homeDir = await getHomeDir();
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 1 addition & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ export async function addNoJekyll(
}
}

export async function addCNAME(
workDir: string,
content: string
): Promise<void> {
export async function addCNAME(workDir: string, content: string): Promise<void> {
if (content === '') {
return;
}
Expand Down

0 comments on commit 4d89a38

Please sign in to comment.