Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Sayali Warule committed Nov 20, 2024
1 parent 47ca723 commit 20400ee
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 36 deletions.
34 changes: 17 additions & 17 deletions action/src/create-commit-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import { VISUAL_REGRESSION_CONTEXT } from 'shared';
import { warning } from '@actions/core';

export const createCommitStatus = async (
commitHash: string,
state: 'failure' | 'success',
description: string,
targetUrl?: string
commitHash: string,
state: 'failure' | 'success',
description: string,
targetUrl?: string
) => {
try {
return octokit.rest.repos.createCommitStatus({
sha: commitHash,
context: VISUAL_REGRESSION_CONTEXT,
state: state,
description: description,
...(targetUrl && {target_url: targetUrl}),
...context.repo
});
} catch (err) {
warning('Failed to update commit status.');
throw err;
}
try {
return octokit.rest.repos.createCommitStatus({
sha: commitHash,
context: VISUAL_REGRESSION_CONTEXT,
state: state,
description: description,
...(targetUrl && { target_url: targetUrl }),
...context.repo
});
} catch (err) {
warning('Failed to update commit status.');
throw err;
}
};
6 changes: 2 additions & 4 deletions action/src/get-latest-visual-regression-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import { VISUAL_REGRESSION_CONTEXT } from 'shared';

export const getLatestVisualRegressionStatus = async (commitHash: string) => {
try {
const {data} = await octokit.rest.repos.listCommitStatusesForRef({
const { data } = await octokit.rest.repos.listCommitStatusesForRef({
ref: commitHash,
...context.repo
});

return data.find(status => status.context === VISUAL_REGRESSION_CONTEXT);
} catch (error) {
warning(
'Failed to get latest visual regression status.'
);
warning('Failed to get latest visual regression status.');
warning(error as Error);
return null;
}
Expand Down
30 changes: 15 additions & 15 deletions action/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ export const run = async () => {
'Visual tests failed to execute successfully. Perhaps one failed to take a screenshot?'
);
return createCommitStatus(
commitHash,
'failure',
VISUAL_TESTS_FAILED_TO_EXECUTE
commitHash,
'failure',
VISUAL_TESTS_FAILED_TO_EXECUTE
);
}

const latestVisualRegressionStatus =
await getLatestVisualRegressionStatus(commitHash);
await getLatestVisualRegressionStatus(commitHash);

if (diffFileCount === 0 && newFileCount === 0) {
info('All visual tests passed, and no diffs found!');
Expand All @@ -90,9 +90,9 @@ export const run = async () => {
}

return createCommitStatus(
commitHash,
'success',
`Visual tests passed${isRetry ? ' on retry' : ''}!`
commitHash,
'success',
`Visual tests passed${isRetry ? ' on retry' : ''}!`
);
}

Expand All @@ -118,18 +118,18 @@ export const run = async () => {
);
await uploadBaseImages(newFilePaths);
return createCommitStatus(
commitHash,
'success',
'New base images were created!'
)
commitHash,
'success',
'New base images were created!'
);
}

await uploadAllImages();
await createCommitStatus(
commitHash,
'failure',
'A visual regression was detected. Check Comparadise!',
buildComparadiseUrl()
commitHash,
'failure',
'A visual regression was detected. Check Comparadise!',
buildComparadiseUrl()
);
await createGithubComment();
};

0 comments on commit 20400ee

Please sign in to comment.