feat: filter users by github user id in the users list CLI command (#17029)

Add the `--github-user-id` option to `coder users list`, which makes the
command only return users with a matching GitHub user id. This will
enable https://github.com/coder/start-workspace-action to find a Coder
user that corresponds to a GitHub user requesting to start a workspace.
This commit is contained in:
Hugo Dutka
2025-03-21 13:30:47 +01:00
committed by GitHub
parent 69ba27e347
commit a71aa202dc
11 changed files with 124 additions and 30 deletions

View File

@ -2,6 +2,7 @@ package coderd_test
import (
"context"
"database/sql"
"fmt"
"net/http"
"slices"
@ -1873,6 +1874,33 @@ func TestGetUsers(t *testing.T) {
require.NoError(t, err)
require.ElementsMatch(t, active, res.Users)
})
t.Run("GithubComUserID", func(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()
client, db := coderdtest.NewWithDatabase(t, nil)
first := coderdtest.CreateFirstUser(t, client)
_ = dbgen.User(t, db, database.User{
Email: "test2@coder.com",
Username: "test2",
})
// nolint:gocritic // Unit test
err := db.UpdateUserGithubComUserID(dbauthz.AsSystemRestricted(ctx), database.UpdateUserGithubComUserIDParams{
ID: first.UserID,
GithubComUserID: sql.NullInt64{
Int64: 123,
Valid: true,
},
})
require.NoError(t, err)
res, err := client.Users(ctx, codersdk.UsersRequest{
SearchQuery: "github_com_user_id:123",
})
require.NoError(t, err)
require.Len(t, res.Users, 1)
require.Equal(t, res.Users[0].ID, first.UserID)
})
}
func TestGetUsersPagination(t *testing.T) {