Skip to content

Commit 6539220

Browse files
committed
fix get_pr_comments to correctly resolve path now that we use amp sdk
1 parent 8890e7d commit 6539220

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

src/config.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { readFileSync } from 'fs';
1+
import { existsSync, readFileSync } from 'fs';
22
import * as yaml from 'js-yaml';
33
import { config } from 'dotenv';
44
import { z } from 'zod';
5+
import path from 'path';
6+
import { fileURLToPath } from 'url';
57

68
// Load environment variables
79
config();
@@ -42,8 +44,23 @@ class ConfigLoader {
4244
private static instance: ConfigLoader;
4345
private config: Config;
4446

47+
private resolveConfigPath(): string {
48+
const candidates: (string | undefined)[] = [
49+
process.env.CONFIG_PATH,
50+
process.env.GITHUB_APP_CWD && path.join(process.env.GITHUB_APP_CWD, 'config.yml'),
51+
path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', 'config.yml'),
52+
path.resolve(process.cwd(), 'config.yml'),
53+
];
54+
55+
const found = candidates.filter(Boolean).find(p => existsSync(p as string)) as string | undefined;
56+
if (!found) {
57+
throw new Error(`config.yml not found. Searched: ${candidates.filter(Boolean).join(', ')}`);
58+
}
59+
return found;
60+
}
61+
4562
private constructor() {
46-
const configFile = readFileSync('config.yml', 'utf8');
63+
const configFile = readFileSync(this.resolveConfigPath(), 'utf8');
4764
const rawConfig = yaml.load(configFile);
4865
const processedConfig = this.processEnvVars(rawConfig);
4966
this.config = ConfigSchema.parse(processedConfig);

toolbox/get-pr-comments.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,24 @@
22

33
import fs from 'fs';
44
import path from 'path';
5-
import { pathToFileURL } from 'url';
5+
import { fileURLToPath, pathToFileURL } from 'url';
66

7-
// Resolve compiled code from project root → dist/
8-
const rootDir = path.resolve(process.cwd());
9-
const distImport = async (rel) => import(pathToFileURL(path.join(rootDir, 'dist', rel)).href);
7+
// Resolve compiled code relative to script location (not cwd)
8+
const __filename = fileURLToPath(import.meta.url);
9+
const __dirname = path.dirname(__filename);
10+
11+
const candidateDistDirs = [
12+
path.resolve(__dirname, '..'), // when script is in dist/toolbox
13+
path.resolve(__dirname, '..', 'dist'), // when script is in toolbox/
14+
path.resolve(process.cwd(), 'dist'), // fallback
15+
];
16+
17+
const distDir = candidateDistDirs.find(d => fs.existsSync(path.join(d, 'config.js')));
18+
if (!distDir) {
19+
throw new Error(`Cannot locate dist/ (searched: ${candidateDistDirs.join(', ')})`);
20+
}
21+
22+
const distImport = async (rel) => import(pathToFileURL(path.join(distDir, rel)).href);
1023

1124
const action = process.env.TOOLBOX_ACTION;
1225

0 commit comments

Comments
 (0)