Skip to content

Commit

Permalink
filters away all non-ghqc tagged Issues and Milestones which do not c…
Browse files Browse the repository at this point in the history
…ontain a ghqc tagged Issue
  • Loading branch information
wes-a2ai committed Nov 12, 2024
1 parent f95d794 commit dc28cf8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 9 deletions.
34 changes: 25 additions & 9 deletions R/get_org_attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,31 @@ filter_for_non_empty_milestones <- function(milestones) {
return(non_empty_milestones)
}

filter_for_ghqc_milestones <- function(owner, repo, milestones) {
labels <- sapply(milestones, function(x) gh::gh("GET /repos/:owner/:repo/milestones/:milestone_number/labels", owner = owner, repo = repo, milestone_number = x$number))
milestones[sapply(labels, function(x) "ghqc" %in% sapply(x, function(y) y$name))]
}

#' @importFrom log4r warn error info debug
get_open_milestone_objects <- function(owner, repo) {
debug(.le$logger, glue::glue("Retrieving open Milestone(s) in organization {owner}, repo {repo}..."))

milestones <- gh::gh("GET /repos/:owner/:repo/milestones", .api_url = .le$github_api_url, owner = owner, repo = repo, state = "open", .limit = Inf)
info(.le$logger, glue::glue("Retrieved {length(milestones)} open Milestone(s) in repo {repo}"))
non_empty_milestones <- filter_for_non_empty_milestones(milestones)
debug(.le$logger, glue::glue("Retrieved {length(milestones)} open Milestone(s) in repo {repo}"))
ghqc_milestones <- filter_for_ghqc_milestones(owner, repo, milestones)
info(.le$logger, glue::glue("Retrieved {length(ghqc_milestones)} open ghqc Milestone(s) in repo {repo}"))
non_empty_milestones <- filter_for_non_empty_milestones(ghqc_milestones)
}

#' @importFrom log4r warn error info debug
get_closed_milestone_objects <- function(owner, repo) {
debug(.le$logger, glue::glue("Retrieving closed Milestone(s) in organization {owner}, repo {repo}..."))

milestones <- gh::gh("GET /repos/:owner/:repo/milestones", .api_url = .le$github_api_url, owner = owner, repo = repo, state = "closed", .limit = Inf)
info(.le$logger, glue::glue("Retrieved {length(milestones)} closed Milestone(s) in repo {repo}"))
non_empty_milestones <- filter_for_non_empty_milestones(milestones)
debug(.le$logger, glue::glue("Retrieved {length(milestones)} closed Milestone(s) in repo {repo}"))
ghqc_milestones <- filter_for_ghqc_milestones(owner, repo, milestones)
info(.le$logger, glue::glue("Retrieved {length(ghqc_milestones)} closed ghqc Milestone(s) in repo {repo}"))
non_empty_milestones <- filter_for_non_empty_milestones(ghqc_milestones)
}

#' @importFrom log4r warn error info debug
Expand Down Expand Up @@ -86,8 +95,10 @@ list_milestones <- function(org, repo) {
debug(.le$logger, glue::glue("Retrieving Milestone(s) in organization {org}, repo {repo}..."))
milestones <- get_all_milestone_objects(org, repo)
info(.le$logger, glue::glue("Retrieved {length(milestones)} total Milestone(s) in repo {repo}"))
non_empty_milestones <- filter_for_non_empty_milestones(milestones)
info(.le$logger, glue::glue("Retrieved {length(non_empty_milestones)} non-empty Milestone(s) in repo {repo}"))
ghqc_milestones <- filter_for_ghqc_milestones(org, repo, milestones)
info(.le$logger, glue::glue("Retrieved {length(ghqc_milestones)} ghqc Milestone(s) in repo {repo}"))
non_empty_milestones <- filter_for_non_empty_milestones(ghqc_milestones)
info(.le$logger, glue::glue("Retrieved {length(non_empty_milestones)} non-empty ghqc Milestone(s) in repo {repo}"))
res <- purrr::map_chr(non_empty_milestones, "title")
return(res)
}
Expand Down Expand Up @@ -314,13 +325,18 @@ get_all_issues_in_repo <- function(owner, repo) {
page <- page + 1
}

issues <- c(open_issues, closed_issues)
issues <- get_only_ghqc_issues(c(open_issues, closed_issues))
num_issues <- length(issues)
info(.le$logger, glue::glue("Retrieved {num_issues} Issue(s) from repo: {repo}"))
return(issues)

}

get_only_ghqc_issues <- function(issues) {
labels <- sapply(issues, function(x) x$labels)
issues[sapply(labels, function(x) "ghqc" %in% sapply(x, function(y) y$name))]
}

# sort by open/closed
#' @importFrom log4r warn error info debug
get_all_issues_in_milestone <- function(owner, repo, milestone_name) {
Expand Down Expand Up @@ -379,8 +395,8 @@ get_all_issues_in_milestone <- function(owner, repo, milestone_name) {
page <- page + 1
}

issues <- c(open_issues, closed_issues)
info(.le$logger, glue::glue("Retrieved {length(issues)} Issue(s) from Milestone: {milestone_name}"))
issues <- get_only_ghqc_issues(c(open_issues, closed_issues))
info(.le$logger, glue::glue("Retrieved {length(issues)} ghqc Issue(s) from Milestone: {milestone_name}"))
return(issues)
}

Expand Down
28 changes: 28 additions & 0 deletions R/multi_issue.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ create_issue <- function(file, issue_params) {
issue <- do.call(gh::gh, c("POST /repos/{owner}/{repo}/issues", issue_params))
debug(.le$logger, glue::glue("Created Issue {issue_params$title}"))

debug(.le$logger, glue::glue("Adding 'ghqc' label to {issue_params$title}"))
label_params <- list(owner = issue_params$owner,
repo = issue_params$repo,
issue_number = issue$number,
labels = array("ghqc"))
label <- do.call(gh::gh, c("POST /repos/{owner}/{repo}/issues/{issue_number}/labels", label_params))
debug(.le$logger, glue::glue("Label 'ghqc' added to {issue_params$title}"))

# return the issue number
list(number = issue$number, assignees = issue_params$assignees)
} # create_issue
Expand Down Expand Up @@ -71,11 +79,31 @@ create_issues <- function(data) {
info(.le$logger, glue::glue("Created checklist(s) for file(s): {file_names}"))
} # create_issues

ghqc_label_exists <- function(data) {
labels <- do.call(gh::gh, c("GET /repos/{owner}/{repo}/labels",
list(owner = data$owner,
repo = data$repo
)))
"ghqc" %in% sapply(labels, function(x) x$name)
}

create_ghqc_label <- function(data) {
issue_params <- list(
owner = data$owner,
repo = data$repo,
name = "ghqc",
color = "FFCB05",
description = "Issue created by the ghqc package"
)
do.call(gh::gh, c("POST /repos/{owner}/{repo}/labels", issue_params))
}


# test with "test_yamls/checklist.yaml"
#' @importFrom log4r warn error info debug
create_checklists <- function(yaml_path) {
data <- read_and_validate_yaml(yaml_path)
if (!ghqc_label_exists(data)) labels <- create_ghqc_label(data)
create_issues(data)
}

Expand Down

0 comments on commit dc28cf8

Please sign in to comment.