|
| 1 | +#' Retrieve latest GitHub workflow results from Rest API |
| 2 | +#' |
| 3 | +#' This uses default of 30 most recent results. |
| 4 | +#' @noRd |
| 5 | +github_repo_workflow_query <- function (org = NULL, repo = NULL, n = 30L) { |
| 6 | + |
| 7 | + checkmate::assert_integer (n, lower = 1L) |
| 8 | + u_base <- "https://api.github.com/repos/" |
| 9 | + u_repo <- paste0 (u_base, org, "/", repo, "/") |
| 10 | + u_wf <- paste0 (u_repo, "actions/runs?per_page=", n) |
| 11 | + |
| 12 | + req <- httr2::request (u_wf) |
| 13 | + |
| 14 | + if (!nzchar (Sys.getenv ("GITHUB_WORKFLOW"))) { |
| 15 | + tok <- get_gh_token () |
| 16 | + headers <- list (Authorization = paste0 ("Bearer ", tok)) |
| 17 | + req <- httr2::req_headers (req, "Authorization" = headers) |
| 18 | + } |
| 19 | + |
| 20 | + resp <- httr2::req_perform (req) |
| 21 | + httr2::resp_check_status (resp) |
| 22 | + |
| 23 | + body <- httr2::resp_body_json (resp) |
| 24 | + workflows <- body$workflow_runs |
| 25 | + |
| 26 | + ids <- vapply (workflows, function (i) i$id, numeric (1L)) |
| 27 | + names <- vapply (workflows, function (i) i$name, character (1L)) |
| 28 | + shas <- vapply (workflows, function (i) i$head_sha, character (1L)) |
| 29 | + titles <- vapply (workflows, function (i) i$display_title, character (1L)) |
| 30 | + status <- vapply (workflows, function (i) i$status, character (1L)) |
| 31 | + conclusion <- vapply (workflows, function (i) i$conclusion, character (1L)) |
| 32 | + created <- vapply (workflows, function (i) i$created_at, character (1L)) |
| 33 | + created <- as.POSIXct (created, format = "%Y-%m-%dT%H:%M:%S", tz = "UTC") |
| 34 | + |
| 35 | + data.frame ( |
| 36 | + name = names, |
| 37 | + id = ids, |
| 38 | + sha = shas, |
| 39 | + title = titles, |
| 40 | + status = status, |
| 41 | + conclusion = conclusion, |
| 42 | + created = created |
| 43 | + ) |
| 44 | +} |
0 commit comments