Skip to content

Commit

Permalink
fix(ci): pass project name to downloadReportArtifact
Browse files Browse the repository at this point in the history
  • Loading branch information
matejchalk committed Nov 8, 2024
1 parent 61d49ea commit 647f7e2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
14 changes: 7 additions & 7 deletions packages/ci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ This will additionally compare reports from both source and target branches and
The PR flow requires interacting with the Git provider's API to post a comparison comment.
Wrap these requests in functions and pass them in as an object which configures the provider.

| Property | Required | Type | Description |
| :----------------------- | :------: | :----------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------- |
| `createComment` | yes | `(body: string) => Promise<Comment>` | Posts a new comment to PR |
| `updateComment` | yes | `(id: number, body: string) => Promise<Comment>` | Updates existing PR comment |
| `listComments` | yes | `() => Promise<Comment[]>` | Fetches all comments from PR |
| `maxCommentChars` | yes | `number` | Character limit for comment body |
| `downloadReportArtifact` | no | `() => Promise<string \| null>` | Fetches previous report for base branch (returns path to downloaded `report.json`), used as cache to speed up comparison |
| Property | Required | Type | Description |
| :----------------------- | :------: | :----------------------------------------------- | :------------------------------------------------------------------------------------------------------------------- |
| `createComment` | yes | `(body: string) => Promise<Comment>` | Posts a new comment to PR |
| `updateComment` | yes | `(id: number, body: string) => Promise<Comment>` | Updates existing PR comment |
| `listComments` | yes | `() => Promise<Comment[]>` | Fetches all comments from PR |
| `maxCommentChars` | yes | `number` | Character limit for comment body |
| `downloadReportArtifact` | no | `(project?: string) => Promise<string \| null>` | Fetches previous (root/project) `report.json` for base branch and returns path, used as cache to speed up comparison |

A `Comment` object has the following required properties:

Expand Down
2 changes: 1 addition & 1 deletion packages/ci/src/lib/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type GitRefs = {
*/
export type ProviderAPIClient = {
maxCommentChars: number;
downloadReportArtifact?: () => Promise<string | null>;
downloadReportArtifact?: (project?: string) => Promise<string | null>;
listComments: () => Promise<Comment[]>;
updateComment: (id: number, body: string) => Promise<Comment>;
createComment: (body: string) => Promise<Comment>;
Expand Down
2 changes: 1 addition & 1 deletion packages/ci/src/lib/run.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ describe('runInCI', () => {
expect.stringContaining(diffMdString),
);
expect(api.createComment).not.toHaveBeenCalled();
expect(api.downloadReportArtifact).toHaveBeenCalledWith();
expect(api.downloadReportArtifact).toHaveBeenCalledWith(undefined);

expect(utils.executeProcess).toHaveBeenCalledTimes(2);
expect(utils.executeProcess).toHaveBeenNthCalledWith(1, {
Expand Down
5 changes: 3 additions & 2 deletions packages/ci/src/lib/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,17 @@ async function runOnProject(args: {
}

async function collectPreviousReport(args: {
project: ProjectConfig | null;
base: GitBranch;
api: ProviderAPIClient;
settings: Settings;
ctx: CommandContext;
git: SimpleGit;
}): Promise<string | null> {
const { base, api, settings, ctx, git } = args;
const { project, base, api, settings, ctx, git } = args;
const logger = settings.logger;

const cachedBaseReport = await api.downloadReportArtifact?.();
const cachedBaseReport = await api.downloadReportArtifact?.(project?.name);
if (api.downloadReportArtifact != null) {
logger.info(
`Previous report artifact ${cachedBaseReport ? 'found' : 'not found'}`,
Expand Down

0 comments on commit 647f7e2

Please sign in to comment.