Skip to content
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: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.27.1

require (
github.com/bradleyfalzon/ghinstallation/v2 v2.19.0
github.com/google/go-github/v90 v90.0.0
github.com/google/go-github/v91 v91.0.0
github.com/spf13/cobra v1.10.2
github.com/spf13/pflag v1.0.10
golang.org/x/oauth2 v0.36.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/go-github/v88 v88.0.0 h1:dZA9IKkPK1eXZj4ypngnpRj5FwdpTv4whix2PrQMP7M=
github.com/google/go-github/v88 v88.0.0/go.mod h1:rufTDgn2N45wjhukLTyxmvc9nilSp3mr3Rgtt6b1MPw=
github.com/google/go-github/v90 v90.0.0 h1:EnX9HvTfqvuJbUSWu1/jLrYH6JJLMz0w0qfQVbTxPzE=
github.com/google/go-github/v90 v90.0.0/go.mod h1:pLzt1FZURZyoTHT5/Z1UQY3b9fYyrbXH6aj7X+qgID4=
github.com/google/go-github/v91 v91.0.0 h1:fpulREh37uBvOj4kF0vLuzjwJ1HHmFcAfquNjJfmpYs=
github.com/google/go-github/v91 v91.0.0/go.mod h1:rHtn7haKvmkTLhUK/aCQypiIj/suWSB3rnS+a1FdH6M=
github.com/google/go-querystring v1.2.0 h1:yhqkPbu2/OH+V9BfpCVPZkNmUXhb2gBxJArfhIxNtP0=
github.com/google/go-querystring v1.2.0/go.mod h1:8IFJqpSRITyJ8QhQ13bmbeMBDfmeEJZD5A0egEOmkqU=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
Expand Down
2 changes: 1 addition & 1 deletion internal/gh/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"time"

"github.com/bradleyfalzon/ghinstallation/v2"
"github.com/google/go-github/v90/github"
"github.com/google/go-github/v91/github"
"golang.org/x/oauth2"

"github.com/DragonSecurity/gomgr/internal/config"
Expand Down
2 changes: 1 addition & 1 deletion internal/gh/installations.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sort"
"strings"

"github.com/google/go-github/v90/github"
"github.com/google/go-github/v91/github"
)

// accountTypeOrganization is what GitHub calls an installation account that is
Expand Down
2 changes: 1 addition & 1 deletion internal/gh/installations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"testing"

"github.com/google/go-github/v90/github"
"github.com/google/go-github/v91/github"

"github.com/DragonSecurity/gomgr/internal/config"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/gh/rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"time"

"github.com/google/go-github/v90/github"
"github.com/google/go-github/v91/github"

"github.com/DragonSecurity/gomgr/internal/util"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/gh/rate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
"time"

"github.com/google/go-github/v90/github"
"github.com/google/go-github/v91/github"
)

func TestRespectRate_Healthy(t *testing.T) {
Expand Down
75 changes: 38 additions & 37 deletions internal/sync/apply_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"time"

"github.com/google/go-github/v90/github"
"github.com/google/go-github/v91/github"

"github.com/DragonSecurity/gomgr/internal/gh"
"github.com/DragonSecurity/gomgr/internal/util"
Expand Down Expand Up @@ -52,14 +52,14 @@ func applyTeamCreate(ctx context.Context, c *gh.Client, ch util.Change) error {
name := detailString(d, "name")
var privacyPtr, descPtr *string
if pv := detailString(d, "privacy"); pv != "" {
privacyPtr = github.Ptr(pv)
privacyPtr = new(pv)
}
if dv := detailString(d, "description"); dv != "" {
descPtr = github.Ptr(dv)
descPtr = new(dv)
}
newTeam := github.NewTeam{Name: name, Privacy: privacyPtr, Description: descPtr}
newTeam := github.CreateTeamRequest{Name: name, Privacy: privacyPtr, Description: descPtr}
if nv := detailString(d, "notification_setting"); nv != "" {
newTeam.NotificationSetting = github.Ptr(nv)
newTeam.NotificationSetting = new(nv)
}
// The plan names the parent by slug, because at plan time the parent may
// not exist yet and so has no ID to name it by. hierarchyOrder guarantees
Expand All @@ -69,7 +69,7 @@ func applyTeamCreate(ctx context.Context, c *gh.Client, ch util.Change) error {
if err != nil {
return fmt.Errorf("create team %q: %w", name, err)
}
newTeam.ParentTeamID = github.Ptr(id)
newTeam.ParentTeamID = new(id)
}
_, _, err = c.REST.Teams.CreateTeam(ctx, org, newTeam)
if err != nil {
Expand Down Expand Up @@ -99,32 +99,33 @@ func applyTeamUpdate(ctx context.Context, c *gh.Client, ch util.Change) error {
org := detailString(d, "org")
slug := detailString(d, "slug")
name := detailString(d, "name")
newTeam := github.NewTeam{Name: name}
newTeam := github.UpdateTeamRequest{Name: new(name)}
// Presence of the key, not truthiness of the value. planTeams only includes
// "description" when it differs, so an empty one means "clear it" — and
// skipping it left the planner detecting a removal the apply never sent,
// re-planning the same change on every run while the description stayed.
if dv, ok := d["description"]; ok {
newTeam.Description = github.Ptr(fmt.Sprint(dv))
newTeam.Description = new(fmt.Sprint(dv))
}
if pv := detailString(d, "privacy"); pv != "" {
newTeam.Privacy = github.Ptr(pv)
newTeam.Privacy = new(pv)
}
if nv := detailString(d, "notification_setting"); nv != "" {
newTeam.NotificationSetting = github.Ptr(nv)
newTeam.NotificationSetting = new(nv)
}
// parent_team_id carries omitempty, so leaving it nil preserves whatever
// nesting the team already has. Clearing one takes the separate
// removeParent argument, which is why the planner distinguishes the two.
removeParent := detailBool(d, "remove_parent")
if parent := detailString(d, "parent"); parent != "" && !removeParent {
// nesting the team already has. Clearing one takes RemoveParentTeam, whose
// marshaller sends an explicit null instead, which is why the planner
// distinguishes the two.
newTeam.RemoveParentTeam = detailBool(d, "remove_parent")
if parent := detailString(d, "parent"); parent != "" && !newTeam.RemoveParentTeam {
id, err := parentTeamID(ctx, c, org, parent)
if err != nil {
return fmt.Errorf("update team %q: %w", slug, err)
}
newTeam.ParentTeamID = github.Ptr(id)
newTeam.ParentTeamID = new(id)
}
_, _, err = c.REST.Teams.EditTeamBySlug(ctx, org, slug, newTeam, removeParent)
_, _, err = c.REST.Teams.UpdateTeamBySlug(ctx, org, slug, newTeam)
if err != nil {
return fmt.Errorf("update team %q: %w", slug, err)
}
Expand Down Expand Up @@ -191,8 +192,8 @@ func applyRepoEnsure(ctx context.Context, c *gh.Client, ch util.Change) error {

_, _, err := c.REST.Repositories.CreateFromTemplate(ctx, templateOrg, templateRepo, github.TemplateRepoRequest{
Name: name,
Owner: github.Ptr(org),
Private: github.Ptr(private),
Owner: new(org),
Private: new(private),
})
if err != nil {
if !isRepoAlreadyExists(err) {
Expand All @@ -202,16 +203,16 @@ func applyRepoEnsure(ctx context.Context, c *gh.Client, ch util.Change) error {
}
} else {
repo := &github.Repository{
Name: github.Ptr(name),
Private: github.Ptr(private),
IsTemplate: github.Ptr(isTemplate),
AllowAutoMerge: github.Ptr(true),
AllowMergeCommit: github.Ptr(false),
DeleteBranchOnMerge: github.Ptr(true),
HasIssues: github.Ptr(true),
Name: new(name),
Private: new(private),
IsTemplate: new(isTemplate),
AllowAutoMerge: new(true),
AllowMergeCommit: new(false),
DeleteBranchOnMerge: new(true),
HasIssues: new(true),
}
if visibility != "" {
repo.Visibility = github.Ptr(visibility)
repo.Visibility = new(visibility)
}
_, _, err := c.REST.Repositories.Create(ctx, org, repo)
if err != nil {
Expand Down Expand Up @@ -307,9 +308,9 @@ func applyRepoFileEnsure(ctx context.Context, c *gh.Client, ch util.Change) erro
}
if file == nil {
_, _, err := c.REST.Repositories.CreateFile(ctx, org, repo, path, &github.RepositoryContentFileOptions{
Message: github.Ptr(message),
Message: new(message),
Content: content,
Branch: github.Ptr(branch),
Branch: new(branch),
})
if err != nil {
// Handle race condition: If repository was created from template,
Expand Down Expand Up @@ -340,10 +341,10 @@ func applyRepoFileEnsure(ctx context.Context, c *gh.Client, ch util.Change) erro
return nil
}
_, _, err = c.REST.Repositories.UpdateFile(ctx, org, repo, path, &github.RepositoryContentFileOptions{
Message: github.Ptr(message),
Message: new(message),
Content: content,
Branch: github.Ptr(branch),
SHA: github.Ptr(file.GetSHA()),
Branch: new(branch),
SHA: new(file.GetSHA()),
})
if err != nil {
return fmt.Errorf("update file %s in %s/%s: %w", path, org, repo, err)
Expand All @@ -369,9 +370,9 @@ func applyRepoFileDelete(ctx context.Context, c *gh.Client, ch util.Change) erro
return nil
}
_, _, err = c.REST.Repositories.DeleteFile(ctx, org, repo, path, &github.RepositoryContentFileOptions{
Message: github.Ptr(message),
Branch: github.Ptr(branch),
SHA: github.Ptr(file.GetSHA()),
Message: new(message),
Branch: new(branch),
SHA: new(file.GetSHA()),
})
if err != nil {
return fmt.Errorf("delete file %s in %s/%s: %w", path, org, repo, err)
Expand Down Expand Up @@ -420,7 +421,7 @@ func applyRepoTemplateEnsure(ctx context.Context, c *gh.Client, ch util.Change)
repo := detailString(d, "repo")

_, _, err = c.REST.Repositories.Edit(ctx, org, repo, &github.Repository{
IsTemplate: github.Ptr(true),
IsTemplate: new(true),
})
if err != nil {
return fmt.Errorf("mark repo %s/%s as template: %w", org, repo, err)
Expand Down Expand Up @@ -465,7 +466,7 @@ func applyOrgOwnerEnsure(ctx context.Context, c *gh.Client, ch util.Change) erro
org := detailString(d, "org")
user := detailString(d, "user")
_, _, err = c.REST.Organizations.EditOrgMembership(ctx, user, org, &github.Membership{
Role: github.Ptr(orgRoleAdmin),
Role: new(orgRoleAdmin),
})
if err != nil {
return fmt.Errorf("make %q an owner of org %q: %w", user, org, err)
Expand All @@ -485,7 +486,7 @@ func applyOrgOwnerRemove(ctx context.Context, c *gh.Client, ch util.Change) erro
org := detailString(d, "org")
user := detailString(d, "user")
_, _, err = c.REST.Organizations.EditOrgMembership(ctx, user, org, &github.Membership{
Role: github.Ptr(orgRoleMember),
Role: new(orgRoleMember),
})
if err != nil {
return fmt.Errorf("demote owner %q of org %q to member: %w", user, org, err)
Expand Down
2 changes: 1 addition & 1 deletion internal/sync/apply_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"testing"
"time"

"github.com/google/go-github/v90/github"
"github.com/google/go-github/v91/github"

"github.com/DragonSecurity/gomgr/internal/config"
"github.com/DragonSecurity/gomgr/internal/gh"
Expand Down
4 changes: 2 additions & 2 deletions internal/sync/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sort"
"strings"

"github.com/google/go-github/v90/github"
"github.com/google/go-github/v91/github"

"github.com/DragonSecurity/gomgr/internal/config"
"github.com/DragonSecurity/gomgr/internal/gh"
Expand Down Expand Up @@ -150,7 +150,7 @@ func applyRepoArchiveEnsure(ctx context.Context, c *gh.Client, ch util.Change) e
archived := detailBool(d, detailArchived)

_, _, err = c.REST.Repositories.Edit(ctx, org, repo, &github.Repository{
Archived: github.Ptr(archived),
Archived: new(archived),
})
if err != nil {
verb := "archive"
Expand Down
4 changes: 2 additions & 2 deletions internal/sync/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"testing"

"github.com/google/go-github/v90/github"
"github.com/google/go-github/v91/github"

"github.com/DragonSecurity/gomgr/internal/config"
"github.com/DragonSecurity/gomgr/internal/util"
Expand All @@ -17,7 +17,7 @@ import (
func boolPtr(b bool) *bool { return &b }

func repoFixture(name string, archived bool) *github.Repository {
return &github.Repository{Name: github.Ptr(name), Archived: github.Ptr(archived)}
return &github.Repository{Name: new(name), Archived: new(archived)}
}

// Omitting `archived:` and setting it to false are different instructions. An
Expand Down
2 changes: 1 addition & 1 deletion internal/sync/collaborators.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sort"
"strings"

"github.com/google/go-github/v90/github"
"github.com/google/go-github/v91/github"

"github.com/DragonSecurity/gomgr/internal/config"
"github.com/DragonSecurity/gomgr/internal/gh"
Expand Down
10 changes: 5 additions & 5 deletions internal/sync/collaborators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"testing"

"github.com/google/go-github/v90/github"
"github.com/google/go-github/v91/github"

"github.com/DragonSecurity/gomgr/internal/config"
"github.com/DragonSecurity/gomgr/internal/util"
Expand Down Expand Up @@ -123,7 +123,7 @@ func (w collabWorld) state() *State {
st.ManagedRepos[repo] = true
}
for _, slug := range w.teams {
st.ActualTeams = append(st.ActualTeams, &github.Team{Slug: github.Ptr(slug)})
st.ActualTeams = append(st.ActualTeams, &github.Team{Slug: new(slug)})
}
return st
}
Expand Down Expand Up @@ -345,8 +345,8 @@ func TestPlanCollaboratorsFollowsParentInheritance(t *testing.T) {

func TestCollaboratorPermissionPrefersRoleName(t *testing.T) {
u := &github.User{
RoleName: github.Ptr("write"),
Permissions: &github.RepositoryPermissions{Pull: github.Ptr(true)},
RoleName: new("write"),
Permissions: &github.RepositoryPermissions{Pull: new(true)},
}
if got := collaboratorPermission(u); got != permPush {
t.Errorf("role_name should win and normalize to push, got %q", got)
Expand All @@ -355,7 +355,7 @@ func TestCollaboratorPermissionPrefersRoleName(t *testing.T) {

func TestCollaboratorPermissionFallsBackToPermissionBlock(t *testing.T) {
u := &github.User{Permissions: &github.RepositoryPermissions{
Pull: github.Ptr(true), Push: github.Ptr(true), Maintain: github.Ptr(true),
Pull: new(true), Push: new(true), Maintain: new(true),
}}
if got := collaboratorPermission(u); got != permMaintain {
t.Errorf("want maintain, got %q", got)
Expand Down
10 changes: 5 additions & 5 deletions internal/sync/custom_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"strings"

"github.com/google/go-github/v90/github"
"github.com/google/go-github/v91/github"

"github.com/DragonSecurity/gomgr/internal/config"
"github.com/DragonSecurity/gomgr/internal/gh"
Expand Down Expand Up @@ -197,7 +197,7 @@ func applyCustomRoleChanges(ctx context.Context, c *gh.Client, changes []util.Ch
Permissions: d.Permissions,
}
if d.Description != "" {
req.Description = github.Ptr(d.Description)
req.Description = new(d.Description)
}

_, _, err := c.REST.Organizations.CreateCustomRepoRole(ctx, d.Org, req)
Expand All @@ -208,12 +208,12 @@ func applyCustomRoleChanges(ctx context.Context, c *gh.Client, changes []util.Ch

case "custom-role:update":
req := github.UpdateCustomRepoRoleRequest{
Name: github.Ptr(d.Name),
BaseRole: github.Ptr(d.BaseRole),
Name: new(d.Name),
BaseRole: new(d.BaseRole),
Permissions: d.Permissions,
}
if d.Description != "" {
req.Description = github.Ptr(d.Description)
req.Description = new(d.Description)
}

_, _, err := c.REST.Organizations.UpdateCustomRepoRole(ctx, d.Org, d.ID, req)
Expand Down
6 changes: 3 additions & 3 deletions internal/sync/file_strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package sync
import (
"testing"

"github.com/google/go-github/v90/github"
"github.com/google/go-github/v91/github"

"github.com/DragonSecurity/gomgr/internal/config"
)
Expand All @@ -15,8 +15,8 @@ func deciderFor(t *testing.T, org []config.RulesetConfig, perRepo map[string][]c
cfg.Org.Rulesets = org

st := &State{Org: "myorg", ActualRepos: []*github.Repository{
{Name: github.Ptr("infra"), DefaultBranch: github.Ptr("main")},
{Name: github.Ptr("legacy"), DefaultBranch: github.Ptr("master")},
{Name: new("infra"), DefaultBranch: new("main")},
{Name: new("legacy"), DefaultBranch: new("master")},
}}
settings := map[string]repoSettings{}
for repo, rs := range perRepo {
Expand Down
Loading
Loading