Skip to content

Commit

Permalink
Merge pull request ixpantia#128 from telaroix/T126
Browse files Browse the repository at this point in the history
Add search_repos function
  • Loading branch information
FvD authored Dec 14, 2022
2 parents caabce0 + 84a3ed0 commit f4b3bb0
Show file tree
Hide file tree
Showing 33 changed files with 728 additions and 675 deletions.
2 changes: 1 addition & 1 deletion R/add-tracked-time-issue.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ add_tracked_time_issue <- function(base_url, api_key, owner, repo, id_issue, tim
stop_for_status(r)


content_tracked_time <- fromJSON(content(r, as = "text"))
content_tracked_time <- jsonlite::fromJSON(content(r, as = "text"))

repo_info <- as.data.frame(content_tracked_time$issue$repository)

Expand Down
2 changes: 1 addition & 1 deletion R/create-comment-issue.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ create_comment_issue <- function(base_url, api_key, owner, repo, id_issue, body)
# To convert http errors to R errors
stop_for_status(r)

add_comment_issue <- fromJSON(content(r, as = "text"))
add_comment_issue <- jsonlite::fromJSON(content(r, as = "text"))
add_comment_issue <- as.data.frame(add_comment_issue)

return(add_comment_issue)
Expand Down
2 changes: 1 addition & 1 deletion R/create-issue.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ create_issue <- function(base_url, api_key, owner, repo, title, body){
# To convert http errors to R errors
stop_for_status(r)

content_create_issue <- fromJSON(content(r, as = "text"))
content_create_issue <- jsonlite::fromJSON(content(r, as = "text"))

return(content_create_issue)

Expand Down
2 changes: 1 addition & 1 deletion R/edit-comment.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ edit_comment <- function(base_url, api_key, owner, repo, id_comment, body){
# To convert http errors to R errors
stop_for_status(r)

content_edited_comment <- fromJSON(content(r, as = "text"))
content_edited_comment <- jsonlite::fromJSON(content(r, as = "text"))

return (content_edited_comment)

Expand Down
2 changes: 1 addition & 1 deletion R/edit-issue.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ edit_issue <- function(base_url, api_key, owner, repo, id_issue, title, body, st
# To convert http errors to R errors
stop_for_status(r)

content_edit_issue <- fromJSON(content(r, as = "text"))
content_edit_issue <- jsonlite::fromJSON(content(r, as = "text"))

return (content_edit_issue)
}
2 changes: 1 addition & 1 deletion R/edit-user.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ edit_user <- function(base_url, api_key, username, active, login_name){
# To convert http errors to R errors
stop_for_status(r)

content_edit_user <- fromJSON(content(r, as = "text"))
content_edit_user <- jsonlite::fromJSON(content(r, as = "text"))

return (content_edit_user)
}
2 changes: 1 addition & 1 deletion R/get-an-organization.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ get_an_organization <- function(base_url, api_key, org){
# To convert http errors to R errors
stop_for_status(r)

content_an_organization <- fromJSON(content(r, as = "text"))
content_an_organization <- jsonlite::fromJSON(content(r, as = "text"))
content_an_organization <- as.data.frame(content_an_organization)

return(content_an_organization)
Expand Down
2 changes: 1 addition & 1 deletion R/get-branches.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ get_branches <- function(base_url, api_key, owner, repo){
# To convert http errors to R errors
stop_for_status(r)

content_branches <- fromJSON(content(r, as = "text"))
content_branches <- jsonlite::fromJSON(content(r, as = "text"))
content_branches <- as.data.frame(content_branches)

return(content_branches)
Expand Down
2 changes: 1 addition & 1 deletion R/get-commits.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ get_commits <- function(base_url, api_key, owner, repo){
# To convert http errors to R errors
stop_for_status(r)

content_commits <- fromJSON(content(r, as = "text"))
content_commits <- jsonlite::fromJSON(content(r, as = "text"))
content_commits <- as.data.frame(content_commits)

return(content_commits)
Expand Down
2 changes: 1 addition & 1 deletion R/get-forks.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ get_forks <- function(base_url, api_key, owner, repo) {
# To convert http errors to R errors
stop_for_status(r)

content_forks <- fromJSON(content(r, as = "text"))
content_forks <- jsonlite::fromJSON(content(r, as = "text"))
content_forks <- as.data.frame(content_forks)

return(content_forks)
Expand Down
2 changes: 1 addition & 1 deletion R/get-issues-closed-state.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ get_issues_closed_state <- function(base_url, api_key, owner, repo){
# To convert http errors to R errors
stop_for_status(r)

page_issues <- fromJSON(content(r, as = "text"))
page_issues <- jsonlite::fromJSON(content(r, as = "text"))
page_issues <- jsonlite::flatten(as.data.frame(page_issues))

if (page != 1 && nrow(page_issues) == 0) {
Expand Down
202 changes: 101 additions & 101 deletions R/get-issues.R
Original file line number Diff line number Diff line change
@@ -1,101 +1,101 @@
#' @import httr
#' @import jsonlite
#' @import magrittr
#' @import graphics
#'
#' @title Returns open issues from an specific repository
#' @description Returns open issues in an specific repository
#'
#' @param base_url The base URL for your gitea server (no trailing '/')
#' @param api_key The user's API token key for the gitea service
#'
#' @param owner The owner of the repository
#' @param repo The name of the repository
#' @param full_info TRUE or FALSE value. If FALSE this will select specific
#' columns from the issues data
#'
#' @export
#'
#' @examples
#' \dontrun{
#' get_issues(base_url = "https://example.gitea.service.com",
#' api_key = "ccaf5c9a22e854856d0c5b1b96c81e851bafb288",
#' owner = "company",
#' repo = "test_repo",
#' full_info = FALSE)
#' }
get_issues <- function(base_url, api_key, owner, repo, full_info = FALSE) {
if (missing(base_url)) {
stop("Please add a valid URL")
} else if (missing(api_key)) {
stop("Please add a valid API token")
} else if (missing(owner)) {
stop("Please add a valid owner")
} else if (missing(repo)) {
stop("Please add a valid repository")
}
base_url <- sub("/$", "", base_url)
gitea_url <- file.path(base_url, "api/v1",
sub("^/", "", "/repos"),
owner, repo, "issues")

authorization <- paste("token", api_key)

r <- tryCatch(GET(gitea_url,
add_headers(Authorization = authorization),
accept_json()),
error = function(cond) {"Failure"})

if (class(r) != "response") {
stop(paste0("Error consulting the url: ", gitea_url))
}

# To convert http errors to R errors
stop_for_status(r)

content_issues <- fromJSON(content(r, as = "text"))

# Data frame wrangling
if (full_info == FALSE) {

if (is.data.frame(content_issues$user)) {
users <- tibble::as_tibble(content_issues$user) %>%
dplyr::select(username) %>%
dplyr::rename(author = username)
} else {
users <- data.frame()
}


if (is.list(content_issues$assignees)) {
assignees <- tibble::as_tibble(content_issues$assignee) %>%
dplyr::select(username) %>%
dplyr::rename(assignee = username)
} else {
assignees <- data.frame()
}

# Join by position
issues_content <- content_issues %>%
dplyr::select(number, title, body, created_at, updated_at,
due_date) %>%
dplyr::bind_cols(users, assignees) %>%
tidyr::separate(col = created_at,
into = c("created_date", "created_time"),
sep = "T") %>%
tidyr::separate(col = updated_at,
into = c("updated_date", "updated_time"),
sep = "T") %>%
dplyr::mutate(created_time = stringr::str_remove(created_time,
pattern = "Z"),
updated_time = stringr::str_remove(updated_time,
pattern = "Z"))

# Return object filtered out
return(issues_content)

} else {
return(content_issues)
}

}
#' @import httr
#' @import jsonlite
#' @import magrittr
#' @import graphics
#'
#' @title Returns open issues from an specific repository
#' @description Returns open issues in an specific repository
#'
#' @param base_url The base URL for your gitea server (no trailing '/')
#' @param api_key The user's API token key for the gitea service
#'
#' @param owner The owner of the repository
#' @param repo The name of the repository
#' @param full_info TRUE or FALSE value. If FALSE this will select specific
#' columns from the issues data
#'
#' @export
#'
#' @examples
#' \dontrun{
#' get_issues(base_url = "https://example.gitea.service.com",
#' api_key = "ccaf5c9a22e854856d0c5b1b96c81e851bafb288",
#' owner = "company",
#' repo = "test_repo",
#' full_info = FALSE)
#' }
get_issues <- function(base_url, api_key, owner, repo, full_info = FALSE) {
if (missing(base_url)) {
stop("Please add a valid URL")
} else if (missing(api_key)) {
stop("Please add a valid API token")
} else if (missing(owner)) {
stop("Please add a valid owner")
} else if (missing(repo)) {
stop("Please add a valid repository")
}
base_url <- sub("/$", "", base_url)
gitea_url <- file.path(base_url, "api/v1",
sub("^/", "", "/repos"),
owner, repo, "issues")

authorization <- paste("token", api_key)

r <- tryCatch(GET(gitea_url,
add_headers(Authorization = authorization),
accept_json()),
error = function(cond) {"Failure"})

if (class(r) != "response") {
stop(paste0("Error consulting the url: ", gitea_url))
}

# To convert http errors to R errors
stop_for_status(r)

content_issues <- jsonlite::fromJSON(content(r, as = "text"))

# Data frame wrangling
if (full_info == FALSE) {

if (is.data.frame(content_issues$user)) {
users <- tibble::as_tibble(content_issues$user) %>%
dplyr::select(username) %>%
dplyr::rename(author = username)
} else {
users <- data.frame()
}


if (is.list(content_issues$assignees)) {
assignees <- tibble::as_tibble(content_issues$assignee) %>%
dplyr::select(username) %>%
dplyr::rename(assignee = username)
} else {
assignees <- data.frame()
}

# Join by position
issues_content <- content_issues %>%
dplyr::select(number, title, body, created_at, updated_at,
due_date) %>%
dplyr::bind_cols(users, assignees) %>%
tidyr::separate(col = created_at,
into = c("created_date", "created_time"),
sep = "T") %>%
tidyr::separate(col = updated_at,
into = c("updated_date", "updated_time"),
sep = "T") %>%
dplyr::mutate(created_time = stringr::str_remove(created_time,
pattern = "Z"),
updated_time = stringr::str_remove(updated_time,
pattern = "Z"))

# Return object filtered out
return(issues_content)

} else {
return(content_issues)
}

}
2 changes: 1 addition & 1 deletion R/get-label-issue.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ get_label_issue <- function(base_url, api_key, owner, repo, id_issue){
# To convert http errors to R errors
stop_for_status(r)

content_label_issue <- fromJSON(content(r, as = "text"))
content_label_issue <- jsonlite::fromJSON(content(r, as = "text"))
content_label_issue <- as.data.frame(content_label_issue)

return(content_label_issue)
Expand Down
2 changes: 1 addition & 1 deletion R/get-list-an-org-teams.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ get_list_org_teams <- function(base_url, api_key, org){
# To convert http errors to R errors
stop_for_status(r)

cont_list_an_org_teams <- fromJSON(content(r, as = "text"))
cont_list_an_org_teams <- jsonlite::fromJSON(content(r, as = "text"))
cont_list_an_org_teams <- as.data.frame(cont_list_an_org_teams)

return(cont_list_an_org_teams)
Expand Down
2 changes: 1 addition & 1 deletion R/get-list-comments-issue.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ get_list_comments_issue <- function(base_url, api_key, owner, repo, id_issue){
# To convert http errors to R errors
stop_for_status(r)

content_list_comments_issue <- fromJSON(content(r, as = "text"))
content_list_comments_issue <- jsonlite::fromJSON(content(r, as = "text"))

return(content_list_comments_issue)

Expand Down
2 changes: 1 addition & 1 deletion R/get-list-comments-repository.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ get_list_comments_repository <- function(base_url, api_key, owner, repo){
# To convert http errors to R errors
stop_for_status(r)

list_com_repository <- fromJSON(content(r, as = "text"))
list_com_repository <- jsonlite::fromJSON(content(r, as = "text"))

return(list_com_repository)

Expand Down
2 changes: 1 addition & 1 deletion R/get-list-organization-members.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ get_list_org_members <- function(base_url, api_key, org){
# To convert http errors to R errors
stop_for_status(r)

content_list_org_members <- fromJSON(content(r, as = "text"))
content_list_org_members <- jsonlite::fromJSON(content(r, as = "text"))
content_list_org_members <- as.data.frame(content_list_org_members)

return(content_list_org_members)
Expand Down
2 changes: 1 addition & 1 deletion R/get-list-repos-of-an-organization.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ get_list_repos_org <- function(base_url, api_key, org){
# To convert http errors to R errors
stop_for_status(r)

content_list_repos_org <- fromJSON(content(r, as = "text"))
content_list_repos_org <- jsonlite::fromJSON(content(r, as = "text"))
content_list_repos_org <- as.data.frame(content_list_repos_org)

return(content_list_repos_org)
Expand Down
2 changes: 1 addition & 1 deletion R/get-list-users.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ get_list_users <- function(base_url, api_key) {
# To convert http errors to R errors
stop_for_status(r)

content_list_users <- fromJSON(content(r, as = "text"))
content_list_users <- jsonlite::fromJSON(content(r, as = "text"))
content_list_users <- as.data.frame(content_list_users)

return(content_list_users)
Expand Down
2 changes: 1 addition & 1 deletion R/get-milestones.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ get_milestones <- function(base_url, api_key, owner, repo){

# To convert http errors to R errors
stop_for_status(r)
content_milestones <- fromJSON(content(r, as = "text"))
content_milestones <- jsonlite::fromJSON(content(r, as = "text"))
content_milestones <- as.data.frame(content_milestones)

return(content_milestones)
Expand Down
Loading

0 comments on commit f4b3bb0

Please sign in to comment.