Skip to content

Commit d42ec8e

Browse files
committed
feat: add function to fetch all scorecard results and repositories by project id
1 parent 837c0cf commit d42ec8e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/store/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,24 @@ const getAllOwaspTop10TrainingsByProjectIds = (knex, projectIds) => {
132132
.select('*')
133133
}
134134

135+
const getAllScorecardsResultsOfRepositoriesByProjectId = (knex, projectIds) => {
136+
debug(`Fetching all scorecards results of repositories by project id (${projectIds})...`)
137+
138+
if (!Array.isArray(projectIds)) {
139+
throw new Error('projectIds must be an array')
140+
}
141+
142+
return knex('github_organizations')
143+
.select('*')
144+
.whereIn('github_organizations.project_id', projectIds)
145+
.leftJoin('github_repositories', function () {
146+
this.on('github_repositories.github_organization_id', '=', 'github_organizations.id')
147+
})
148+
.leftJoin('ossf_scorecard_results', function () {
149+
this.on('ossf_scorecard_results.github_repository_id', '=', 'github_repositories.id')
150+
})
151+
}
152+
135153
const initializeStore = (knex) => {
136154
debug('Initializing store...')
137155
const getAll = getAllFn(knex)
@@ -147,6 +165,7 @@ const initializeStore = (knex) => {
147165
getAllSSoftwareDesignTrainings: () => getAll('software_design_training'),
148166
getAllOwaspTop10Trainings: () => getAll('owasp_top10_training'),
149167
getAllGithubRepositories: () => getAll('github_repositories'),
168+
getAllScorecardsResultsOfRepositoriesByProjectId: (projectId) => getAllScorecardsResultsOfRepositoriesByProjectId(knex, projectId),
150169
getAllChecklists: () => getAll('compliance_checklists'),
151170
getAllResults: () => getAll('compliance_checks_results'),
152171
getAllTasks: () => getAll('compliance_checks_tasks'),

0 commit comments

Comments
 (0)