Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

input refactoring #163

Merged
merged 1 commit into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 50 additions & 48 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

79 changes: 39 additions & 40 deletions src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ function getList(name: string): string[] | undefined {
.split('\n')
.map((v) => v.trim())
.filter((v) => v.length > 0);
if (values.length <= 0) {
return undefined;
}

return values;
}
Expand Down Expand Up @@ -82,40 +79,42 @@ function getLevel(): Level {
return level;
}

const android = getBoolean('android');
const debug = getBoolean('debug');
const disabledRules = getList('disabled_rules');
const format = getBoolean('format');
const limit = getNumber('limit');
const relative = getBoolean('relative');
const reporter = getList('reporter');
const ruleset = getString('ruleset');
const verbose = getBoolean('verbose');
const editorconfig = getString('editorconfig');
const experimental = getBoolean('experimental');
const baseline = getString('baseline');
const patterns = getList('patterns');

const ktlintVersion = getKtlintVersion();
const level = getLevel();

const input: Input = {
ktlintVersion,
level,

android,
debug,
disabledRules,
format,
limit,
relative,
reporter,
ruleset,
verbose,
editorconfig,
experimental,
baseline,
patterns,
};

export = input;
function parseInput(): Input {
const android = getBoolean('android');
const debug = getBoolean('debug');
const disabledRules = getList('disabled_rules');
const format = getBoolean('format');
const limit = getNumber('limit');
const relative = getBoolean('relative');
const reporter = getList('reporter');
const ruleset = getString('ruleset');
const verbose = getBoolean('verbose');
const editorconfig = getString('editorconfig');
const experimental = getBoolean('experimental');
const baseline = getString('baseline');
const patterns = getList('patterns');

const ktlintVersion = getKtlintVersion();
const level = getLevel();

return {
ktlintVersion,
level,

android,
debug,
disabledRules,
format,
limit,
relative,
reporter,
ruleset,
verbose,
editorconfig,
experimental,
baseline,
patterns,
};
}

export {parseInput};
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as core from '@actions/core';
import {exec} from '@actions/exec';
import input from './input';
import {parseInput} from './input';
import {install as installLinter} from './setup-linter';
import {install as installReporter} from './setup-reporter';
import {buildArguments} from './linter';
Expand All @@ -26,4 +26,4 @@ async function check(input: Input) {
await exec('ktlint', args);
}

check(input).catch(core.setFailed);
check(parseInput()).catch(core.setFailed);
25 changes: 17 additions & 8 deletions src/tool-provisioner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from 'path';
import * as tc from '@actions/tool-cache';
import * as path from 'path';
import {Tool} from './types';

function createTool(
Expand All @@ -17,19 +17,28 @@ function createTool(
};
}

async function getOrDownload(
async function findOrDownload(
name: string,
version: string,
downloadUrl: string,
fileName: string,
): Promise<Tool> {
let path = tc.find(name, version);

if (!path) {
const downloadedFile = await tc.downloadTool(downloadUrl);
path = await tc.cacheFile(downloadedFile, fileName, name, version);
): Promise<string> {
const path = tc.find(name, version);
if (path) {
return path;
}

const downloadedFile = await tc.downloadTool(downloadUrl);
return await tc.cacheFile(downloadedFile, fileName, name, version);
}

async function getOrDownload(
name: string,
version: string,
downloadUrl: string,
fileName: string,
): Promise<Tool> {
const path = await findOrDownload(name, version, downloadUrl, fileName);
return createTool(name, path, version, fileName);
}

Expand Down
Loading