From 76a73b3934bc7f42ae0d628889f158362644a469 Mon Sep 17 00:00:00 2001 From: PietrH Date: Thu, 31 Jul 2025 15:56:35 +0200 Subject: [PATCH 1/3] Stub function to get report on most recent deployment of api on test domain. --- R/utils.R | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/R/utils.R b/R/utils.R index 682c0dc..1aded34 100644 --- a/R/utils.R +++ b/R/utils.R @@ -234,3 +234,59 @@ md5sum <- function(str) { # Checksum unname(tools::md5sum(temp_file)) } + + +#' Get the most recent task ID from the etnservice webhook +#' +#' +#' @return The most recent task ID from the etnservice webhook. +#' +#' @examples +#' get_most_recent_task_id() +get_most_recent_task_id <- function() { + # Get the most recent delivery id from the etnservice to VLIZ deployment + # webhook. + most_recent_delivery_id <- + gh::gh("/repos/inbo/etnservice/hooks/518163094/deliveries", + .token = gh::gh_token() + ) |> + purrr::map_dfr(~.x) |> + dplyr::slice_head(n = 1) |> + dplyr::pull(id) + + # Get the task id from the most recent delivery. + task_id <- gh::gh("/repos/inbo/etnservice/hooks/518163094/deliveries/{delivery_id}", + delivery_id = most_recent_delivery_id + ) |> + purrr::chuck("response", "payload") |> + jsonlite::fromJSON() |> + purrr::chuck("id") + + return(task_id) +} + +#' Get the status of a deployment task +#' +#' This function retrieves the status of a deployment task by its task ID from +#' the webhook endpoint. The status is printed to the console. +#' +#' Deployments are triggered by tag creation, and are installed from the +#' live-test branch. +#' +#' This function requires a Github Personal Access Token to be set via +#' gitcreds::gitcreds_set(), organisation and personal read access to webhooks +#' is required, but can be limited to the inbo/etnservice repo. +#' +#' @param task_id The ID of the deployment task to check the status for. +#' +#' @return The status of the deployment task is printed to the console. +#' +#' @examples +get_deploy_status <- function(task_id = get_most_recent_task_id()) { + httr2::request("https://opencpu-test.lifewatch.be/webhook/") |> + httr2::req_url_path_append(task_id) |> + httr2::req_perform() |> + httr2::resp_body_string() |> + stringr::str_replace_all(stringr::fixed("\\n"), "\n") |> + message() +} From 11927b9fdfe23fe958ffd8a9a55cc310fa9b1aeb Mon Sep 17 00:00:00 2001 From: PietrH Date: Thu, 31 Jul 2025 15:57:35 +0200 Subject: [PATCH 2/3] Remove unnecessary whitespace. --- R/utils.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/utils.R b/R/utils.R index 1aded34..b76b435 100644 --- a/R/utils.R +++ b/R/utils.R @@ -238,7 +238,6 @@ md5sum <- function(str) { #' Get the most recent task ID from the etnservice webhook #' -#' #' @return The most recent task ID from the etnservice webhook. #' #' @examples From ce748e31c6c0e00e86fab354b14661bb0c927f15 Mon Sep 17 00:00:00 2001 From: PietrH Date: Thu, 31 Jul 2025 16:01:06 +0200 Subject: [PATCH 3/3] Declare new dependencies --- DESCRIPTION | 2 ++ R/utils.R | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index c8cae82..188a0eb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,6 +29,8 @@ Imports: stringr, utils Suggests: + gh, + httr2, purrr, testthat (>= 3.0.0) Config/testthat/edition: 3 diff --git a/R/utils.R b/R/utils.R index b76b435..26963b2 100644 --- a/R/utils.R +++ b/R/utils.R @@ -243,10 +243,13 @@ md5sum <- function(str) { #' @examples #' get_most_recent_task_id() get_most_recent_task_id <- function() { + # Check if required packages are installed. + rlang::check_installed(c("gh", "purrr")) # Get the most recent delivery id from the etnservice to VLIZ deployment # webhook. most_recent_delivery_id <- - gh::gh("/repos/inbo/etnservice/hooks/518163094/deliveries", + gh::gh("/repos/inbo/etnservice/hooks/{webhook_id}/deliveries", + webhook_id = 518163094, # etnservice to VLIZ deployment webhook .token = gh::gh_token() ) |> purrr::map_dfr(~.x) |> @@ -282,10 +285,14 @@ get_most_recent_task_id <- function() { #' #' @examples get_deploy_status <- function(task_id = get_most_recent_task_id()) { + # Check if required packages are installed. + rlang::check_installed("httr2") + # Fetch the most recent install output. httr2::request("https://opencpu-test.lifewatch.be/webhook/") |> httr2::req_url_path_append(task_id) |> httr2::req_perform() |> httr2::resp_body_string() |> + # Replace the newline characters with actual newlines stringr::str_replace_all(stringr::fixed("\\n"), "\n") |> message() }