Skip to content

Commit

Permalink
Merge pull request #164 from jhudsl/cansavvy/find_issue
Browse files Browse the repository at this point in the history
Add find_issue as a function
  • Loading branch information
cansavvy authored Jan 13, 2025
2 parents d4afcdf + 0cbe717 commit 6aa5218
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export(delete_creds)
export(extract_meta)
export(extract_object_id)
export(extract_quiz)
export(find_issue)
export(get_chapters)
export(get_github)
export(get_gs_pptx)
Expand Down
53 changes: 53 additions & 0 deletions R/github_handling.R
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,56 @@ check_git_repo <- function(repo_name,

return(exists)
}




#' Find an issue on GitHub with a particular title
#'
#' Given text and repository name, find if an issue exists.
#'
#' @param text What text to be searched for in the GitHub issues. Can be regex.
#' @param repo_name the name of the repository, e.g. jhudsl/OTTR_Template
#' @param token A personal access token from GitHub. Only necessary if the
#' repository being checked is a private repository.
#'
#' @return A TRUE/FALSE whether or not the issue with this text on this repository exists.
#'
#' @export
#'
#' @examples \dontrun{
#'
#' authorize("github")
#'
#' find_issue(text = "TEST", repo_name = "jhudsl/ottrpal")
#'
#' }

find_issue <- function(text, repo_name, token = NULL) {

if (!is.character(repo_name)) {
repo <- as.character(repo_name)
}

# Github api get
result <- httr::GET(
paste0("https://api.github.com/repos/", repo_name, "/issues"),
#httr::add_headers(Authorization = paste0("Bearer ", token)),
httr::accept_json()
)

if (httr::status_code(result) != 200) {
httr::stop_for_status(result)
}

# Process and return results
result_content <- httr::content(result, "text")
result_list <- jsonlite::fromJSON(result_content)

issue_exists <- length(grep(text, result_list$title))

# Print out the result
write(issue_exists, stdout())

return(result_list)
}
31 changes: 31 additions & 0 deletions man/find_issue.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions tests/testthat/test-gh.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

test_that("Test issue finder", {

issue <- find_issue(text = "TEST:", repo_name = "jhudsl/ottrpal")

testthat::expect_true(length(issue$id) > 0)
})

0 comments on commit 6aa5218

Please sign in to comment.