Skip to content

Commit

Permalink
Move list_team_*() functions to own file
Browse files Browse the repository at this point in the history
  • Loading branch information
ateucher committed May 29, 2024
1 parent e1be8d8 commit 22d035e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 65 deletions.
63 changes: 0 additions & 63 deletions R/add_team_members.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,66 +40,3 @@ add_team_members <- function(team, members, org = "openscapes"){
}
invisible(responses)
}

#' List members of a GitHub Team
#'
#' @inheritParams add_team_members
#' @param names_only Should only the team member names be returned (as a character vector; `TRUE`, the default),
#' or should all of the team member metadata be returned?
#' @param ... passed on to [gh::gh()]
#'
#' @return a character vector of team member GitHub usernames if `names_only = TRUE`, otherwise
#' a `gh_response` object containing team member information
#' @export
#'
#' @examples
#' \dontrun{
#' list_team_members(team = "2023-superdogs-test-cohort", org = "openscapes")
#' list_team_members(team = "2023-superdogs-test-cohort", org = "openscapes", names_only = FALSE)
#' }
list_team_members <- function(team, org = "openscapes", names_only = TRUE, ...) {
check_gh_pat()

org_teams <- list_teams(org)

if (!team %in% org_teams) {
stop("'", team, "' is not part of the '", org, "' organization",
call. = FALSE)
}

team_members <- gh(
"GET /orgs/{org}/teams/{team_slug}/members",
org = org,
team_slug = team,
...
)

if (!names_only) return(team_members)

vapply(team_members, `[[`, FUN.VALUE = character(1), "login")
}

#' List teams in a GitHub organization
#'
#' @inheritParams list_team_members
#' @param names_only Should only the team names be returned (as a character vector; `TRUE`, the default),
#' or should all of the team metadata be returned?
#'
#' @return a character vector of team names if `names_only = TRUE`, otherwise
#' a `gh_response` object containing team information
#' @export
#'
#' @examples
#' \dontrun{
#' list_teams(org = "openscapes")
#' list_teams(org = "openscapes", names_only = FALSE)
#' }
list_teams <- function(org = "openscapes", names_only = TRUE, ...) {
check_gh_pat()

teams <- gh("GET /orgs/{org}/teams", org = org)

if (!names_only) return(teams)

vapply(teams, `[[`, FUN.VALUE = character(1), "name")
}
62 changes: 62 additions & 0 deletions R/list_teams.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#' List members of a GitHub Team
#'
#' @inheritParams add_team_members
#' @param names_only Should only the team member names be returned (as a character vector; `TRUE`, the default),
#' or should all of the team member metadata be returned?
#' @param ... passed on to [gh::gh()]
#'
#' @return a character vector of team member GitHub usernames if `names_only = TRUE`, otherwise
#' a `gh_response` object containing team member information
#' @export
#'
#' @examples
#' \dontrun{
#' list_team_members(team = "2023-superdogs-test-cohort", org = "openscapes")
#' list_team_members(team = "2023-superdogs-test-cohort", org = "openscapes", names_only = FALSE)
#' }
list_team_members <- function(team, org = "openscapes", names_only = TRUE, ...) {
check_gh_pat()

org_teams <- list_teams(org)

if (!team %in% org_teams) {
stop("'", team, "' is not part of the '", org, "' organization",
call. = FALSE)
}

team_members <- gh(
"GET /orgs/{org}/teams/{team_slug}/members",
org = org,
team_slug = team,
...
)

if (!names_only) return(team_members)

vapply(team_members, `[[`, FUN.VALUE = character(1), "login")
}

#' List teams in a GitHub organization
#'
#' @inheritParams list_team_members
#' @param names_only Should only the team names be returned (as a character vector; `TRUE`, the default),
#' or should all of the team metadata be returned?
#'
#' @return a character vector of team names if `names_only = TRUE`, otherwise
#' a `gh_response` object containing team information
#' @export
#'
#' @examples
#' \dontrun{
#' list_teams(org = "openscapes")
#' list_teams(org = "openscapes", names_only = FALSE)
#' }
list_teams <- function(org = "openscapes", names_only = TRUE, ...) {
check_gh_pat()

teams <- gh("GET /orgs/{org}/teams", org = org)

if (!names_only) return(teams)

vapply(teams, `[[`, FUN.VALUE = character(1), "name")
}
2 changes: 1 addition & 1 deletion man/list_team_members.Rd

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

2 changes: 1 addition & 1 deletion man/list_teams.Rd

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

0 comments on commit 22d035e

Please sign in to comment.