Skip to content

Commit

Permalink
Merge 6da01c0 into 119ea80
Browse files Browse the repository at this point in the history
  • Loading branch information
technote-space committed Aug 31, 2019
2 parents 119ea80 + 6da01c0 commit 757f0b7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ Just run [DocToc](https://github.com/thlorenz/doctoc) and commit to branch if ch
### TARGET_PATHS
Target file path. (Comma separated, [Detail](https://github.com/thlorenz/doctoc#adding-toc-to-individual-files))
default: `'README.md'`
### TOC_TITLE
TOC Title.
default: `'**Table of Contents**'`
### COMMIT_MESSAGE
Commit message.
default: `'docs: Update TOC'`
Expand Down
13 changes: 7 additions & 6 deletions __tests__/utils/misc.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import {getContext, getApiFixture, disableNetConnect, testEnv} from '../util';
import {getContext, testEnv} from '../util';
import {
isTargetEvent,
getBuildVersion,
Expand Down Expand Up @@ -66,15 +66,16 @@ describe('getBuildVersion', () => {
describe('getDocTocArgs', () => {
testEnv();

it('should get default DocToc args', () => {
it('should get DocToc args', () => {
process.env.GITHUB_WORKSPACE = '/tmp/workspace';
expect(getDocTocArgs()).toBe('/tmp/workspace/.work/README.md');
process.env.INPUT_TARGET_PATHS = 'README.md,.github/CONTRIBUTING.md';
process.env.INPUT_TOC_TITLE = '**Table of Contents**';
expect(getDocTocArgs()).toBe('/tmp/workspace/.work/README.md /tmp/workspace/.work/.github/CONTRIBUTING.md --title **Table of Contents**');
});

it('should get DocToc args', () => {
it('should get default DocToc args', () => {
process.env.GITHUB_WORKSPACE = '/tmp/workspace';
process.env.INPUT_TARGET_PATHS = 'README.md,.github/CONTRIBUTING.md';
expect(getDocTocArgs()).toBe('/tmp/workspace/.work/README.md /tmp/workspace/.work/.github/CONTRIBUTING.md');
expect(getDocTocArgs()).toBe('/tmp/workspace/.work/README.md --notitle');
});
});

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ inputs:
TARGET_PATHS:
description: Target file path. (Comma separated, @see https://github.com/thlorenz/doctoc#adding-toc-to-individual-files)
default: 'README.md'
TOC_TITLE:
description: TOC Title
default: '**Table of Contents**'
COMMIT_MESSAGE:
description: Commit message.
default: 'docs: Update TOC'
Expand Down
5 changes: 4 additions & 1 deletion src/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ const getTargetPaths = (): string[] => [...new Set<string>((getInput('TARGET_PAT

export const getDocTocArgs = () => {
const workDir = getWorkDir();
return getTargetPaths().map(item => path.resolve(workDir, item)).join(' ');
const title = getTocTitle().replace('\'', '\\\'').replace('"', '\\"');
return getTargetPaths().map(item => path.resolve(workDir, item)).join(' ') + (title ? ` --title ${title}` : ' --notitle');
};

const getTocTitle = (): string => getInput('TOC_TITLE') || '';

const getWorkspace = (): string => process.env.GITHUB_WORKSPACE || '';

export const getWorkDir = () => path.resolve(getWorkspace(), '.work');
Expand Down

0 comments on commit 757f0b7

Please sign in to comment.