Skip to content

Commit

Permalink
fix: handle missing projects (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleTryon authored Apr 5, 2023
1 parent 024b8fe commit 4e89998
Showing 1 changed file with 8 additions and 31 deletions.
39 changes: 8 additions & 31 deletions src/utils/CircleCI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,32 +112,21 @@ export class CircleCI {
return pagedData;
}

async getProject(slug: string): Promise<CircleCIProject> {
async getProject(repo: CircleCIAPIRepo): Promise<CircleCIProject> {
const errors: ProjectError[] = [];
const { data: projectMeta } = await this._client
.get<CircleCIAPIProject>(`${CircleCI.endpoint.v2}/project/${slug}`)
.catch((e) => {
const error = getAxiosError(e);
printAxiosError(error, 2);
errors.push({
error: createMinimalAxiosError(error),
projectSlug: slug,
url: `${CircleCI.endpoint.v2}/project/${slug}`,
});
throw error;
});
const { data: projectSecrets } = await this._client
.get<CircleCIAPIPrivateProject>(
`${CircleCI.endpoint.private}/project/${projectMeta.id}?include-deleted=true`
`${CircleCI.endpoint.private}/project/${repo.id}?include-deleted=true`
)
.catch((e) => {
const error = getAxiosError(e);
printAxiosError(error, 2);
errors.push({
error: createMinimalAxiosError(error),
projectSlug: slug,
url: `${CircleCI.endpoint.private}/project/${projectMeta.id}`,
projectSlug: repo.slug,
url: `${CircleCI.endpoint.private}/project/${repo.id}`,
});

const project: CircleCIAPIPrivateProject = {
project_env_vars: [],
checkout_keys: [],
Expand All @@ -147,14 +136,15 @@ export class CircleCI {
secret_access_key: "",
},
};

return {
data: project,
};
});

const project: CircleCIProject = {
errors,
...projectMeta,
...repo,
...projectSecrets,
};
return project;
Expand All @@ -169,7 +159,7 @@ export class CircleCI {
"Fetching project details for:",
2
);
const project = await this.getProject(repos[i].slug);
const project = await this.getProject(repos[i]);
projects.push(project);
}
return projects;
Expand Down Expand Up @@ -275,19 +265,6 @@ type CircleCIAPIRepo = {
slug: string;
has_trigger: boolean;
};
type CircleCIAPIProject = {
slug: string;
name: string;
id: string;
organization_name: string;
organization_id: string;
organization_slug: string;
vcs_info: {
vcs_url: string;
provider: VCS_TYPE;
default_branch: string;
};
};
// An internally created API to more easily fetch project secrets
type CircleCIAPIPrivateProject = {
project_env_vars: CircleCIAPIProjectVariable[];
Expand Down

0 comments on commit 4e89998

Please sign in to comment.