Skip to content
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

Merged
merged 32 commits into from
Sep 28, 2024

Conversation

fwuensche
Copy link
Contributor

@fwuensche fwuensche commented Sep 19, 2024

This should close #98

@fwuensche fwuensche changed the title fix(add-support-to-custom-repo-info): WIP feat: add support to custom repository info Sep 19, 2024
Comment on lines 73 to 74
console.error(error)
process.exit(1)
Copy link
Contributor

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

Copy link
Contributor Author

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

https://nodejs.org/api/process.html#processexitcode_1

bin/commands/run.ts Outdated Show resolved Hide resolved
bin/commands/run.ts Outdated Show resolved Hide resolved
Comment on lines 62 to 73
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)
}
Copy link
Contributor

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)

Copy link
Contributor Author

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()
Copy link
Contributor

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

Copy link
Contributor Author

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.

src/occurrences.ts Outdated Show resolved Hide resolved
src/contributions.test.ts Outdated Show resolved Hide resolved
@fwuensche fwuensche merged commit 59d383b into main Sep 28, 2024
2 checks passed
fwuensche added a commit that referenced this pull request Oct 4, 2024
* 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
fwuensche added a commit that referenced this pull request Oct 4, 2024
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong URL in the "recent commit" section
2 participants