feat(repos): add repository permission lookup
All checks were successful
Security Scan / security (push) Successful in 11s
Test / test (push) Successful in 1m37s

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 02:18:31 +00:00
parent 232c1fa943
commit 48c6296d25
2 changed files with 18 additions and 0 deletions

View file

@ -282,6 +282,16 @@ func (s *RepoService) GetCollaboratorPermission(ctx context.Context, owner, repo
return &out, nil
}
// GetRepoPermissions returns repository permissions for a user.
func (s *RepoService) GetRepoPermissions(ctx context.Context, owner, repo, collaborator string) (*types.RepoCollaboratorPermission, error) {
path := ResolvePath("/api/v1/repos/{owner}/{repo}/collaborators/{collaborator}/permission", pathParams("owner", owner, "repo", repo, "collaborator", collaborator))
var out types.RepoCollaboratorPermission
if err := s.client.Get(ctx, path, &out); err != nil {
return nil, err
}
return &out, nil
}
// GetArchive returns a repository archive as raw bytes.
func (s *RepoService) GetArchive(ctx context.Context, owner, repo, archive string) ([]byte, error) {
path := ResolvePath("/api/v1/repos/{owner}/{repo}/archive/{archive}", pathParams("owner", owner, "repo", repo, "archive", archive))

View file

@ -1607,6 +1607,14 @@ func TestRepoService_GetCollaboratorPermission_Good(t *testing.T) {
if perm.Permission != "write" || perm.User == nil || perm.User.UserName != "alice" {
t.Fatalf("got %#v", perm)
}
perm, err = f.Repos.GetRepoPermissions(context.Background(), "core", "go-forge", "alice")
if err != nil {
t.Fatal(err)
}
if perm.Permission != "write" || perm.User == nil || perm.User.UserName != "alice" {
t.Fatalf("got %#v", perm)
}
}
func TestRepoService_Watch_Good(t *testing.T) {