-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat: add support to custom repository info #100
Conversation
bin/commands/push.ts
Outdated
console.error(error) | ||
process.exit(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could put this inside the catch
clause, allowing to remove the error
variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. The problem is that when I call process.exit(1)
, the process is terminated, so the finally
block will never be executed. However, I've just figured that we can also just change the process code with:
process.exitCode = 1
if (format === 'json') { | ||
const metrics = buildMetricsPayload(occurrences) | ||
content = JSON.stringify(metrics, null, 2) | ||
} else if (format === 'sarif') { | ||
const branch = await git.branchName() | ||
const sha = await git.sha() | ||
const sarif = buildSarifPayload(configuration.project_name, branch, sha, occurrences) | ||
const sarif = buildSarifPayload(configuration.repository, branch, sha, occurrences) | ||
content = JSON.stringify(sarif, null, 2) | ||
} else if (format === 'sonar') { | ||
const sonar = buildSonarGenericImportPayload(occurrences) | ||
content = JSON.stringify(sonar, null, 2) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another way to do this is by doing a mapping, like this :
const buildPayloadMapping: Record<keyof ALLOWED_FORMATS, () => object> = {
json: () => buildMetricsPayload(occurences),
sonar: () => buildSonarGenericImportPayload(occurences),
sarif: async () => {
const branch = await git.branchName()
const sha = await git.sha()
return buildSarifPayload(...)
}
}
const content = JSON.stringify(await buildPayloadMapping[format], null, 2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having a hard time with this one because some of the mappings are async while others are not. I'll make this change in a follow-up PR.
export const upload = async (apiKey: string, projectName: string, date: Date, occurrences: Occurrence[]) => { | ||
if (!projectName) panic('specify a project_name in your cherry.js configuration file before pushing metrics') | ||
|
||
const uuid = await v4() | ||
const uuid = v4() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also use randomUUID
which is an ECMAscript feature : https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID
It would allow you to remove the uuid
dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Will also do it in another PR.
* wip * wip * remove * Initial commit * fix test * fix types * rollback * chore * chore * setup auto formatting * silence fixture setup script * add commit url to contributions payload * test contributions payload * use relative imports * fix deprecated method * stop suggesting dist folder for imports * fix test * prevent push if there are uncommitted changes * fix lint * increase timeout in ci * refactor * refactor * handle error * rollback * as const * type * fix test * remove async * remove finally * remove project name * add project name
* wip * wip * remove * Initial commit * fix test * fix types * rollback * chore * chore * setup auto formatting * silence fixture setup script * add commit url to contributions payload * test contributions payload * use relative imports * fix deprecated method * stop suggesting dist folder for imports * fix test * prevent push if there are uncommitted changes * fix lint * increase timeout in ci * refactor * refactor * handle error * rollback * as const * type * fix test * remove async * remove finally * remove project name * add project name
This should close #98