Skip to content

Commit f38efde

Browse files
Copilotchenrui333
andauthored
fix: gracefully fallback to body when body_path cannot be read (#671)
* Initial plan * fix: gracefully fallback to body when body_path cannot be read Co-authored-by: chenrui333 <1580956+chenrui333@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: chenrui333 <1580956+chenrui333@users.noreply.github.com>
1 parent cec1a11 commit f38efde

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

__tests__/util.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,52 @@ describe('util', () => {
122122
}),
123123
);
124124
});
125+
it('falls back to body when body_path is missing', () => {
126+
assert.equal(
127+
releaseBody({
128+
github_ref: '',
129+
github_repository: '',
130+
github_token: '',
131+
input_body: 'fallback-body',
132+
input_body_path: '__tests__/does-not-exist.txt',
133+
input_draft: false,
134+
input_prerelease: false,
135+
input_files: [],
136+
input_overwrite_files: undefined,
137+
input_preserve_order: undefined,
138+
input_name: undefined,
139+
input_tag_name: undefined,
140+
input_target_commitish: undefined,
141+
input_discussion_category_name: undefined,
142+
input_generate_release_notes: false,
143+
input_make_latest: undefined,
144+
}),
145+
'fallback-body',
146+
);
147+
});
148+
it('returns undefined when body_path is missing and body is not provided', () => {
149+
assert.equal(
150+
releaseBody({
151+
github_ref: '',
152+
github_repository: '',
153+
github_token: '',
154+
input_body: undefined,
155+
input_body_path: '__tests__/does-not-exist.txt',
156+
input_draft: false,
157+
input_prerelease: false,
158+
input_files: [],
159+
input_overwrite_files: undefined,
160+
input_preserve_order: undefined,
161+
input_name: undefined,
162+
input_tag_name: undefined,
163+
input_target_commitish: undefined,
164+
input_discussion_category_name: undefined,
165+
input_generate_release_notes: false,
166+
input_make_latest: undefined,
167+
}),
168+
undefined,
169+
);
170+
});
125171
});
126172
describe('parseConfig', () => {
127173
it('parses basic config', () => {

src/util.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,17 @@ export const uploadUrl = (url: string): string => {
3535
};
3636

3737
export const releaseBody = (config: Config): string | undefined => {
38-
return (
39-
(config.input_body_path && readFileSync(config.input_body_path).toString('utf8')) ||
40-
config.input_body
41-
);
38+
if (config.input_body_path) {
39+
try {
40+
const contents = readFileSync(config.input_body_path, 'utf8');
41+
return contents;
42+
} catch (err: any) {
43+
console.warn(
44+
`⚠️ Failed to read body_path "${config.input_body_path}" (${err?.code ?? 'ERR'}). Falling back to 'body' input.`,
45+
);
46+
}
47+
}
48+
return config.input_body;
4249
};
4350

4451
type Env = { [key: string]: string | undefined };

0 commit comments

Comments
 (0)