Skip to content

Commit

Permalink
When running an export, drop project items with no content with a war…
Browse files Browse the repository at this point in the history
…ning (#328)

* When running an export, warn and drop project items with no content

* Pass the logger

* Clarify warning
  • Loading branch information
timrogers authored Nov 15, 2024
1 parent 67893ea commit 6e74710
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/commands/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
normalizeBaseUrl,
} from '../utils.js';
import VERSION from '../version.js';
import { createLogger } from '../logger.js';
import { createLogger, Logger } from '../logger.js';
import { createOctokit } from '../octokit.js';
import { type Project, type ProjectItem } from '../graphql-types.js';
import { getReferencedRepositories } from '../project-items.js';
Expand Down Expand Up @@ -128,9 +128,11 @@ const getGlobalIdForUserOwnedProject = async ({
const getProjectItems = async ({
id,
octokit,
logger,
}: {
id: string;
octokit: Octokit;
logger: Logger;
}): Promise<ProjectItem[]> => {
const response = await octokit.graphql.paginate(
`query getProjectItems($id: ID!, $cursor: String) {
Expand Down Expand Up @@ -235,7 +237,22 @@ const getProjectItems = async ({
},
);

return response.node.items.nodes;
const allProjectItems = response.node.items.nodes;

const validProjectItems = allProjectItems.filter((projectItem) => {
if (!projectItem.content) {
logger.warn(
`Skipping project item ${projectItem.id} because its linked issue or pull request could not be retrieved - your access token may lack the required permissions, or you may not have access to the issue or pull request.`,
);
logger.debug('Skipped project item:', projectItem);

return false;
}

return true;
});

return validProjectItems;
};

const getProject = async ({
Expand Down Expand Up @@ -539,7 +556,7 @@ command
logger.info(`Successfully fetched project "${project.title}"`);

logger.info(`Fetching project items...`);
const projectItems = await getProjectItems({ id: projectId, octokit });
const projectItems = await getProjectItems({ id: projectId, octokit, logger });
logger.info(`Successfully fetched ${projectItems.length} project item(s)`);

logger.info(`Writing project data to ${projectOutputPath}...`);
Expand Down

0 comments on commit 6e74710

Please sign in to comment.