Skip to content

Commit 0be04f7

Browse files
authored
Merge pull request #24 from gomicro/fix-fresh-repo-team-error
fix fresh repo team error
2 parents 9bef663 + 7dcb31d commit 0be04f7

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

client/repos.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ func (c *Client) GetRepoTeams(ctx context.Context, org, repo string) ([]*github.
137137
return nil, fmt.Errorf("github: hit rate limit")
138138
}
139139

140-
return nil, fmt.Errorf("get repo teams: %w", err)
141-
}
140+
if resp.StatusCode == http.StatusNotFound {
141+
return nil, ErrRepoNotFound
142+
}
142143

143-
if resp.StatusCode == http.StatusNotFound {
144-
return nil, ErrRepoNotFound
144+
return nil, fmt.Errorf("get repo teams: %w", err)
145145
}
146146

147147
return teams, nil
@@ -150,7 +150,7 @@ func (c *Client) GetRepoTeams(ctx context.Context, org, repo string) ([]*github.
150150
func (c *Client) AddRepoToTeam(ctx context.Context, org, team, repo, perm string) error {
151151
gts, err := c.GetRepoTeams(ctx, org, repo)
152152
if err != nil {
153-
return err
153+
return fmt.Errorf("add repo team: %w", err)
154154
}
155155

156156
gtps := map[string]string{}

cmd/apply_repos.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"context"
55
"errors"
6+
"fmt"
67
"io"
78
"os"
89
"strings"
@@ -205,9 +206,12 @@ func ensureRepo(ctx context.Context, org string, repo *gh_pb.Repository) error {
205206
}
206207
}
207208

208-
err = setTeamPermissions(ctx, org, repo, ghr)
209-
if err != nil {
210-
return err
209+
// if repo is fresh, we can't do anything with teams yet
210+
if !fresh {
211+
err = setTeamPermissions(ctx, org, repo, ghr)
212+
if err != nil {
213+
return err
214+
}
211215
}
212216

213217
err = ensureFiles(ctx, org, repo, ghr)
@@ -301,7 +305,7 @@ func setTeamPermissions(ctx context.Context, org string, repo *gh_pb.Repository,
301305

302306
gts, err := clt.GetRepoTeams(ctx, org, repo.Name)
303307
if err != nil {
304-
return err
308+
return fmt.Errorf("remove unamaged teams: %w", err)
305309
}
306310

307311
for _, gt := range gts {

0 commit comments

Comments
 (0)