Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvements to listing GH teams/members #108

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions R/list_teams.R
Original file line number Diff line number Diff line change
@@ -1,34 +1,46 @@
#' 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 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 members Should current members (`"members"`) be returned, or pending
#' invitations (`"invitations"`) invitations be returned? Default `"members"`.
#' @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
#' @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(team = "2023-superdogs-test-cohort", org = "openscapes",
#' names_only = FALSE)
#' list_team_members(team = "2023-superdogs-test-cohort", org = "openscapes",
#' members = "invitations")
#' }
list_team_members <- function(team, org = "openscapes", names_only = TRUE, ...) {
list_team_members <- function(team, org = "openscapes", names_only = TRUE,
members = c("members", "invitations"), ...) {
check_gh_pat()

org_teams <- list_teams(org)
team <- tolower(team)
org <- tolower(org)
org_teams <- tolower(list_teams(org))
members <- match.arg(members)

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",
"GET /orgs/{org}/teams/{team_slug}/{members}",
org = org,
team_slug = team,
...
members = members,
...,
.limit = Inf
)

if (!names_only) return(team_members)
Expand All @@ -54,7 +66,7 @@ list_team_members <- function(team, org = "openscapes", names_only = TRUE, ...)
list_teams <- function(org = "openscapes", names_only = TRUE, ...) {
check_gh_pat()

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

if (!names_only) return(teams)

Expand Down
19 changes: 14 additions & 5 deletions man/list_team_members.Rd

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

Loading