@@ -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+
135153const 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