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

migrate to pino #153

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ project
try {
await runAddProjectCommand(knex, options)
} catch (error) {
logger.error('Error adding project:', error.message)
logger.error(error)
process.exit(1)
} finally {
await knex.destroy()
Expand All @@ -38,7 +38,7 @@ workflow
try {
await runWorkflowCommand(knex, options)
} catch (error) {
logger.error('Error running workflow:', error.message)
logger.error(error)
process.exit(1)
} finally {
await knex.destroy()
Expand All @@ -62,7 +62,7 @@ check
try {
await listCheckCommand(knex, options)
} catch (error) {
logger.error('Error running check:', error.message)
logger.error(error)
process.exit(1)
} finally {
await knex.destroy()
Expand All @@ -77,7 +77,7 @@ check
try {
await runCheckCommand(knex, options)
} catch (error) {
logger.error('Error running check:', error.message)
logger.error(error)
process.exit(1)
} finally {
await knex.destroy()
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"knex": "3.1.0",
"octokit": "3.2.1",
"pg": "8.13.1",
"pino": "^9.5.0",
"pino-pretty": "^13.0.0",
"validator": "13.12.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/cli/workflows.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const commandList = [{
const validCommandNames = commandList.map(({ name }) => name)

function listWorkflowCommand (options = {}) {
logger.log('Available workflows:')
logger.log(commandList.map(({ name, description }) => `- ${name}: ${description}`).join('\n'))
logger.log('Available workflows: \n')
commandList.forEach(({ name, description }) => logger.log(`- ${name}: ${description}`))
return commandList
}

Expand Down
1 change: 0 additions & 1 deletion src/providers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const performScorecardAnalysis = async (repo) => {
const start = new Date().getTime()
const { stdout, stderr } = await exec(`docker run -e GITHUB_AUTH_TOKEN=${process.env.GITHUB_TOKEN} --rm ${ossfScorecardSettings.dockerImage} --repo=${repo.html_url} --show-details --format=json`)
if (stderr) {
console.error(stderr)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not possible to parse a string, so the best option would be to remove this to prevent a token leak.

Or maybe I haven't found the option yet.

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 know there is redact to do that, but it only works at the object level, or that's the only way it has worked correctly for me.

https://github.com/pinojs/pino/blob/main/docs/redaction.md

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are totally right! Let me see if I can use a hook for this, as the token pattern is clear.

throw new Error(`Error running OSSF Scorecard for repository (${repo.full_name})`)
}
const data = JSON.parse(stdout)
Expand Down
14 changes: 12 additions & 2 deletions src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
const { add, parseISO, isBefore } = require('date-fns')
const isURL = require('validator/lib/isURL.js')
const pino = require('pino')({
transport: {
target: 'pino-pretty',
options: {
ignore: 'pid,hostname'
}
},
level: process.env.PINO_LOG_LEVEL || 'trace'
})

const validateGithubUrl = (url) => isURL(url, { protocols: ['https'], require_protocol: true }) && url.includes('github.com')

Expand All @@ -13,14 +22,15 @@ const defineLog = (type) => function () {
if (process.env.NODE_ENV === 'test') {
return () => {}
}
return console[type](...arguments)

return pino[type](...arguments)
}

const logger = {
info: defineLog('info'),
error: defineLog('error'),
warn: defineLog('warn'),
log: defineLog('log')
log: defineLog('trace')
}

const getSeverityFromPriorityGroup = (priorityGroup) => {
Expand Down
Loading