2424
2525// Github API URL for the kata-container ci-nightly workflow's runs. This
2626// will only get the most recent 10 runs ('page' is empty, and 'per_page=10').
27- var ci_nightly_runs_url =
27+ const ci_nightly_runs_url =
2828 "https://api.github.com/repos/" +
2929 "kata-containers/kata-containers/actions/workflows/" +
3030 "ci-nightly.yaml/runs?per_page=10" ;
@@ -34,34 +34,28 @@ var ci_nightly_runs_url =
3434// Current approach (there may be better alternatives) is to:
3535// 1. retrieve the last 10 closed PRs
3636// 2. fetch the checks for each PR (using the head commit SHA)
37- var pull_requests_url =
37+ const pull_requests_url =
3838 "https://api.github.com/repos/" +
3939 "kata-containers/kata-containers/pulls?state=closed&per_page=" ;
40- var pr_checks_url = // for our purposes, 'check' refers to a job in the context of a PR
40+ const pr_checks_url = // for our purposes, 'check' refers to a job in the context of a PR
4141 "https://api.github.com/repos/" +
4242 "kata-containers/kata-containers/commits/" ; // will be followed by {commit_sha}/check-runs
4343 // Max of 100 per page, w/ little *over* 300 checks total, so that's 40 calls total for 10 PRs
4444
4545// Github API URL for the main branch of the kata-containers repo.
4646// Used to get the list of required jobs.
47- var main_branch_url =
48- "https://api.github.com/repos/" +
49- "kata-containers/kata-containers/branches/main" ;
50-
51- // Github API URL for the main branch of the kata-containers repo.
52- // Used to get the list of required jobs.
53- var main_branch_url =
47+ const main_branch_url =
5448 "https://api.github.com/repos/" +
5549 "kata-containers/kata-containers/branches/main" ;
5650
5751// The number of jobs to fetch from the github API on each paged request.
58- var jobs_per_request = 100 ;
52+ const jobs_per_request = 100 ;
5953// The last X closed PRs to retrieve
60- var pr_count = 5 ;
54+ const pr_count = 5 ;
6155// Complete list of jobs (from the CI nightly run)
62- var job_names = new Set ( ) ;
56+ const job_names = new Set ( ) ;
6357// Count of the number of fetches
64- var fetch_count = 0 ;
58+ let fetch_count = 0 ;
6559
6660// Perform a github API request for workflow runs.
6761async function fetch_workflow_runs ( ) {
@@ -111,7 +105,7 @@ function get_job_data(run) {
111105 // Perform the actual (paged) request
112106 async function fetch_jobs_by_page ( which_page ) {
113107 fetch_count ++ ;
114- var jobs_url =
108+ const jobs_url =
115109 run [ "jobs_url" ] + "?per_page=" + jobs_per_request + "&page=" + which_page ;
116110 return fetch ( jobs_url , {
117111 headers : {
@@ -145,7 +139,7 @@ function get_job_data(run) {
145139 } ) ;
146140 }
147141
148- var run_with_job_data = {
142+ const run_with_job_data = {
149143 id : run [ "id" ] ,
150144 run_number : run [ "run_number" ] ,
151145 created_at : run [ "created_at" ] ,
@@ -165,7 +159,7 @@ function get_check_data(pr) {
165159 // Perform a github API request for a list of commits for a PR (takes in the PR's head commit SHA)
166160 async function fetch_checks_by_page ( which_page ) {
167161 fetch_count ++ ;
168- var checks_url =
162+ const checks_url =
169163 pr_checks_url + prs_with_check_data [ "commit_sha" ] + "/check-runs" + "?per_page=" + jobs_per_request + "&page=" + which_page ;
170164 return fetch ( checks_url , {
171165 headers : {
@@ -206,7 +200,7 @@ function get_check_data(pr) {
206200 }
207201
208202 // Extract list of objects with PR commit SHAs, PR URLs, and PR number (i.e. id)
209- var prs_with_check_data = {
203+ const prs_with_check_data = {
210204 html_url : pr [ "html_url" ] , // link to PR page
211205 number : pr [ "number" ] , // PR number (used as PR id); displayed on dashboard
212206 commit_sha : pr [ "head" ] [ "sha" ] , // For getting checks run on PR branch
@@ -220,14 +214,14 @@ function get_check_data(pr) {
220214
221215// Extract list of required jobs (i.e. main branch details: protection: required_status_checks: contexts)
222216function get_required_jobs ( main_branch ) {
223- var required_jobs = main_branch [ "protection" ] [ "required_status_checks" ] [ "contexts" ] ;
217+ const required_jobs = main_branch [ "protection" ] [ "required_status_checks" ] [ "contexts" ] ;
224218 // console.log('required jobs: ', required_jobs);
225219 return required_jobs ;
226220}
227221
228222// Calculate and return job stats across all runs
229223function compute_job_stats ( runs_with_job_data , prs_with_check_data , required_jobs ) {
230- var job_stats = { } ;
224+ const job_stats = { } ;
231225 for ( const run of runs_with_job_data ) {
232226 for ( const job of run [ "jobs" ] ) {
233227 if ( ! ( job [ "name" ] in job_stats ) ) {
@@ -247,7 +241,7 @@ function compute_job_stats(runs_with_job_data, prs_with_check_data, required_job
247241 pr_nums : [ ] , // list of PR numbers that this job is associated with
248242 } ;
249243 }
250- var job_stat = job_stats [ job [ "name" ] ] ;
244+ const job_stat = job_stats [ job [ "name" ] ] ;
251245 job_stat [ "runs" ] += 1 ;
252246 job_stat [ "run_nums" ] . push ( run [ "run_number" ] ) ;
253247 job_stat [ "urls" ] . push ( job [ "html_url" ] ) ;
@@ -269,7 +263,7 @@ function compute_job_stats(runs_with_job_data, prs_with_check_data, required_job
269263 for ( const pr of prs_with_check_data ) {
270264 for ( const check of pr [ "checks" ] ) {
271265 if ( ( check [ "name" ] in job_stats ) ) {
272- var job_stat = job_stats [ check [ "name" ] ] ;
266+ const job_stat = job_stats [ check [ "name" ] ] ;
273267 job_stat [ "pr_runs" ] += 1 ;
274268 job_stat [ "pr_urls" ] . push ( pr [ "html_url" ] )
275269 job_stat [ "pr_nums" ] . push ( pr [ "number" ] )
@@ -293,26 +287,26 @@ function compute_job_stats(runs_with_job_data, prs_with_check_data, required_job
293287
294288async function main ( ) {
295289 // Fetch recent workflow runs via the github API
296- var workflow_runs = await fetch_workflow_runs ( ) ;
290+ const workflow_runs = await fetch_workflow_runs ( ) ;
297291
298292 // Fetch required jobs from main branch
299- var main_branch = await fetch_main_branch ( ) ;
300- var required_jobs = get_required_jobs ( main_branch ) ;
293+ const main_branch = await fetch_main_branch ( ) ;
294+ const required_jobs = get_required_jobs ( main_branch ) ;
301295
302296 // Fetch job data for each of the runs.
303297 // Store all of this in an array of maps, runs_with_job_data.
304- var promises_buf = [ ] ;
298+ const promises_buf = [ ] ;
305299 for ( const run of workflow_runs [ "workflow_runs" ] ) {
306300 promises_buf . push ( get_job_data ( run ) ) ;
307301 }
308302 runs_with_job_data = await Promise . all ( promises_buf ) ;
309303
310304 // Fetch recent pull requests via the github API
311- var pull_requests = await fetch_pull_requests ( ) ;
305+ const pull_requests = await fetch_pull_requests ( ) ;
312306
313307 // Fetch last pr_count closed PRs
314308 // Store all of this in an array of maps, prs_with_check_data.
315- var promises_buffer = [ ] ;
309+ const promises_buffer = [ ] ;
316310 for ( const pr of pull_requests ) {
317311 promises_buffer . push ( get_check_data ( pr ) ) ;
318312 }
@@ -321,7 +315,7 @@ async function main() {
321315 // Transform the raw details of each run and its jobs' results into a
322316 // an array of just the jobs and their overall results (e.g. pass or fail,
323317 // and the URLs associated with them).
324- var job_stats = compute_job_stats ( runs_with_job_data , prs_with_check_data , required_jobs ) ;
318+ const job_stats = compute_job_stats ( runs_with_job_data , prs_with_check_data , required_jobs ) ;
325319
326320 // Write the job_stats to console as a JSON object
327321 console . log ( JSON . stringify ( job_stats ) ) ;
0 commit comments