Skip to content

Commit a865eab

Browse files
committed
fix(batch-pr): trackedIssues disappearing from pr body
1 parent c88bb6f commit a865eab

2 files changed

Lines changed: 142 additions & 26 deletions

File tree

packages/batch-pr/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ const batchPrPlugin: YukiNoPlugin = {
143143
`batchPr :: Updating PR body with ${issuesToProcess.length} linked issues`,
144144
);
145145
const nextPrBody = createPrBody(
146-
issuesToProcess.map(({ number }) => ({
146+
[...issuesToProcess, ...trackedIssues].map(({ number }) => ({
147147
number,
148148
type: 'Resolved',
149149
})),

packages/batch-pr/tests/integration/orchestration.test.ts

Lines changed: 141 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,6 @@ describe('batch-pr plugin integration', () => {
6666
]),
6767
}));
6868

69-
vi.mock('@yuki-no/plugin-sdk/utils/createFileNameFilter', () => ({
70-
createFileNameFilter: vi.fn(
71-
(_cfg: any, _root?: string) => (file: string) =>
72-
!file.endsWith('.spec.ts') &&
73-
!file.endsWith('.test.ts') &&
74-
file.startsWith('docs/'),
75-
),
76-
}));
77-
78-
vi.mock('@yuki-no/plugin-sdk/utils/input', async importOriginal => {
79-
const orig =
80-
await importOriginal<
81-
typeof import('@yuki-no/plugin-sdk/utils/input')
82-
>();
83-
return { ...orig };
84-
});
85-
8669
// batch-pr utils mocks/spies
8770
vi.mock('../../utils/filterPendedTranslationIssues', () => ({
8871
filterPendedTranslationIssues: vi.fn(async (_gh: any, issues: any[]) =>
@@ -141,13 +124,6 @@ describe('batch-pr plugin integration', () => {
141124
vi.mock('../../utils/createCommit', () => ({
142125
createCommit: vi.fn((_git: any, _opts: any) => {}),
143126
}));
144-
145-
vi.mock('../../utils/createPrBody', () => ({
146-
createPrBody: vi.fn(
147-
(items: any[], meta: any) =>
148-
`Body ${items.length} ${JSON.stringify(meta.excludedFiles)}`,
149-
),
150-
}));
151127
});
152128

153129
afterEach(() => {
@@ -161,6 +137,35 @@ describe('batch-pr plugin integration', () => {
161137
const config = {
162138
labels: ['sync'],
163139
exclude: [],
140+
include: [],
141+
headRepoSpec: { owner: 'acme', name: 'head', branch: 'main' },
142+
upstreamRepoSpec: { owner: 'acme', name: 'upstream', branch: 'main' },
143+
} as any;
144+
145+
await plugin.onFinally?.({ config } as any);
146+
147+
const { pullsUpdate } = (globalThis as any).__mockBP_GH as {
148+
pullsUpdate: ReturnType<typeof vi.fn>;
149+
};
150+
expect(pullsUpdate).toHaveBeenCalled();
151+
const arg = pullsUpdate.mock.calls[0][0];
152+
expect(arg).toMatchObject({
153+
owner: 'acme',
154+
repo: 'upstream',
155+
pull_number: 123,
156+
});
157+
158+
expect(arg.body).toContain('Resolved #222');
159+
expect(arg.body).toContain('Resolved #111');
160+
});
161+
162+
it('should include both trackedIssues and issuesToProcess in PR body', async () => {
163+
const plugin = (await import('../../index')).default;
164+
165+
const config = {
166+
labels: ['sync'],
167+
exclude: [],
168+
include: [],
164169
headRepoSpec: { owner: 'acme', name: 'head', branch: 'main' },
165170
upstreamRepoSpec: { owner: 'acme', name: 'upstream', branch: 'main' },
166171
} as any;
@@ -177,7 +182,9 @@ describe('batch-pr plugin integration', () => {
177182
repo: 'upstream',
178183
pull_number: 123,
179184
});
180-
expect(arg.body).toContain('Body 1');
185+
186+
expect(arg.body).toContain('Resolved #222');
187+
expect(arg.body).toContain('Resolved #111');
181188
});
182189

183190
it('Skip when no pending translation issues', async () => {
@@ -190,6 +197,7 @@ describe('batch-pr plugin integration', () => {
190197
const config = {
191198
labels: ['sync'],
192199
exclude: [],
200+
include: [],
193201
headRepoSpec: { owner: 'acme', name: 'head', branch: 'main' },
194202
upstreamRepoSpec: { owner: 'acme', name: 'upstream', branch: 'main' },
195203
} as any;
@@ -214,6 +222,31 @@ describe('batch-pr plugin integration', () => {
214222
const config = {
215223
labels: ['sync'],
216224
exclude: [],
225+
include: [],
226+
headRepoSpec: { owner: 'acme', name: 'head', branch: 'main' },
227+
upstreamRepoSpec: { owner: 'acme', name: 'upstream', branch: 'main' },
228+
} as any;
229+
230+
await plugin.onFinally?.({ config } as any);
231+
232+
const { pullsUpdate } = (globalThis as any).__mockBP_GH as {
233+
pullsUpdate: ReturnType<typeof vi.fn>;
234+
};
235+
expect(pullsUpdate).not.toHaveBeenCalled();
236+
});
237+
238+
it('should handle only trackedIssues scenario', async () => {
239+
const { getTrackedIssues } = await import('../../utils/getTrackedIssues');
240+
(getTrackedIssues as any).mockResolvedValueOnce({
241+
trackedIssues: [{ number: 111, hash: 'aaaaaaaa' }],
242+
shouldTrackIssues: [],
243+
});
244+
245+
const plugin = (await import('../../index')).default;
246+
const config = {
247+
labels: ['sync'],
248+
exclude: [],
249+
include: [],
217250
headRepoSpec: { owner: 'acme', name: 'head', branch: 'main' },
218251
upstreamRepoSpec: { owner: 'acme', name: 'upstream', branch: 'main' },
219252
} as any;
@@ -223,6 +256,89 @@ describe('batch-pr plugin integration', () => {
223256
const { pullsUpdate } = (globalThis as any).__mockBP_GH as {
224257
pullsUpdate: ReturnType<typeof vi.fn>;
225258
};
259+
260+
expect(pullsUpdate).not.toHaveBeenCalled();
261+
});
262+
263+
it('should handle only new issues scenario', async () => {
264+
const { getTrackedIssues } = await import('../../utils/getTrackedIssues');
265+
(getTrackedIssues as any).mockResolvedValueOnce({
266+
trackedIssues: [],
267+
shouldTrackIssues: [{ number: 222, hash: 'bbbbbbbb' }],
268+
});
269+
270+
const { extractFileChanges } = await import(
271+
'../../utils/extractFileChanges'
272+
);
273+
(extractFileChanges as any).mockImplementation(
274+
(
275+
_git: any,
276+
hash: string,
277+
filter: (f: string) => boolean,
278+
opts: { onExcluded: (p: string) => void },
279+
) => {
280+
if (hash === 'bbbbbbbb') {
281+
const files = [`docs/${hash}/keep.md`];
282+
const out = [] as import('../../types').FileChange[];
283+
for (const f of files) {
284+
if (!filter(f)) {
285+
opts.onExcluded(f);
286+
continue;
287+
}
288+
out.push({
289+
type: 'update',
290+
upstreamFileName: f,
291+
changes: [{ type: 'insert-line', lineNumber: 1, content: 'x' }],
292+
});
293+
}
294+
return out;
295+
}
296+
return [];
297+
},
298+
);
299+
300+
const plugin = (await import('../../index')).default;
301+
const config = {
302+
labels: ['sync'],
303+
exclude: [],
304+
include: [],
305+
headRepoSpec: { owner: 'acme', name: 'head', branch: 'main' },
306+
upstreamRepoSpec: { owner: 'acme', name: 'upstream', branch: 'main' },
307+
} as any;
308+
309+
await plugin.onFinally?.({ config } as any);
310+
311+
const { pullsUpdate } = (globalThis as any).__mockBP_GH as {
312+
pullsUpdate: ReturnType<typeof vi.fn>;
313+
};
314+
315+
expect(pullsUpdate).toHaveBeenCalled();
316+
const arg = pullsUpdate.mock.calls[0][0];
317+
expect(arg.body).toContain('Resolved #222');
318+
});
319+
320+
it('should handle empty issues scenario', async () => {
321+
const { getTrackedIssues } = await import('../../utils/getTrackedIssues');
322+
(getTrackedIssues as any).mockResolvedValueOnce({
323+
trackedIssues: [],
324+
shouldTrackIssues: [],
325+
});
326+
327+
const plugin = (await import('../../index')).default;
328+
const config = {
329+
labels: ['sync'],
330+
exclude: [],
331+
include: [],
332+
headRepoSpec: { owner: 'acme', name: 'head', branch: 'main' },
333+
upstreamRepoSpec: { owner: 'acme', name: 'upstream', branch: 'main' },
334+
} as any;
335+
336+
await plugin.onFinally?.({ config } as any);
337+
338+
const { pullsUpdate } = (globalThis as any).__mockBP_GH as {
339+
pullsUpdate: ReturnType<typeof vi.fn>;
340+
};
341+
226342
expect(pullsUpdate).not.toHaveBeenCalled();
227343
});
228344
});

0 commit comments

Comments
 (0)