Skip to content

Commit

Permalink
Merge pull request #32 from KoolTheba/main
Browse files Browse the repository at this point in the history
Hide titles if the tags mode is enabled
  • Loading branch information
UlisesGascon authored Feb 25, 2023
2 parents 9d9ab49 + 611de75 commit e3526f9
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 13 deletions.
15 changes: 14 additions & 1 deletion __fixtures__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,20 @@ const scope = {
}
}

const scores = [
{
org: 'fake-org',
repo: 'fake-repo',
platform: 'github.com',
commit: '846b3ddb5f75d95235e94d9eb52e920f4a067338',
score: 10,
date: '2023-02-20',
currentDiff: 5
}
]

module.exports = {
database,
scope
scope,
scores
}
31 changes: 31 additions & 0 deletions __tests__/__snapshots__/utils.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Utils generateReportContent Should render template with scores and title 1`] = `
"# OpenSSF Scorecard Report
## Summary
| Repository | Commit | Score | Date | Difference | Report Link |
| -- | -- | -- | -- | -- | -- |
| [fake-org/fake-repo](https://github.com/fake-org/fake-repo) | [846b3dd](https://github.com/fake-org/fake-repo/commit/846b3ddb5f75d95235e94d9eb52e920f4a067338) | 10 | 2023-02-20 | 5 | [Full Report](https://deps.dev/project/github/fake-org%2Ffake-repo) |
_Report generated by [UlisesGascon/openssf-scorecard-monitor](https://github.com/UlisesGascon/openssf-scorecard-monitor)._"
`;

exports[`Utils generateReportContent Should render template with scores only 1`] = `
"
| Repository | Commit | Score | Date | Difference | Report Link |
| -- | -- | -- | -- | -- | -- |
| [fake-org/fake-repo](https://github.com/fake-org/fake-repo) | [846b3dd](https://github.com/fake-org/fake-repo/commit/846b3ddb5f75d95235e94d9eb52e920f4a067338) | 10 | 2023-02-20 | 5 | [Full Report](https://deps.dev/project/github/fake-org%2Ffake-repo) |
_Report generated by [UlisesGascon/openssf-scorecard-monitor](https://github.com/UlisesGascon/openssf-scorecard-monitor)._"
`;

exports[`Utils generateReportContent Should render template with title only 1`] = `
"# OpenSSF Scorecard Report
## Summary
_Report generated by [UlisesGascon/openssf-scorecard-monitor](https://github.com/UlisesGascon/openssf-scorecard-monitor)._"
`;
23 changes: 21 additions & 2 deletions __tests__/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { validateDatabaseIntegrity, validateScopeIntegrity } = require('../src/utils')
const { database, scope } = require('../__fixtures__')
const { validateDatabaseIntegrity, validateScopeIntegrity, generateReportContent } = require('../src/utils')
const { database, scope, scores } = require('../__fixtures__')

describe('Utils', () => {
describe('validateDatabaseIntegrity', () => {
Expand All @@ -19,4 +19,23 @@ describe('Utils', () => {
expect(() => validateScopeIntegrity(scope.emptyScope)).not.toThrow()
})
})

describe('generateReportContent', () => {
it('Should render template with scores and title', async () => {
const reportTagsEnabled = false
const report = await generateReportContent(scores, reportTagsEnabled)
expect(report).toMatchSnapshot()
})
it('Should render template with scores only', async () => {
const reportTagsEnabled = true
const report = await generateReportContent(scores, reportTagsEnabled)
expect(report).toMatchSnapshot()
})
it('Should render template with title only', async () => {
const emptyScores = []
const reportTagsEnabled = false
const report = await generateReportContent(emptyScores, reportTagsEnabled)
expect(report).toMatchSnapshot()
})
})
})
10 changes: 5 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27711,7 +27711,7 @@ const generateScope = async ({ octokit, orgs, scope, maxRequestInParallel }) =>
return newScope
}

const generateScores = async ({ scope, database: currentDatabase, maxRequestInParallel }) => {
const generateScores = async ({ scope, database: currentDatabase, maxRequestInParallel, reportTagsEnabled }) => {
// @TODO: Improve deep clone logic
const database = JSON.parse(JSON.stringify(currentDatabase))
const platform = 'github.com'
Expand Down Expand Up @@ -27770,7 +27770,7 @@ const generateScores = async ({ scope, database: currentDatabase, maxRequestInPa

core.debug('All the scores are already collected')

const reportContent = await generateReportContent(scores)
const reportContent = await generateReportContent(scores, reportTagsEnabled)
const issueContent = await generateIssueContent(scores)

// SET OUTPUTS
Expand Down Expand Up @@ -27834,10 +27834,10 @@ const saveScore = ({ database, platform, org, repo, score, date, commit }) => {
repoRef.current = { score, date, commit }
}

const generateReportContent = async (scores) => {
const generateReportContent = async (scores, reportTagsEnabled) => {
core.debug('Generating report content')
const template = await readFile(__nccwpck_require__.ab + "report.ejs", 'utf8')
return ejs.render(template, { scores })
return ejs.render(template, { scores, reportTagsEnabled })
}

const generateIssueContent = async (scores) => {
Expand Down Expand Up @@ -28219,7 +28219,7 @@ async function run () {

// PROCESS
core.info('Generating scores...')
const { reportContent, issueContent, database: newDatabaseState } = await generateScores({ scope, database, maxRequestInParallel })
const { reportContent, issueContent, database: newDatabaseState } = await generateScores({ scope, database, maxRequestInParallel, reportTagsEnabled })

core.info('Checking database changes...')
const hasChanges = isDifferent(database, newDatabaseState)
Expand Down
2 changes: 2 additions & 0 deletions dist/report.ejs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<%_ if (!reportTagsEnabled) { -%>
# OpenSSF Scorecard Report
## Summary
<%_ } -%>

<%_ if (scores.length) { -%>
| Repository | Commit | Score | Date | Difference | Report Link |
Expand Down
2 changes: 1 addition & 1 deletion src/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async function run () {

// PROCESS
core.info('Generating scores...')
const { reportContent, issueContent, database: newDatabaseState } = await generateScores({ scope, database, maxRequestInParallel })
const { reportContent, issueContent, database: newDatabaseState } = await generateScores({ scope, database, maxRequestInParallel, reportTagsEnabled })

core.info('Checking database changes...')
const hasChanges = isDifferent(database, newDatabaseState)
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const generateScope = async ({ octokit, orgs, scope, maxRequestInParallel }) =>
return newScope
}

const generateScores = async ({ scope, database: currentDatabase, maxRequestInParallel }) => {
const generateScores = async ({ scope, database: currentDatabase, maxRequestInParallel, reportTagsEnabled }) => {
// @TODO: Improve deep clone logic
const database = JSON.parse(JSON.stringify(currentDatabase))
const platform = 'github.com'
Expand Down Expand Up @@ -157,7 +157,7 @@ const generateScores = async ({ scope, database: currentDatabase, maxRequestInPa

core.debug('All the scores are already collected')

const reportContent = await generateReportContent(scores)
const reportContent = await generateReportContent(scores, reportTagsEnabled)
const issueContent = await generateIssueContent(scores)

// SET OUTPUTS
Expand Down
4 changes: 2 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ const saveScore = ({ database, platform, org, repo, score, date, commit }) => {
repoRef.current = { score, date, commit }
}

const generateReportContent = async (scores) => {
const generateReportContent = async (scores, reportTagsEnabled) => {
core.debug('Generating report content')
const template = await readFile(join(process.cwd(), 'templates/report.ejs'), 'utf8')
return ejs.render(template, { scores })
return ejs.render(template, { scores, reportTagsEnabled })
}

const generateIssueContent = async (scores) => {
Expand Down
2 changes: 2 additions & 0 deletions templates/report.ejs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<%_ if (!reportTagsEnabled) { -%>
# OpenSSF Scorecard Report
## Summary
<%_ } -%>

<%_ if (scores.length) { -%>
| Repository | Commit | Score | Date | Difference | Report Link |
Expand Down

0 comments on commit e3526f9

Please sign in to comment.