Skip to content

Commit 972976d

Browse files
committed
Add PR review feature.
1 parent dac1851 commit 972976d

11 files changed

Lines changed: 988 additions & 93 deletions

File tree

bin/arguments.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ const commitHashPattern = /^[0-9a-f]{4,64}$/i;
66

77
const isCommitHashArgument = (arg) => commitHashPattern.test(arg) && !existsSync(resolve(arg));
88

9+
const isPullRequestUrlArgument = (arg) => {
10+
try {
11+
const url = new URL(arg);
12+
return (
13+
url.hostname.toLowerCase() === 'github.com' &&
14+
/^\/[^/]+\/[^/]+\/pull\/\d+\/?$/.test(url.pathname)
15+
);
16+
} catch {
17+
return false;
18+
}
19+
};
20+
921
export const parseArguments = (args) => {
1022
const { positionals, values } = parseArgs({
1123
allowPositionals: true,
@@ -23,10 +35,13 @@ export const parseArguments = (args) => {
2335
});
2436

2537
let commitRef = typeof values.commit === 'string' ? values.commit : null;
38+
let pullRequestUrl = null;
2639
let requestedPath = null;
2740

2841
for (const arg of positionals) {
29-
if (!commitRef && isCommitHashArgument(arg)) {
42+
if (!pullRequestUrl && isPullRequestUrlArgument(arg)) {
43+
pullRequestUrl = arg;
44+
} else if (!commitRef && isCommitHashArgument(arg)) {
3045
commitRef = arg;
3146
} else if (requestedPath == null) {
3247
requestedPath = arg;
@@ -35,6 +50,7 @@ export const parseArguments = (args) => {
3550

3651
return {
3752
commitRef,
53+
pullRequestUrl,
3854
requestedPath: resolve(requestedPath ?? process.cwd()),
3955
walkthrough: values.walkthrough === true,
4056
};

bin/codiff.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import { parseArguments } from './arguments.js';
1010
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
1111

1212
const run = () => {
13-
const { commitRef, requestedPath, walkthrough } = parseArguments(process.argv.slice(2));
13+
const { commitRef, pullRequestUrl, requestedPath, walkthrough } = parseArguments(
14+
process.argv.slice(2),
15+
);
1416

1517
if (!existsSync(resolve(root, 'dist/index.html')) && !process.env.ELECTRON_RENDERER_URL) {
1618
console.error('Codiff has not been built yet. Run `pnpm build` first.');
@@ -21,6 +23,7 @@ const run = () => {
2123
env: {
2224
...process.env,
2325
CODIFF_COMMIT_REF: commitRef ?? '',
26+
CODIFF_PULL_REQUEST_URL: pullRequestUrl ?? '',
2427
CODIFF_REPOSITORY_PATH: requestedPath,
2528
CODIFF_WALKTHROUGH: walkthrough ? '1' : '',
2629
},

0 commit comments

Comments
 (0)