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

List teams in an org and list org team members #107

Merged
merged 4 commits into from
Jun 4, 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
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export(create_readme)
export(create_team)
export(init_repo)
export(kyber_file)
export(list_team_members)
export(list_teams)
export(md_agenda)
export(short_names)
import(knitr)
Expand Down
3 changes: 1 addition & 2 deletions R/add_team_members.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#' @param team The name of the team.
#' @param members A vector of GitHub usernames.
#' @param org The GitHub organization that owns the team and the repository.
#' @importFrom gh gh
#' @importFrom purrr map safely map_lgl
#' @export
#' @examples
Expand Down Expand Up @@ -40,4 +39,4 @@ add_team_members <- function(team, members, org = "openscapes"){
username = members[i], role = "member")
}
invisible(responses)
}
}
2 changes: 1 addition & 1 deletion R/add_team_to_repo.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' @param repository The name of the GitHub repository.
#' @param team The name of the team.
#' @param org The GitHub organization that owns the team and the repository.
#' @importFrom gh gh
#'
#' @export
#' @examples
#' \dontrun{
Expand Down
1 change: 0 additions & 1 deletion R/create_team.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#' @param org The GitHub organization that will own the team.
#' @param visible Should the team be visible to every member of the organization?
#'
#' @importFrom gh gh
#' @export
#' @examples
#' \dontrun{
Expand Down
1 change: 0 additions & 1 deletion R/init_repo.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#'
#' @importFrom fs path dir_create file_copy
#' @importFrom gert git_clone git_init git_add git_commit git_branch git_branch_move git_remote_add git_push
#' @importFrom gh gh
#' @importFrom purrr map_chr
#' @export
#' @details
Expand Down
1 change: 1 addition & 0 deletions R/kyber-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

## usethis namespace: start
#' @importFrom dplyr .data
#' @importFrom gh gh
## usethis namespace: end
NULL
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")
}
31 changes: 31 additions & 0 deletions man/list_team_members.Rd

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

29 changes: 29 additions & 0 deletions man/list_teams.Rd

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

Loading