Skip to content

Commit

Permalink
Merge pull request #21 from UlisesGascon/feat/12
Browse files Browse the repository at this point in the history
feat: added commit reference to reports
  • Loading branch information
UlisesGascon committed Feb 21, 2023
2 parents cce1de6 + 1961dd0 commit 09d05c9
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
14 changes: 7 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20004,15 +20004,15 @@ const generateScores = async ({ scope, database: currentDatabase, maxRequestInPa
core.debug(`Processing chunk ${index + 1}/${chunks.length}`)

const chunkScores = await Promise.all(chunk.map(async ({ org, repo }) => {
const { score, date } = await getProjectScore({ platform, org, repo })
const { score, date, commit } = await getProjectScore({ platform, org, repo })
core.debug(`Got project score for ${platform}/${org}/${repo}: ${score} (${date})`)

const storedScore = getScore({ database, platform, org, repo })

const scoreData = { platform, org, repo, score, date }
const scoreData = { platform, org, repo, score, date, commit }
// If no stored score then record if score is different then:
if (!storedScore || storedScore.score !== score) {
saveScore({ database, platform, org, repo, score, date })
saveScore({ database, platform, org, repo, score, date, commit })
}

// Add previous score and date if available to the report
Expand Down Expand Up @@ -20062,24 +20062,24 @@ const { softAssign } = __nccwpck_require__(7348)
const getProjectScore = async ({ platform, org, repo }) => {
core.debug(`Getting project score for ${platform}/${org}/${repo}`)
const response = await got(`https://api.securityscorecards.dev/projects/${platform}/${org}/${repo}`)
const { score, date } = JSON.parse(response.body)
const { score, date, repo: { commit } = {} } = JSON.parse(response.body)
core.debug(`Got project score for ${platform}/${org}/${repo}: ${score} (${date})`)
return { platform, org, repo, score, date }
return { platform, org, repo, score, date, commit }
}

const getScore = ({ database, platform, org, repo }) => {
const { current } = database?.[platform]?.[org]?.[repo] || {}
return current || null
}

const saveScore = ({ database, platform, org, repo, score, date }) => {
const saveScore = ({ database, platform, org, repo, score, date, commit }) => {
softAssign(database, [platform, org, repo, 'previous'], [])
const repoRef = database[platform][org][repo]

if (repoRef.current) {
repoRef.previous.push(repoRef.current)
}
repoRef.current = { score, date }
repoRef.current = { score, date, commit }
}

const generateReportContent = async (scores) => {
Expand Down
6 changes: 3 additions & 3 deletions dist/issue.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ Please review the following changes and take action if necessary.
There are changes in the following repositories:

<%_ if (scores.length) { -%>
| Repository | Score | Difference | Report Link |
| -- | -- | -- | -- |
| Repository | Commit | Score | Difference | Report Link |
| -- | -- | -- | -- | -- |
<%_ } -%>
<%_ scores.forEach( score => { -%>
| [<%= score.org %>/<%= score.repo %>](https://<%= score.platform %>/<%= score.org %>/<%= score.repo %>) | <%= score.score %> | <%= score.currentDiff || 0 %> | [Full Report](https://deps.dev/project/github/<%= score.org.toLowerCase() %>%2F<%= score.repo.toLowerCase() %>) |
| [<%= 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() %>) |
<%_ }); -%>
_Report generated by [UlisesGascon/openssf-scorecard-monitor](https://github.com/UlisesGascon/openssf-scorecard-monitor)._
6 changes: 3 additions & 3 deletions dist/report.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
## Summary

<%_ if (scores.length) { -%>
| Repository | Score | Date | Difference | Report Link |
| -- | -- | -- | -- | -- |
| Repository | Commit | Score | Date | Difference | Report Link |
| -- | -- | -- | -- | -- | -- |
<%_ } -%>
<%_ scores.forEach( score => { -%>
| [<%= score.org %>/<%= score.repo %>](https://<%= score.platform %>/<%= score.org %>/<%= score.repo %>) | <%= score.score %> | <%= score.date %> | <%= score.currentDiff || 0 %> | [Full Report](https://deps.dev/project/github/<%= score.org.toLowerCase() %>%2F<%= score.repo.toLowerCase() %>) |
| [<%= 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() %>) |
<%_ }); -%>
_Report generated by [UlisesGascon/openssf-scorecard-monitor](https://github.com/UlisesGascon/openssf-scorecard-monitor)._
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ const generateScores = async ({ scope, database: currentDatabase, maxRequestInPa
core.debug(`Processing chunk ${index + 1}/${chunks.length}`)

const chunkScores = await Promise.all(chunk.map(async ({ org, repo }) => {
const { score, date } = await getProjectScore({ platform, org, repo })
const { score, date, commit } = await getProjectScore({ platform, org, repo })
core.debug(`Got project score for ${platform}/${org}/${repo}: ${score} (${date})`)

const storedScore = getScore({ database, platform, org, repo })

const scoreData = { platform, org, repo, score, date }
const scoreData = { platform, org, repo, score, date, commit }
// If no stored score then record if score is different then:
if (!storedScore || storedScore.score !== score) {
saveScore({ database, platform, org, repo, score, date })
saveScore({ database, platform, org, repo, score, date, commit })
}

// Add previous score and date if available to the report
Expand Down
8 changes: 4 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ const { softAssign } = require('@ulisesgascon/soft-assign-deep-property')
const getProjectScore = async ({ platform, org, repo }) => {
core.debug(`Getting project score for ${platform}/${org}/${repo}`)
const response = await got(`https://api.securityscorecards.dev/projects/${platform}/${org}/${repo}`)
const { score, date } = JSON.parse(response.body)
const { score, date, repo: { commit } = {} } = JSON.parse(response.body)
core.debug(`Got project score for ${platform}/${org}/${repo}: ${score} (${date})`)
return { platform, org, repo, score, date }
return { platform, org, repo, score, date, commit }
}

const getScore = ({ database, platform, org, repo }) => {
const { current } = database?.[platform]?.[org]?.[repo] || {}
return current || null
}

const saveScore = ({ database, platform, org, repo, score, date }) => {
const saveScore = ({ database, platform, org, repo, score, date, commit }) => {
softAssign(database, [platform, org, repo, 'previous'], [])
const repoRef = database[platform][org][repo]

if (repoRef.current) {
repoRef.previous.push(repoRef.current)
}
repoRef.current = { score, date }
repoRef.current = { score, date, commit }
}

const generateReportContent = async (scores) => {
Expand Down
6 changes: 3 additions & 3 deletions templates/issue.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ Please review the following changes and take action if necessary.
There are changes in the following repositories:

<%_ if (scores.length) { -%>
| Repository | Score | Difference | Report Link |
| -- | -- | -- | -- |
| Repository | Commit | Score | Difference | Report Link |
| -- | -- | -- | -- | -- |
<%_ } -%>
<%_ scores.forEach( score => { -%>
| [<%= score.org %>/<%= score.repo %>](https://<%= score.platform %>/<%= score.org %>/<%= score.repo %>) | <%= score.score %> | <%= score.currentDiff || 0 %> | [Full Report](https://deps.dev/project/github/<%= score.org.toLowerCase() %>%2F<%= score.repo.toLowerCase() %>) |
| [<%= 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() %>) |
<%_ }); -%>
_Report generated by [UlisesGascon/openssf-scorecard-monitor](https://github.com/UlisesGascon/openssf-scorecard-monitor)._
6 changes: 3 additions & 3 deletions templates/report.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
## Summary

<%_ if (scores.length) { -%>
| Repository | Score | Date | Difference | Report Link |
| -- | -- | -- | -- | -- |
| Repository | Commit | Score | Date | Difference | Report Link |
| -- | -- | -- | -- | -- | -- |
<%_ } -%>
<%_ scores.forEach( score => { -%>
| [<%= score.org %>/<%= score.repo %>](https://<%= score.platform %>/<%= score.org %>/<%= score.repo %>) | <%= score.score %> | <%= score.date %> | <%= score.currentDiff || 0 %> | [Full Report](https://deps.dev/project/github/<%= score.org.toLowerCase() %>%2F<%= score.repo.toLowerCase() %>) |
| [<%= 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() %>) |
<%_ }); -%>
_Report generated by [UlisesGascon/openssf-scorecard-monitor](https://github.com/UlisesGascon/openssf-scorecard-monitor)._

0 comments on commit 09d05c9

Please sign in to comment.