-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes and improvements for strategies #26
Changes from all commits
d86414e
aad9662
261ed9b
c7d2368
81dcef0
3edf4e6
37b6748
9821383
c9f98e5
4352850
d940853
0579af9
c2d4b99
89f3b76
f65c8b3
e58166a
33e7277
846f5b0
a470d97
9796b12
5a3a6d9
0f6b80e
ac12fea
31ff448
5370242
7ae7b72
109db00
047d3f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,7 +96,19 @@ get_ref_min.remote_ref_cran <- function(remote_ref, op = "", op_ver = "") { | |
min_ver <- Filter(function(x) x == min(pv), pv) | ||
|
||
new_ref <- sprintf("%s@%s", remote_ref$ref, names(min_ver)) # @TODO deparse, add ver, parse again | ||
pkgdepends::parse_pkg_ref(new_ref) | ||
tryCatch( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am just curious - can we move this try to the generic so that other types of remote will be covered without the need of copy&paste same error message |
||
pkgdepends::parse_pkg_ref(new_ref), | ||
error = function(err) { | ||
cli::cli_alert_danger( | ||
paste( | ||
sep = " ", | ||
"Possible problem finding release for:", | ||
"`{remote_ref$package} ({op} {op_ver})`.", | ||
"The version might be invalid." | ||
) | ||
) | ||
stop(err) | ||
}) | ||
} | ||
|
||
#' @rdname get_ref_min | ||
|
@@ -150,7 +162,13 @@ get_ref_min.remote_ref_github <- function(remote_ref, op = "", op_ver = "") { | |
} | ||
} | ||
|
||
new_ref <- sprintf("%s=%s/%s%s", remote_ref$package, remote_ref$username, remote_ref$repo, ref_suffix) # @TODO | ||
new_ref <- sprintf( | ||
"%s=%s/%s%s", | ||
remote_ref$package, | ||
remote_ref$username, | ||
remote_ref$repo, | ||
ref_suffix | ||
) | ||
pkgdepends::parse_pkg_ref(new_ref) | ||
} | ||
|
||
|
@@ -163,6 +181,7 @@ get_gh_refs <- function(org, repo) { | |
} | ||
get_gh_tags(org, repo) | ||
} | ||
|
||
#' @importFrom gh gh_gql | ||
#' @keywords internal | ||
get_gh_releases <- function(org, repo, max_date = Sys.Date() + 1, min_date = as.Date("1900-01-01")) { | ||
|
@@ -187,6 +206,7 @@ get_gh_releases <- function(org, repo, max_date = Sys.Date() + 1, min_date = as. | |
) | ||
vapply(res, `[[`, character(1), "tagName") | ||
} | ||
|
||
#' @importFrom gh gh_gql | ||
#' @keywords internal | ||
get_gh_tags <- function(org, repo, max_date = Sys.Date() + 1, min_date = as.Date("1900-01-01")) { | ||
|
@@ -316,40 +336,76 @@ cond_parse_pkg_ref_release <- function(remote_ref) { | |
get_release_date <- function(remote_ref) { | ||
UseMethod("get_release_date", remote_ref) | ||
} | ||
|
||
#' Get release date from GitHub references | ||
#' | ||
#' @inheritParams get_release_date | ||
#' | ||
#' @importFrom gh gh_gql | ||
#' @export | ||
#' @examplesIf gh::gh_token() != "" | ||
#' remote_ref <- pkgdepends::parse_pkg_ref("insightsengineering/[email protected]") | ||
#' get_release_date.remote_ref_github(remote_ref) | ||
get_release_date.remote_ref_github <- function(remote_ref) { | ||
gql_query <- sprintf("{ | ||
repository(owner: \"%s\", name: \"%s\") { | ||
refs(refPrefix: \"refs/tags/\", query: \"%s\", first: 100) { | ||
nodes { | ||
target { | ||
... on Commit { | ||
committedDate | ||
edges { | ||
node { | ||
name | ||
target { | ||
... on Commit { | ||
committedDate | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}", remote_ref$username, remote_ref$repo, remote_ref$commitish) | ||
|
||
resp <- try(gh::gh_gql(gql_query), silent = TRUE) | ||
if (inherits(resp, "try-error")) { | ||
return(character(0)) | ||
} | ||
vapply(resp$data$repository$refs$nodes, function(x) x$target$committedDate, character(1)) | ||
|
||
result <- vapply( | ||
resp$data$repository$refs$edges, | ||
function(x) { | ||
if (x$node$name != remote_ref$commitish) return(NA_character_) | ||
x$node$target$committedDate | ||
}, | ||
character(1) | ||
) | ||
|
||
if (length(result) <= 1) { | ||
return(result %||% NA_character_) | ||
} | ||
|
||
max(result, na.rm = TRUE) | ||
} | ||
|
||
#' Get release date from GitHub references | ||
#' | ||
#' @inheritParams get_release_date | ||
#' | ||
#' @export | ||
#' @examplesIf Sys.getenv("R_USER_CACHE_DIR", "") != "" | ||
#' remote_ref <- pkgdepends::parse_pkg_ref("[email protected]") | ||
#' get_release_date.remote_ref_cran(remote_ref) | ||
get_release_date.remote_ref_cran <- function(remote_ref) { | ||
subset( | ||
get_cran_data(remote_ref$package), | ||
package_version(version, strict = FALSE) == package_version(remote_ref$version, strict = FALSE), | ||
mtime | ||
)[[1]][1] | ||
} | ||
|
||
#' @export | ||
get_release_date.remote_ref_standard <- function(remote_ref) { | ||
get_release_date.remote_ref_cran(remote_ref) | ||
} | ||
|
||
#' @export | ||
get_release_date.remote_ref <- function(remote_ref) { | ||
NA | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still struggle to fully understand what it does and why it is there.
You have the following:
d$get_remotes()[!(remotes_pkg %in% new_ref_pkg)]
is a vector of remotes not present in config/needs/verdepchecknew_ref_remote
is vector with config/needs/verdepcheck refs for packages existing in remotes fieldSo essentially it's (conditionally) replacing remotes entries with config/needs/verdepcheck entries. OK seems that I get what it does while writing this comment.
UPDATE: I just came up with example where you actually remove some entries so it's not only about replacing one with another. Then I guess we can modify for loop with
if (cond1) then NULL else if (cond2) x else y
$get_remotes()
twice - also not a big dealnew_refs
,new_ref_remote
,new_ref_remote
and none of them indicates new references for remote fieldHow about a simple for loop:
desc_cond_set_refs
first and thendesc_remotes_cleanup
using one argument only indicating desc object. This could potentially simplify naming issue as well as it fits to the role better - you want to replace desc remotes field with another field (that is being extracted from the same desc object and not another argument)Please have a look at
get_refs_from_desc
executed at the very beginning of each installation proposal constructor - it is that function which is responsible for preparing correct list of references for further analysis. I would even ask if we need a Remotes at all - as we already / should have everything we need in the config/needs/verdepcheck. That field can potentially have downstream implications so I am inclined to request to always clear it.