-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from rundel/artifacts
Artifacts
- Loading branch information
Showing
30 changed files
with
1,064 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ Makefile | |
^cran-comments\.md$ | ||
^\.github$ | ||
^CRAN-SUBMISSION$ | ||
test/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ inst/doc | |
doc | ||
Meta | ||
vignettes/articles/cache/ | ||
test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
github_api_action_artifacts = function(repo) { | ||
arg_is_chr_scalar(repo) | ||
|
||
ghclass_api_v3_req( | ||
endpoint = "GET /repos/{owner}/{repo}/actions/artifacts", | ||
owner = get_repo_owner(repo), | ||
repo = get_repo_name(repo) | ||
) | ||
} | ||
|
||
#' @name action | ||
#' @rdname action | ||
#' | ||
#' @param repo Character. Address of repositories in `owner/name` format. | ||
#' @param keep_expired Logical. Should expired artifacts be returned. | ||
#' @param which Character. Either `"latest"` to return only the most recent of each | ||
#' artifact or `"all"` to return all artifacts. | ||
#' @export | ||
#' | ||
action_artifacts = function(repo, keep_expired=FALSE, which=c("latest", "all")) { | ||
which = match.arg(which) | ||
|
||
arg_is_chr(repo) | ||
arg_is_chr_scalar(which) | ||
arg_is_lgl_scalar(keep_expired) | ||
|
||
res = purrr::map_dfr( | ||
repo, | ||
function(r) { | ||
res = purrr::safely(github_api_action_artifacts)(r) | ||
status_msg( | ||
res, | ||
fail = "Failed to retrieve artifacts for repo {.val {repo}}." | ||
) | ||
|
||
if (failed(res)) { | ||
NULL | ||
} else if (empty_result(res) || result(res)[["total_count"]] == 0) { | ||
tibble::tibble( | ||
repo = character(), | ||
name = character(), | ||
id = integer(), | ||
size = integer(), | ||
url = character(), | ||
expired = logical(), | ||
created = lubridate::ymd_hms(), | ||
updated = lubridate::ymd_hms(), | ||
expires = lubridate::ymd_hms() | ||
) | ||
} else { | ||
artifacts = result(res)[["artifacts"]] | ||
|
||
tibble::tibble( | ||
repo = r, | ||
name = purrr::map_chr(artifacts, "name", .default = NA), | ||
id = purrr::map_int(artifacts, "id", .default = NA), | ||
size = purrr::map_int(artifacts, "size_in_bytes", .default = NA), | ||
url = purrr::map_chr(artifacts, "url", .default = NA), | ||
expired = purrr::map_lgl(artifacts, "expired", .default = NA), | ||
created = purrr::map_chr(artifacts, "created_at", .default = NA) %>% lubridate::ymd_hms(), | ||
updated = purrr::map_chr(artifacts, "updated_at", .default = NA) %>% lubridate::ymd_hms(), | ||
expires = purrr::map_chr(artifacts, "expires_at", .default = NA) %>% lubridate::ymd_hms() | ||
) | ||
} | ||
} | ||
) | ||
|
||
if (!keep_expired) { | ||
res = dplyr::filter(res, .data[["expired"]] == FALSE) | ||
} | ||
|
||
if (which == "latest") { | ||
res %>% | ||
dplyr::group_by(.data[["repo"]], .data[["name"]]) %>% | ||
dplyr::arrange(dplyr::desc(.data[["created"]])) %>% | ||
dplyr::slice(1) %>% | ||
dplyr::ungroup() | ||
} else if (which == "all") { | ||
res | ||
} else { | ||
cli_stop("Invalid which choice.") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
github_api_delete_artifact = function(repo, id) { | ||
arg_is_chr_scalar(repo) | ||
arg_is_pos_int(id) | ||
|
||
ghclass_api_v3_req( | ||
endpoint = "DELETE /repos/{owner}/{repo}/actions/artifacts/{artifact_id}", | ||
owner = get_repo_owner(repo), | ||
repo = get_repo_name(repo), | ||
artifact_id = id | ||
) | ||
|
||
} | ||
|
||
|
||
#' @name action | ||
#' @rdname action | ||
#' | ||
#' @export | ||
#' | ||
action_artifact_delete = function(repo, ids) { | ||
|
||
arg_is_chr(repo) | ||
|
||
if (is.numeric(ids)) | ||
ids = tibble::tibble(repo = repo, id = ids) | ||
arg_is_df(ids) | ||
|
||
df = dplyr::left_join( | ||
tibble::tibble(repo = repo), ids, | ||
by = "repo" | ||
) %>% | ||
dplyr::select("repo", "id") | ||
|
||
purrr::pwalk( | ||
df, | ||
function(repo, id) { | ||
res = purrr::safely(github_api_delete_artifact)(repo, id) | ||
|
||
status_msg( | ||
res, | ||
"Deleted artifact {.val {id}} from repo {.val {repo}}.", | ||
"Failed to delete artifact with id {.val {id}} from repo {.val {repo}}." | ||
) | ||
} | ||
) | ||
|
||
invisible(df) | ||
} |
Oops, something went wrong.