Skip to content

Commit fcc1888

Browse files
committed
refactor: rename variable, function, interface
1 parent f0c5057 commit fcc1888

File tree

3 files changed

+36
-40
lines changed

3 files changed

+36
-40
lines changed

__tests__/index.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import * as cp from 'child_process'
2-
import * as path from 'path'
1+
import { execSync } from 'child_process'
2+
import path from 'path'
33
import dotenv from 'dotenv'
4-
import { getInputs } from '../src/inputs'
4+
import { getInput } from '../src/inputs'
55

66
test('input', () => {
7-
process.env.INPUT_GIST_ID = 'test_gist_id'
8-
process.env.INPUT_GIST_FILE_NAME = 'test_gist_file_name'
9-
process.env.INPUT_FILE_PATH = 'test_file_path'
7+
process.env.INPUT_GIST_ID = 'gist_id'
8+
process.env.INPUT_GIST_FILE_NAME = 'gist_file_name'
9+
process.env.INPUT_FILE_PATH = 'file_path'
1010

11-
const inp = getInputs()
11+
const input = getInput()
1212

13-
expect(inp.Token).toMatch('')
14-
expect(inp.GistID).toMatch('test_gist_id')
15-
expect(inp.GistFileName).toMatch('test_gist_file_name')
16-
expect(inp.FilePath).toMatch('test_file_path')
13+
expect(input.Token).toMatch('')
14+
expect(input.GistID).toMatch('gist_id')
15+
expect(input.GistFileName).toMatch('gist_file_name')
16+
expect(input.FilePath).toMatch('file_path')
1717
})
1818

1919
test('run', () => {
@@ -23,6 +23,6 @@ test('run', () => {
2323
process.env.INPUT_GIST_FILE_NAME = 'foo.bar'
2424
process.env.INPUT_FILE_PATH = '__tests__/foo.bar'
2525

26-
const ip = path.join(__dirname, '..', 'lib', 'index.js')
27-
cp.execSync(`node ${ip}`, { env: process.env })
26+
const filePath = path.join(__dirname, '..', 'lib', 'index.js')
27+
execSync(`node ${filePath}`, { env: process.env })
2828
})

src/inputs.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
import * as core from '@actions/core'
22

3-
export interface Inputs {
3+
export interface Input {
44
readonly Token: string
55
readonly GistID: string
66
readonly GistFileName?: string
77
readonly FilePath: string
88
}
99

10-
export const showInputs = (inp: Inputs): void => {
10+
export const showInput = (input: Input): void => {
1111
core.info(`\
12-
[INFO] GistID: ${inp.GistID}
13-
[INFO] GistFileName: ${inp.GistFileName ?? 'No Change'}
14-
[INFO] FilePath: ${inp.FilePath}
12+
[INFO] GistID: ${input.GistID}
13+
[INFO] GistFileName: ${input.GistFileName ?? 'No Change'}
14+
[INFO] FilePath: ${input.FilePath}
1515
`)
1616
}
1717

18-
export const getInputs = (): Inputs => {
19-
const inp: Inputs = {
20-
Token: core.getInput('token'),
21-
GistID: core.getInput('gist_id'),
22-
GistFileName: core.getInput('gist_file_name'),
23-
FilePath: core.getInput('file_path')
24-
}
25-
26-
return inp
27-
}
18+
export const getInput = (): Input => ({
19+
Token: core.getInput('token'),
20+
GistID: core.getInput('gist_id'),
21+
GistFileName: core.getInput('gist_file_name'),
22+
FilePath: core.getInput('file_path')
23+
})

src/run.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@ import fs from 'fs'
22
import path from 'path'
33
import * as core from '@actions/core'
44
import * as github from '@actions/github'
5-
import { showInputs, getInputs } from './inputs'
5+
import { showInput, getInput } from './inputs'
66

77
export const run = async (): Promise<void> => {
8-
const inp = getInputs()
9-
showInputs(inp)
8+
const input = getInput()
9+
showInput(input)
1010

1111
core.startGroup('Read file content')
1212
const workSpace = process.env.GITHUB_WORKSPACE as string
13-
const filepath = path.join(workSpace, inp.FilePath)
14-
const content = fs.readFileSync(filepath, 'utf-8')
15-
core.info(`[INFO] Done with file "${filepath}"`)
13+
const filePath = path.join(workSpace, input.FilePath)
14+
const content = fs.readFileSync(filePath, 'utf-8')
15+
core.info(`[INFO] Done with file "${filePath}"`)
1616
core.endGroup()
1717

1818
core.startGroup('Deploy to gist')
19-
const octokit = github.getOctokit(inp.Token)
20-
const filename = inp.GistFileName ?? path.basename(filepath)
19+
const octokit = github.getOctokit(input.Token)
20+
const fileName = input.GistFileName ?? path.basename(filePath)
2121
await octokit.gists.update({
22-
gist_id: inp.GistID,
22+
gist_id: input.GistID,
2323
files: {
24-
[filename]: {
25-
filename,
24+
[fileName]: {
25+
fileName,
2626
content
2727
}
2828
}
2929
})
30-
core.info(`[INFO] Done with gist "${inp.GistID}/${filename}"`)
30+
core.info(`[INFO] Done with gist "${input.GistID}/${fileName}"`)
3131
core.endGroup()
3232

3333
core.info('[INFO] Action successfully completed')

0 commit comments

Comments
 (0)