Skip to content

Commit

Permalink
API and processing edits to include the number of repo stars datapoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-vand committed Sep 17, 2024
1 parent 7db5949 commit 9fca17c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 6 additions & 2 deletions R/gh_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
#' @return A list object containing the API query response data.
api_get_endpoint <- function(owner, repo, endpoint) {

# Create API query to string
api_query <- paste0("GET /repos/", owner, "/", repo, "/", endpoint)
# Create API endpoint string
if (is.na(endpoint)) {
api_query <- paste0("GET /repos/", owner, "/", repo)
} else {
api_query <- paste0("GET /repos/", owner, "/", repo, "/", endpoint)
}
logger::log_debug(api_query)

# Make GitHub API request for endpoint. tryCatch used as error handler wrapper.
Expand Down
11 changes: 8 additions & 3 deletions R/metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ compile_metadata <- function(gh_data, cran_data = NULL, description_contents = N
has_tests = gh_data$has_tests,
has_vignettes = gh_data$has_vignettes,
num_contributors = gh_data$num_contributors,
num_stars = gh_data$num_stars,
on_cran = on_cran
)

Expand Down Expand Up @@ -180,16 +181,20 @@ github_metadata <- function(name, owner, repo) {
return(NULL)
}

# Get additional repo metadata via contributors" and "commits" endpoints.
extra_meta <- api_get_endpoints(owner = owner, repo = repo, endpoint = c("contributors", "commits"))
# Get additional repo metadata - NA for used for `main` call as there is no specific endpoint for the API call.
extra_endpoints <- c("contributors", "commits", NA)
extra_meta <- api_get_endpoints(owner = owner, repo = repo, endpoint = extra_endpoints)
names(extra_meta)[3] <- "main"
logger::log_info(sprintf("Github metadata retrieved for package %s", name))

# Compile list of target metadata.
ret <- list(has_tests = has_tests(filenames),
has_vignettes = has_vignettes(filenames),
name = name,
url = paste("https://github.com", owner, repo, sep = "/"),
num_contributors = length(extra_meta$contributors))
num_contributors = length(extra_meta$contributors),
num_stars = extra_meta$main$stargazers_count
)

# Add class "github_metadata".
class(ret) <- append("github_metadata", class(ret))
Expand Down

0 comments on commit 9fca17c

Please sign in to comment.