diff --git a/README.md b/README.md index c056d90..f55ccae 100644 --- a/README.md +++ b/README.md @@ -109,10 +109,10 @@ jobs: - `max-request-in-parallel`: Defines the total HTTP Request that can be done in parallel - `discovery-enabled`: Defined if the discovery is enabled - `discovery-orgs`: List of organizations to be includes in the discovery, example: `discovery-orgs: owasp,nodejs`. The OpenSSF Scorecard API is case sensitive, please use the same organization name as in the github url, like: https://github.com/NodeSecure is `NodeSecure` and not `nodesecure`. [See example](https://github.com/NodeSecure/Governance/issues/21#issuecomment-1474770986) -- `report-tags-enabled`: Defines if the markdown report must be created/updated around tags by default is disabled. This is useful if the report is going to be include in a file that has other content on it, like docusaurus docs site or similar. -- `report-start-tag`: Defines the start tag, default `` -- `report-end-tag` Defines the closing tag, default `` - +- `report-tags-enabled`: Defines if the markdown report must be created/updated around tags by default is disabled. This is useful if the report is going to be include in a file that has other content on it, like docusaurus docs site or similar +- `report-start-tag` Defines the start tag, default `` +- `report-end-tag`: Defines the closing tag, default `` +- `render-badge`: Defines if the OpenSSF badge must be rendered in the reportor to only show the score ### Outputs diff --git a/action.yml b/action.yml index 70c63f9..19e56e2 100644 --- a/action.yml +++ b/action.yml @@ -55,6 +55,10 @@ inputs: description: 'Maximum number of HTTP requests to be executed in parallel' required: false default: "10" + render-badge: + description: 'Render the OSSF badge in the report' + required: false + default: "false" outputs: scores: diff --git a/dist/index.js b/dist/index.js index d5ddcf5..f17e3d6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -27711,7 +27711,7 @@ const generateScope = async ({ octokit, orgs, scope, maxRequestInParallel }) => return newScope } -const generateScores = async ({ scope, database: currentDatabase, maxRequestInParallel, reportTagsEnabled }) => { +const generateScores = async ({ scope, database: currentDatabase, maxRequestInParallel, reportTagsEnabled, renderBadge }) => { // @TODO: Improve deep clone logic const database = JSON.parse(JSON.stringify(currentDatabase)) const platform = 'github.com' @@ -27770,8 +27770,8 @@ const generateScores = async ({ scope, database: currentDatabase, maxRequestInPa core.debug('All the scores are already collected') - const reportContent = await generateReportContent(scores, reportTagsEnabled) - const issueContent = await generateIssueContent(scores) + const reportContent = await generateReportContent(scores, reportTagsEnabled, renderBadge) + const issueContent = await generateIssueContent(scores, renderBadge) // SET OUTPUTS core.setOutput('scores', scores) @@ -27834,20 +27834,20 @@ const saveScore = ({ database, platform, org, repo, score, date, commit }) => { repoRef.current = { score, date, commit } } -const generateReportContent = async (scores, reportTagsEnabled) => { +const generateReportContent = async (scores, reportTagsEnabled, renderBadge) => { core.debug('Generating report content') const template = await readFile(__nccwpck_require__.ab + "report.ejs", 'utf8') - return ejs.render(template, { scores, reportTagsEnabled }) + return ejs.render(template, { scores, reportTagsEnabled, renderBadge }) } -const generateIssueContent = async (scores) => { +const generateIssueContent = async (scores, renderBadge) => { core.debug('Generating issue content') const scoresInScope = scores.filter(({ currentDiff }) => currentDiff) if (!scoresInScope.length) { return null } const template = await readFile(__nccwpck_require__.ab + "issue.ejs", 'utf8') - return ejs.render(template, { scores: scoresInScope }) + return ejs.render(template, { scores: scoresInScope, renderBadge }) } module.exports = { @@ -28161,6 +28161,7 @@ async function run () { const reportTagsEnabled = normalizeBoolean(core.getInput('report-tags-enabled')) const startTag = core.getInput('report-start-tag') || '' const endTag = core.getInput('report-end-tag') || '' + const renderBadge = normalizeBoolean(core.getInput('render-badge')) // Error Handling if (!githubToken && [autoPush, autoCommit, generateIssue, discoveryEnabled].some(value => value)) { @@ -28221,7 +28222,7 @@ async function run () { // PROCESS core.info('Generating scores...') - const { reportContent, issueContent, database: newDatabaseState } = await generateScores({ scope, database, maxRequestInParallel, reportTagsEnabled }) + const { reportContent, issueContent, database: newDatabaseState } = await generateScores({ scope, database, maxRequestInParallel, reportTagsEnabled, renderBadge }) core.info('Checking database changes...') const hasChanges = isDifferent(database, newDatabaseState) diff --git a/dist/issue.ejs b/dist/issue.ejs index b2f178a..d2e5236 100644 --- a/dist/issue.ejs +++ b/dist/issue.ejs @@ -13,7 +13,7 @@ There are changes in the following repositories: | -- | -- | -- | -- | -- | -- | <%_ } -%> <%_ scores.forEach( score => { -%> -| [<%= score.org %>/<%= score.repo %>](https://<%= score.platform %>/<%= score.org %>/<%= score.repo %>) | [<%= score.commit.slice(0, 7) %>](https://<%= score.platform %>/<%= score.org %>/<%= score.repo %>/commit/<%= score.commit %>) | <%= score.score %> | <%= score.currentDiff || 0 %> | [Full Report](https://deps.dev/project/github/<%= score.org.toLowerCase() %>%2F<%= score.repo.toLowerCase() %>) | [Fix it](http://app.stepsecurity.io/securerepo?repo=<%= score.org %>/<%= score.repo %>) | +| [<%= score.org %>/<%= score.repo %>](https://<%= score.platform %>/<%= score.org %>/<%= score.repo %>) | [<%= score.commit.slice(0, 7) %>](https://<%= score.platform %>/<%= score.org %>/<%= score.repo %>/commit/<%= score.commit %>) | <% if (!renderBadge) { -%><%= score.score %> <%_ } -%> <%_ if (renderBadge) { -%> [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/<%= score.org %>/<%= score.repo %>/badge)](https://api.securityscorecards.dev/projects/github.com/<%= score.org %>/<%= score.repo %>) <%_ } -%> | <%= score.currentDiff || 0 %> | [Full Report](https://deps.dev/project/github/<%= score.org.toLowerCase() %>%2F<%= score.repo.toLowerCase() %>) | [Fix it](http://app.stepsecurity.io/securerepo?repo=<%= score.org %>/<%= score.repo %>) | <%_ }); -%> _Report generated by [UlisesGascon/openssf-scorecard-monitor](https://github.com/UlisesGascon/openssf-scorecard-monitor)._ \ No newline at end of file diff --git a/dist/report.ejs b/dist/report.ejs index 9287243..03adb08 100644 --- a/dist/report.ejs +++ b/dist/report.ejs @@ -9,7 +9,7 @@ | -- | -- | -- | -- | -- | -- | -- | <%_ } -%> <%_ scores.forEach( score => { -%> -| [<%= score.org %>/<%= score.repo %>](https://<%= score.platform %>/<%= score.org %>/<%= score.repo %>) | [<%= score.commit.slice(0, 7) %>](https://<%= score.platform %>/<%= score.org %>/<%= score.repo %>/commit/<%= score.commit %>) | <%= score.score %> | <%= score.date %> | <%= score.currentDiff || 0 %> | [Full Report](https://deps.dev/project/github/<%= score.org.toLowerCase() %>%2F<%= score.repo.toLowerCase() %>) | [Fix it](http://app.stepsecurity.io/securerepo?repo=<%= score.org %>/<%= score.repo %>) | +| [<%= score.org %>/<%= score.repo %>](https://<%= score.platform %>/<%= score.org %>/<%= score.repo %>) | [<%= score.commit.slice(0, 7) %>](https://<%= score.platform %>/<%= score.org %>/<%= score.repo %>/commit/<%= score.commit %>) | <% if (!renderBadge) { -%><%= score.score %> <%_ } -%><% if (renderBadge) { -%> [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/<%= score.org %>/<%= score.repo %>/badge)](https://api.securityscorecards.dev/projects/github.com/<%= score.org %>/<%= score.repo %>) <%_ } -%> | <%= score.date %> | <%= score.currentDiff || 0 %> | [Full Report](https://deps.dev/project/github/<%= score.org.toLowerCase() %>%2F<%= score.repo.toLowerCase() %>) | [Fix it](http://app.stepsecurity.io/securerepo?repo=<%= score.org %>/<%= score.repo %>) | <%_ }); -%> _Report generated by [UlisesGascon/openssf-scorecard-monitor](https://github.com/UlisesGascon/openssf-scorecard-monitor)._ \ No newline at end of file diff --git a/src/action.js b/src/action.js index 0a20e38..a8e7025 100644 --- a/src/action.js +++ b/src/action.js @@ -31,6 +31,7 @@ async function run () { const reportTagsEnabled = normalizeBoolean(core.getInput('report-tags-enabled')) const startTag = core.getInput('report-start-tag') || '' const endTag = core.getInput('report-end-tag') || '' + const renderBadge = normalizeBoolean(core.getInput('render-badge')) // Error Handling if (!githubToken && [autoPush, autoCommit, generateIssue, discoveryEnabled].some(value => value)) { @@ -91,7 +92,7 @@ async function run () { // PROCESS core.info('Generating scores...') - const { reportContent, issueContent, database: newDatabaseState } = await generateScores({ scope, database, maxRequestInParallel, reportTagsEnabled }) + const { reportContent, issueContent, database: newDatabaseState } = await generateScores({ scope, database, maxRequestInParallel, reportTagsEnabled, renderBadge }) core.info('Checking database changes...') const hasChanges = isDifferent(database, newDatabaseState) diff --git a/src/index.js b/src/index.js index 863c646..a29156c 100644 --- a/src/index.js +++ b/src/index.js @@ -98,7 +98,7 @@ const generateScope = async ({ octokit, orgs, scope, maxRequestInParallel }) => return newScope } -const generateScores = async ({ scope, database: currentDatabase, maxRequestInParallel, reportTagsEnabled }) => { +const generateScores = async ({ scope, database: currentDatabase, maxRequestInParallel, reportTagsEnabled, renderBadge }) => { // @TODO: Improve deep clone logic const database = JSON.parse(JSON.stringify(currentDatabase)) const platform = 'github.com' @@ -157,8 +157,8 @@ const generateScores = async ({ scope, database: currentDatabase, maxRequestInPa core.debug('All the scores are already collected') - const reportContent = await generateReportContent(scores, reportTagsEnabled) - const issueContent = await generateIssueContent(scores) + const reportContent = await generateReportContent(scores, reportTagsEnabled, renderBadge) + const issueContent = await generateIssueContent(scores, renderBadge) // SET OUTPUTS core.setOutput('scores', scores) diff --git a/src/utils.js b/src/utils.js index e7f7c0e..901d4b0 100644 --- a/src/utils.js +++ b/src/utils.js @@ -42,20 +42,20 @@ const saveScore = ({ database, platform, org, repo, score, date, commit }) => { repoRef.current = { score, date, commit } } -const generateReportContent = async (scores, reportTagsEnabled) => { +const generateReportContent = async (scores, reportTagsEnabled, renderBadge) => { core.debug('Generating report content') const template = await readFile(join(process.cwd(), 'templates/report.ejs'), 'utf8') - return ejs.render(template, { scores, reportTagsEnabled }) + return ejs.render(template, { scores, reportTagsEnabled, renderBadge }) } -const generateIssueContent = async (scores) => { +const generateIssueContent = async (scores, renderBadge) => { core.debug('Generating issue content') const scoresInScope = scores.filter(({ currentDiff }) => currentDiff) if (!scoresInScope.length) { return null } const template = await readFile(join(process.cwd(), 'templates/issue.ejs'), 'utf8') - return ejs.render(template, { scores: scoresInScope }) + return ejs.render(template, { scores: scoresInScope, renderBadge }) } module.exports = { diff --git a/templates/issue.ejs b/templates/issue.ejs index b2f178a..d2e5236 100644 --- a/templates/issue.ejs +++ b/templates/issue.ejs @@ -13,7 +13,7 @@ There are changes in the following repositories: | -- | -- | -- | -- | -- | -- | <%_ } -%> <%_ scores.forEach( score => { -%> -| [<%= score.org %>/<%= score.repo %>](https://<%= score.platform %>/<%= score.org %>/<%= score.repo %>) | [<%= score.commit.slice(0, 7) %>](https://<%= score.platform %>/<%= score.org %>/<%= score.repo %>/commit/<%= score.commit %>) | <%= score.score %> | <%= score.currentDiff || 0 %> | [Full Report](https://deps.dev/project/github/<%= score.org.toLowerCase() %>%2F<%= score.repo.toLowerCase() %>) | [Fix it](http://app.stepsecurity.io/securerepo?repo=<%= score.org %>/<%= score.repo %>) | +| [<%= score.org %>/<%= score.repo %>](https://<%= score.platform %>/<%= score.org %>/<%= score.repo %>) | [<%= score.commit.slice(0, 7) %>](https://<%= score.platform %>/<%= score.org %>/<%= score.repo %>/commit/<%= score.commit %>) | <% if (!renderBadge) { -%><%= score.score %> <%_ } -%> <%_ if (renderBadge) { -%> [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/<%= score.org %>/<%= score.repo %>/badge)](https://api.securityscorecards.dev/projects/github.com/<%= score.org %>/<%= score.repo %>) <%_ } -%> | <%= score.currentDiff || 0 %> | [Full Report](https://deps.dev/project/github/<%= score.org.toLowerCase() %>%2F<%= score.repo.toLowerCase() %>) | [Fix it](http://app.stepsecurity.io/securerepo?repo=<%= score.org %>/<%= score.repo %>) | <%_ }); -%> _Report generated by [UlisesGascon/openssf-scorecard-monitor](https://github.com/UlisesGascon/openssf-scorecard-monitor)._ \ No newline at end of file diff --git a/templates/report.ejs b/templates/report.ejs index 9287243..03adb08 100644 --- a/templates/report.ejs +++ b/templates/report.ejs @@ -9,7 +9,7 @@ | -- | -- | -- | -- | -- | -- | -- | <%_ } -%> <%_ scores.forEach( score => { -%> -| [<%= score.org %>/<%= score.repo %>](https://<%= score.platform %>/<%= score.org %>/<%= score.repo %>) | [<%= score.commit.slice(0, 7) %>](https://<%= score.platform %>/<%= score.org %>/<%= score.repo %>/commit/<%= score.commit %>) | <%= score.score %> | <%= score.date %> | <%= score.currentDiff || 0 %> | [Full Report](https://deps.dev/project/github/<%= score.org.toLowerCase() %>%2F<%= score.repo.toLowerCase() %>) | [Fix it](http://app.stepsecurity.io/securerepo?repo=<%= score.org %>/<%= score.repo %>) | +| [<%= score.org %>/<%= score.repo %>](https://<%= score.platform %>/<%= score.org %>/<%= score.repo %>) | [<%= score.commit.slice(0, 7) %>](https://<%= score.platform %>/<%= score.org %>/<%= score.repo %>/commit/<%= score.commit %>) | <% if (!renderBadge) { -%><%= score.score %> <%_ } -%><% if (renderBadge) { -%> [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/<%= score.org %>/<%= score.repo %>/badge)](https://api.securityscorecards.dev/projects/github.com/<%= score.org %>/<%= score.repo %>) <%_ } -%> | <%= score.date %> | <%= score.currentDiff || 0 %> | [Full Report](https://deps.dev/project/github/<%= score.org.toLowerCase() %>%2F<%= score.repo.toLowerCase() %>) | [Fix it](http://app.stepsecurity.io/securerepo?repo=<%= score.org %>/<%= score.repo %>) | <%_ }); -%> _Report generated by [UlisesGascon/openssf-scorecard-monitor](https://github.com/UlisesGascon/openssf-scorecard-monitor)._ \ No newline at end of file