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

Gh teams improvements #139

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ name: R-CMD-check
jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}



name: ${{ matrix.config.os }} (${{ matrix.config.r }})

Expand All @@ -25,7 +27,7 @@ jobs:
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
GITHUB_PAT: ${{ secrets.GH_PAT }}
R_KEEP_PKG_SOURCE: yes

steps:
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Imports:
cli,
dplyr,
Expand Down
12 changes: 6 additions & 6 deletions R/list_teams.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' @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?
#' metadata be returned as a data.frame?
#' @param members Should current members (`"members"`) be returned, or pending
#' invitations (`"invitations"`) invitations be returned? Default `"members"`.
#' @param ... passed on to [gh::gh()]
Expand All @@ -26,10 +26,10 @@ list_team_members <- function(team, org = "openscapes", names_only = TRUE,

team <- tolower(team)
org <- tolower(org)
org_teams <- tolower(list_teams(org))
org_teams <- list_teams(org, names_only = FALSE)
members <- match.arg(members)

if (!team %in% org_teams) {
if (!team %in% org_teams$slug) {
stop("'", team, "' is not part of the '", org, "' organization",
call. = FALSE)
}
Expand All @@ -43,7 +43,7 @@ list_team_members <- function(team, org = "openscapes", names_only = TRUE,
.limit = Inf
)

if (!names_only) return(team_members)
if (!names_only) return(dplyr::bind_rows(team_members))

vapply(team_members, `[[`, FUN.VALUE = character(1), "login")
}
Expand All @@ -52,7 +52,7 @@ list_team_members <- function(team, org = "openscapes", names_only = TRUE,
#'
#' @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?
#' or should all of the team metadata be returned as a data frame?
#'
#' @return a character vector of team names if `names_only = TRUE`, otherwise
#' a `gh_response` object containing team information
Expand All @@ -68,7 +68,7 @@ list_teams <- function(org = "openscapes", names_only = TRUE, ...) {

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

if (!names_only) return(teams)
if (!names_only) return(dplyr::bind_rows(teams))

vapply(teams, `[[`, FUN.VALUE = character(1), "name")
}
7 changes: 5 additions & 2 deletions 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.

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/list_teams.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# list_team_members fails with non-existent team

Code
list_team_members("foofy")
Condition
Error:
! 'foofy' is not part of the 'openscapes' organization

28 changes: 28 additions & 0 deletions tests/testthat/test-list_teams.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
test_that("list_teams works", {
expect_type(
list_teams(names_only = TRUE),
"character"
)
expect_s3_class(
list_teams(names_only = FALSE),
"data.frame"
)
})

test_that("list_team_members works", {
expect_type(
list_team_members("core-team"),
"character"
)
expect_s3_class(
list_team_members("core-team", names_only = FALSE),
"data.frame"
)
})

test_that("list_team_members fails with non-existent team", {
expect_snapshot(
list_team_members("foofy"),
error = TRUE
)
})
Loading