mirror of
https://github.com/tinyhumansai/openhuman.git
synced 2026-07-27 21:08:00 +00:00
fix(scripts): add short help to PR main sync (#3221)
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import { dirname, join, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { test } from 'node:test';
|
||||
|
||||
const HERE = dirname(fileURLToPath(import.meta.url));
|
||||
const SCRIPT = resolve(HERE, '..', 'merge-main-into-open-prs.mjs');
|
||||
|
||||
function writeFailingStub(binDir, name) {
|
||||
fs.writeFileSync(
|
||||
join(binDir, name),
|
||||
`#!/usr/bin/env sh\necho "${name} should not run for help" >&2\nexit 99\n`,
|
||||
{ mode: 0o755 },
|
||||
);
|
||||
}
|
||||
|
||||
function runHelp(flag) {
|
||||
const binDir = fs.mkdtempSync(join(os.tmpdir(), 'openhuman-git-gh-stub-'));
|
||||
writeFailingStub(binDir, 'git');
|
||||
writeFailingStub(binDir, 'gh');
|
||||
|
||||
return spawnSync(process.execPath, [SCRIPT, flag], {
|
||||
encoding: 'utf8',
|
||||
env: {
|
||||
...process.env,
|
||||
PATH: `${binDir}${process.platform === 'win32' ? ';' : ':'}${process.env.PATH ?? ''}`,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
test('merge-main-into-open-prs help exits before invoking git or gh', () => {
|
||||
for (const flag of ['--help', '-h']) {
|
||||
const result = runHelp(flag);
|
||||
|
||||
assert.equal(result.status, 0, result.stderr);
|
||||
assert.match(result.stdout, /Usage: merge-main-into-open-prs\.mjs \[options\]/);
|
||||
assert.match(result.stdout, /-h, --help\s+Show this message\./);
|
||||
assert.equal(result.stderr, '');
|
||||
}
|
||||
});
|
||||
@@ -23,7 +23,7 @@ Options:
|
||||
--pr <number> Restrict to one PR number. May be passed multiple times.
|
||||
--include-drafts Include draft PRs (default: false)
|
||||
--execute Actually merge and push. Dry-run by default.
|
||||
--help Show this message.
|
||||
-h, --help Show this message.
|
||||
|
||||
Examples:
|
||||
node scripts/merge-main-into-open-prs.mjs
|
||||
@@ -79,7 +79,7 @@ function parseArgs(argv) {
|
||||
|
||||
for (let i = 0; i < argv.length; i += 1) {
|
||||
const arg = argv[i];
|
||||
if (arg === '--help') {
|
||||
if (arg === '--help' || arg === '-h') {
|
||||
printUsage();
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user