Skip to content

Commit

Permalink
Add no-comments option to disable commenting on PRs and commits
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed May 5, 2021
1 parent 4458c73 commit 4a48f7d
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 9 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ inputs:
extra-args:
description: 'Extra arguments; can be used to specify specific files to check.'
required: false
no-comments:
description: 'Disable issue/commit comments'
required: false
default: 'false'
```
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ inputs:
extra-args:
description: 'Extra arguments; can be used to specify specific files to check.'
required: false
no-comments:
description: 'Disable issue/commit comments'
required: false
default: 'false'

runs:
using: 'node12'
Expand Down
31 changes: 27 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5637,7 +5637,16 @@ async function main() {
}
const version = await getVersion();
console.log(`pyright ${version}`);
const args = await getArgs(version);
const {args, noComments} = await getArgs(version);
if (noComments) {
const {status: status2} = cp.spawnSync(process.execPath, args, {
stdio: ["ignore", "inherit", "inherit"]
});
if (status2 !== 0) {
core.setFailed(`Exit code ${status2}`);
}
return;
}
const {status, stdout} = cp.spawnSync(process.execPath, args, {
encoding: "utf-8",
stdio: ["ignore", "pipe", "inherit"]
Expand Down Expand Up @@ -5684,7 +5693,11 @@ async function getVersion() {
}
async function getArgs(version) {
const pyrightIndex = await getPyright(version);
const args = [pyrightIndex, "--outputjson"];
const args = [pyrightIndex];
const noComments = getBooleanInput("no-comments", false);
if (!noComments) {
args.push("--outputjson");
}
const pythonPlatform = core.getInput("python-platform");
if (pythonPlatform) {
args.push("--pythonplatform");
Expand All @@ -5710,15 +5723,25 @@ async function getArgs(version) {
args.push("--project");
args.push(project);
}
const lib = (core.getInput("lib") || "false").toUpperCase() === "TRUE";
const lib = getBooleanInput("lib", false);
if (lib) {
args.push("--lib");
}
const extraArgs = core.getInput("extra-args");
if (extraArgs) {
args.push(...(0, import_string_argv.default)(extraArgs));
}
return args;
return {
args,
noComments
};
}
function getBooleanInput(name, defaultValue) {
const input = core.getInput(name);
if (!input) {
return defaultValue;
}
return input.toUpperCase() === "TRUE";
}
async function getPyright(version) {
const url = `https://registry.npmjs.org/pyright/-/pyright-${version.format()}.tgz`;
Expand Down
38 changes: 33 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,19 @@ export async function main() {
const version = await getVersion();
console.log(`pyright ${version}`);

const args = await getArgs(version);
const { args, noComments } = await getArgs(version);

if (noComments) {
// Comments are disabled, just run as a subprocess passing things through.
const { status } = cp.spawnSync(process.execPath, args, {
stdio: ['ignore', 'inherit', 'inherit'],
});

if (status !== 0) {
core.setFailed(`Exit code ${status}`);
}
return;
}

const { status, stdout } = cp.spawnSync(process.execPath, args, {
encoding: 'utf-8',
Expand Down Expand Up @@ -87,10 +99,15 @@ async function getVersion(): Promise<SemVer> {
return new SemVer(obj.version);
}

async function getArgs(version: SemVer): Promise<string[]> {
async function getArgs(version: SemVer) {
const pyrightIndex = await getPyright(version);

const args = [pyrightIndex, '--outputjson'];
const args = [pyrightIndex];

const noComments = getBooleanInput('no-comments', false);
if (!noComments) {
args.push('--outputjson');
}

const pythonPlatform = core.getInput('python-platform');
if (pythonPlatform) {
Expand Down Expand Up @@ -122,7 +139,7 @@ async function getArgs(version: SemVer): Promise<string[]> {
args.push(project);
}

const lib = (core.getInput('lib') || 'false').toUpperCase() === 'TRUE';
const lib = getBooleanInput('lib', false);
if (lib) {
args.push('--lib');
}
Expand All @@ -132,7 +149,18 @@ async function getArgs(version: SemVer): Promise<string[]> {
args.push(...stringArgv(extraArgs));
}

return args;
return {
args,
noComments,
};
}

function getBooleanInput(name: string, defaultValue: boolean): boolean {
const input = core.getInput(name);
if (!input) {
return defaultValue;
}
return input.toUpperCase() === 'TRUE';
}

async function getPyright(version: SemVer): Promise<string> {
Expand Down

0 comments on commit 4a48f7d

Please sign in to comment.