Skip to content

fix: wait for draft issues to populate in copy project #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion __tests__/copy-project.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
editItem,
editProject,
getDraftIssues,
getProject,
linkProjectToRepository,
linkProjectToTeam
linkProjectToTeam,
ProjectDetails
} from '../src/lib.js';
import { mockGetBooleanInput, mockGetInput } from './utils.js';

Expand Down Expand Up @@ -231,6 +233,11 @@ describe('copyProjectAction', () => {
'template-view': templateView
});
mockGetBooleanInput({ drafts: true });
vi.mocked(getProject).mockResolvedValue({
items: {
totalCount: 1
}
} as ProjectDetails);
vi.mocked(getDraftIssues).mockResolvedValue([
{
id: 'item-id',
Expand Down Expand Up @@ -264,6 +271,11 @@ describe('copyProjectAction', () => {
'template-view': templateView
});
mockGetBooleanInput({ drafts: true });
vi.mocked(getProject).mockResolvedValue({
items: {
totalCount: 1
}
} as ProjectDetails);
vi.mocked(getDraftIssues).mockResolvedValue([
{
id: itemId,
Expand Down Expand Up @@ -302,6 +314,11 @@ describe('copyProjectAction', () => {
'template-view': templateView
});
mockGetBooleanInput({ drafts: true });
vi.mocked(getProject).mockResolvedValue({
items: {
totalCount: 1
}
} as ProjectDetails);
vi.mocked(getDraftIssues).mockResolvedValue([
{
id: itemId,
Expand Down
33 changes: 32 additions & 1 deletion dist/copy-project.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 26 additions & 1 deletion src/copy-project.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { setTimeout } from 'node:timers/promises';

import * as core from '@actions/core';

import {
copyProject,
DraftIssueItem,
editItem,
editProject,
getDraftIssues,
getProject,
linkProjectToRepository,
linkProjectToTeam
} from './lib';
Expand Down Expand Up @@ -69,7 +73,28 @@ export async function copyProjectAction(): Promise<void> {

// Do template interpolation on draft issues
if (templateView) {
const draftIssues = await getDraftIssues(project.id);
// HACK - It seems that GitHub now populates the draft issues
// on the new project in an async manner so they may not all
// be available yet. Wait until the number of draft issues
// matches the number of draft issues in the source project.
const {
items: { totalCount: draftIssueCount }
} = await getProject(owner, projectNumber);

let draftIssues: DraftIssueItem[] = [];

for (let i = 0; i < 10; i++) {
await setTimeout(1000);
draftIssues = await getDraftIssues(project.id);
if (draftIssues.length === draftIssueCount) break;
}

// Log an error but continue as partial success is better than failure
if (draftIssues.length !== draftIssueCount) {
core.error(
`Not all draft issues available for interpolation, expected ${draftIssueCount} but got ${draftIssues.length}`
);
}

for (const draftIssue of draftIssues) {
try {
Expand Down