Skip to content

Commit

Permalink
Merge pull request #35 from A2-ai/issue_tag
Browse files Browse the repository at this point in the history
use Issue labels to filter Issues and Milestones
  • Loading branch information
wes-a2ai authored Nov 13, 2024
2 parents f95d794 + e5ed61a commit 767041c
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 11 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ghqc.app
Title: Create QC Checklists in Github Issues
Version: 0.1.9
Version: 0.1.10
Authors@R: c(
person("Jenna", "Johnson", email = "[email protected]", role = c("aut", "cre")),
person("Anne", "Zheng", email = "[email protected]", role = c("aut")),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ghqc.app 0.1.10

- Adds "ghqc" label to all GitHub Issues created by ghqc. Only Issues with this label, and the Milestones containing them, will be viewable/selectable in the apps. This change is NOT backward compatible with Issues/Milestones created in previous versions

# ghqc.app 0.1.9

- Clarifies language in Warning and Error modals for all three apps
Expand Down
39 changes: 29 additions & 10 deletions R/get_org_attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,32 @@ filter_for_non_empty_milestones <- function(milestones) {
return(non_empty_milestones)
}

filter_for_ghqc_milestones <- function(owner, repo, milestones) {
if (length(milestones) == 0) return(milestones)
labels <- sapply(milestones, function(x) gh::gh("GET /repos/:owner/:repo/milestones/:milestone_number/labels", owner = owner, repo = repo, milestone_number = x$number, .api_url = .le$github_api_url))
milestones[sapply(labels, function(x) "ghqc" %in% sapply(x, function(y) y))]
}

#' @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 +96,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 +326,20 @@ 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) {
if (length(issues) == 0) return(issues)
labels <- sapply(issues, function(x) x$labels)
if (length(labels) == 0) return(c(list(), list()))
issues[sapply(labels, function(x) "ghqc" %in% sapply(x, function(y) y))]
}

# sort by open/closed
#' @importFrom log4r warn error info debug
get_all_issues_in_milestone <- function(owner, repo, milestone_name) {
Expand Down Expand Up @@ -378,9 +397,9 @@ get_all_issues_in_milestone <- function(owner, repo, milestone_name) {
# next page
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
33 changes: 33 additions & 0 deletions R/multi_issue.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ 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"),
.api_url = .le$github_api_url)
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 +80,35 @@ create_issues <- function(data) {
info(.le$logger, glue::glue("Created checklist(s) for file(s): {file_names}"))
} # create_issues

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

#' @importFrom gh gh
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",
.api_url = .le$github_api_url
)
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 767041c

Please sign in to comment.