Skip to content

Commit 6c1d547

Browse files
authored
Merge pull request #46 from rajbos/main
Enable support for OpenSSF Badges instead of only scores
2 parents c6d7c04 + c53d679 commit 6c1d547

File tree

10 files changed

+30
-24
lines changed

10 files changed

+30
-24
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ jobs:
109109
- `max-request-in-parallel`: Defines the total HTTP Request that can be done in parallel
110110
- `discovery-enabled`: Defined if the discovery is enabled
111111
- `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)
112-
- `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.
113-
- `report-start-tag`: Defines the start tag, default `<!-- OPENSSF-SCORECARD-MONITOR:START -->`
114-
- `report-end-tag` Defines the closing tag, default `<!-- OPENSSF-SCORECARD-MONITOR:END -->`
115-
112+
- `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
113+
- `report-start-tag` Defines the start tag, default `<!-- OPENSSF-SCORECARD-MONITOR:START -->`
114+
- `report-end-tag`: Defines the closing tag, default `<!-- OPENSSF-SCORECARD-MONITOR:END -->`
115+
- `render-badge`: Defines if the OpenSSF badge must be rendered in the reportor to only show the score
116116

117117
### Outputs
118118

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ inputs:
5555
description: 'Maximum number of HTTP requests to be executed in parallel'
5656
required: false
5757
default: "10"
58+
render-badge:
59+
description: 'Render the OSSF badge in the report'
60+
required: false
61+
default: "false"
5862

5963
outputs:
6064
scores:

dist/index.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27711,7 +27711,7 @@ const generateScope = async ({ octokit, orgs, scope, maxRequestInParallel }) =>
2771127711
return newScope
2771227712
}
2771327713

27714-
const generateScores = async ({ scope, database: currentDatabase, maxRequestInParallel, reportTagsEnabled }) => {
27714+
const generateScores = async ({ scope, database: currentDatabase, maxRequestInParallel, reportTagsEnabled, renderBadge }) => {
2771527715
// @TODO: Improve deep clone logic
2771627716
const database = JSON.parse(JSON.stringify(currentDatabase))
2771727717
const platform = 'github.com'
@@ -27770,8 +27770,8 @@ const generateScores = async ({ scope, database: currentDatabase, maxRequestInPa
2777027770

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

27773-
const reportContent = await generateReportContent(scores, reportTagsEnabled)
27774-
const issueContent = await generateIssueContent(scores)
27773+
const reportContent = await generateReportContent(scores, reportTagsEnabled, renderBadge)
27774+
const issueContent = await generateIssueContent(scores, renderBadge)
2777527775

2777627776
// SET OUTPUTS
2777727777
core.setOutput('scores', scores)
@@ -27834,20 +27834,20 @@ const saveScore = ({ database, platform, org, repo, score, date, commit }) => {
2783427834
repoRef.current = { score, date, commit }
2783527835
}
2783627836

27837-
const generateReportContent = async (scores, reportTagsEnabled) => {
27837+
const generateReportContent = async (scores, reportTagsEnabled, renderBadge) => {
2783827838
core.debug('Generating report content')
2783927839
const template = await readFile(__nccwpck_require__.ab + "report.ejs", 'utf8')
27840-
return ejs.render(template, { scores, reportTagsEnabled })
27840+
return ejs.render(template, { scores, reportTagsEnabled, renderBadge })
2784127841
}
2784227842

27843-
const generateIssueContent = async (scores) => {
27843+
const generateIssueContent = async (scores, renderBadge) => {
2784427844
core.debug('Generating issue content')
2784527845
const scoresInScope = scores.filter(({ currentDiff }) => currentDiff)
2784627846
if (!scoresInScope.length) {
2784727847
return null
2784827848
}
2784927849
const template = await readFile(__nccwpck_require__.ab + "issue.ejs", 'utf8')
27850-
return ejs.render(template, { scores: scoresInScope })
27850+
return ejs.render(template, { scores: scoresInScope, renderBadge })
2785127851
}
2785227852

2785327853
module.exports = {
@@ -28161,6 +28161,7 @@ async function run () {
2816128161
const reportTagsEnabled = normalizeBoolean(core.getInput('report-tags-enabled'))
2816228162
const startTag = core.getInput('report-start-tag') || '<!-- OPENSSF-SCORECARD-MONITOR:START -->'
2816328163
const endTag = core.getInput('report-end-tag') || '<!-- OPENSSF-SCORECARD-MONITOR:END -->'
28164+
const renderBadge = normalizeBoolean(core.getInput('render-badge'))
2816428165

2816528166
// Error Handling
2816628167
if (!githubToken && [autoPush, autoCommit, generateIssue, discoveryEnabled].some(value => value)) {
@@ -28221,7 +28222,7 @@ async function run () {
2822128222

2822228223
// PROCESS
2822328224
core.info('Generating scores...')
28224-
const { reportContent, issueContent, database: newDatabaseState } = await generateScores({ scope, database, maxRequestInParallel, reportTagsEnabled })
28225+
const { reportContent, issueContent, database: newDatabaseState } = await generateScores({ scope, database, maxRequestInParallel, reportTagsEnabled, renderBadge })
2822528226

2822628227
core.info('Checking database changes...')
2822728228
const hasChanges = isDifferent(database, newDatabaseState)

dist/issue.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ There are changes in the following repositories:
1313
| -- | -- | -- | -- | -- | -- |
1414
<%_ } -%>
1515
<%_ scores.forEach( score => { -%>
16-
| [<%= 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 %>) |
16+
| [<%= 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 %>) |
1717
<%_ }); -%>
1818
1919
_Report generated by [UlisesGascon/openssf-scorecard-monitor](https://github.com/UlisesGascon/openssf-scorecard-monitor)._

dist/report.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| -- | -- | -- | -- | -- | -- | -- |
1010
<%_ } -%>
1111
<%_ scores.forEach( score => { -%>
12-
| [<%= 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 %>) |
12+
| [<%= 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 %>) |
1313
<%_ }); -%>
1414
1515
_Report generated by [UlisesGascon/openssf-scorecard-monitor](https://github.com/UlisesGascon/openssf-scorecard-monitor)._

src/action.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ async function run () {
3131
const reportTagsEnabled = normalizeBoolean(core.getInput('report-tags-enabled'))
3232
const startTag = core.getInput('report-start-tag') || '<!-- OPENSSF-SCORECARD-MONITOR:START -->'
3333
const endTag = core.getInput('report-end-tag') || '<!-- OPENSSF-SCORECARD-MONITOR:END -->'
34+
const renderBadge = normalizeBoolean(core.getInput('render-badge'))
3435

3536
// Error Handling
3637
if (!githubToken && [autoPush, autoCommit, generateIssue, discoveryEnabled].some(value => value)) {
@@ -91,7 +92,7 @@ async function run () {
9192

9293
// PROCESS
9394
core.info('Generating scores...')
94-
const { reportContent, issueContent, database: newDatabaseState } = await generateScores({ scope, database, maxRequestInParallel, reportTagsEnabled })
95+
const { reportContent, issueContent, database: newDatabaseState } = await generateScores({ scope, database, maxRequestInParallel, reportTagsEnabled, renderBadge })
9596

9697
core.info('Checking database changes...')
9798
const hasChanges = isDifferent(database, newDatabaseState)

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const generateScope = async ({ octokit, orgs, scope, maxRequestInParallel }) =>
9898
return newScope
9999
}
100100

101-
const generateScores = async ({ scope, database: currentDatabase, maxRequestInParallel, reportTagsEnabled }) => {
101+
const generateScores = async ({ scope, database: currentDatabase, maxRequestInParallel, reportTagsEnabled, renderBadge }) => {
102102
// @TODO: Improve deep clone logic
103103
const database = JSON.parse(JSON.stringify(currentDatabase))
104104
const platform = 'github.com'
@@ -157,8 +157,8 @@ const generateScores = async ({ scope, database: currentDatabase, maxRequestInPa
157157

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

160-
const reportContent = await generateReportContent(scores, reportTagsEnabled)
161-
const issueContent = await generateIssueContent(scores)
160+
const reportContent = await generateReportContent(scores, reportTagsEnabled, renderBadge)
161+
const issueContent = await generateIssueContent(scores, renderBadge)
162162

163163
// SET OUTPUTS
164164
core.setOutput('scores', scores)

src/utils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@ const saveScore = ({ database, platform, org, repo, score, date, commit }) => {
4242
repoRef.current = { score, date, commit }
4343
}
4444

45-
const generateReportContent = async (scores, reportTagsEnabled) => {
45+
const generateReportContent = async (scores, reportTagsEnabled, renderBadge) => {
4646
core.debug('Generating report content')
4747
const template = await readFile(join(process.cwd(), 'templates/report.ejs'), 'utf8')
48-
return ejs.render(template, { scores, reportTagsEnabled })
48+
return ejs.render(template, { scores, reportTagsEnabled, renderBadge })
4949
}
5050

51-
const generateIssueContent = async (scores) => {
51+
const generateIssueContent = async (scores, renderBadge) => {
5252
core.debug('Generating issue content')
5353
const scoresInScope = scores.filter(({ currentDiff }) => currentDiff)
5454
if (!scoresInScope.length) {
5555
return null
5656
}
5757
const template = await readFile(join(process.cwd(), 'templates/issue.ejs'), 'utf8')
58-
return ejs.render(template, { scores: scoresInScope })
58+
return ejs.render(template, { scores: scoresInScope, renderBadge })
5959
}
6060

6161
module.exports = {

templates/issue.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ There are changes in the following repositories:
1313
| -- | -- | -- | -- | -- | -- |
1414
<%_ } -%>
1515
<%_ scores.forEach( score => { -%>
16-
| [<%= 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 %>) |
16+
| [<%= 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 %>) |
1717
<%_ }); -%>
1818
1919
_Report generated by [UlisesGascon/openssf-scorecard-monitor](https://github.com/UlisesGascon/openssf-scorecard-monitor)._

templates/report.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| -- | -- | -- | -- | -- | -- | -- |
1010
<%_ } -%>
1111
<%_ scores.forEach( score => { -%>
12-
| [<%= 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 %>) |
12+
| [<%= 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 %>) |
1313
<%_ }); -%>
1414
1515
_Report generated by [UlisesGascon/openssf-scorecard-monitor](https://github.com/UlisesGascon/openssf-scorecard-monitor)._

0 commit comments

Comments
 (0)