Skip to content

Commit

Permalink
Updates and try to get owner from gh installation account.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 committed Jan 9, 2024
1 parent 6cf558e commit 345e57a
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 522 deletions.
44 changes: 23 additions & 21 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,68 @@ go 1.21
require (
github.com/Masterminds/semver/v3 v3.2.1
github.com/atedja/go-multilock v0.0.0-20170315063113-31d195f255fb
github.com/bradleyfalzon/ghinstallation/v2 v2.8.0
github.com/bradleyfalzon/ghinstallation/v2 v2.9.0
github.com/go-git/go-billy/v5 v5.5.0
// IMPORTANT: keep this version as long as https://github.com/go-git/go-git/issues/328 is open
github.com/go-git/go-git/v5 v5.3.0
github.com/go-playground/validator/v10 v10.15.5
github.com/go-git/go-git/v5 v5.11.0
github.com/go-playground/validator/v10 v10.16.0
github.com/go-playground/webhooks/v6 v6.3.0
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v56 v56.0.0
github.com/google/go-github/v57 v57.0.0
github.com/metal-stack/v v1.0.3
github.com/mitchellh/mapstructure v1.5.0
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.17.0
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2
github.com/tidwall/gjson v1.17.0
github.com/tidwall/sjson v1.2.5
go.uber.org/zap v1.26.0
golang.org/x/sync v0.4.0
sigs.k8s.io/yaml v1.3.0
golang.org/x/sync v0.6.0
sigs.k8s.io/yaml v1.4.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/imdario/mergo v0.3.15 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.13.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
572 changes: 87 additions & 485 deletions go.sum

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion pkg/clients/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/metal-stack/metal-robot/pkg/config"
"go.uber.org/zap"

v3 "github.com/google/go-github/v56/github"
v3 "github.com/google/go-github/v57/github"
)

type Github struct {
Expand All @@ -18,6 +18,7 @@ type Github struct {
appID int64
installationID int64
organizationID string
owner string
atr *ghinstallation.AppsTransport
itr *ghinstallation.Transport
}
Expand Down Expand Up @@ -49,6 +50,8 @@ func (a *Github) initClients() error {
return fmt.Errorf("error finding organization installation %w", err)
}

a.owner = *installation.Account.Login

a.installationID = installation.GetID()

itr := ghinstallation.NewFromAppsTransport(atr, a.installationID)
Expand Down Expand Up @@ -84,3 +87,7 @@ func (a *Github) GitToken(ctx context.Context) (string, error) {
}
return t.GetToken(), nil
}

func (a *Github) Owner() string {
return a.owner
}
9 changes: 2 additions & 7 deletions pkg/webhooks/github/actions/aggregate_releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/Masterminds/semver/v3"
"github.com/atedja/go-multilock"
v3 "github.com/google/go-github/v56/github"
v3 "github.com/google/go-github/v57/github"
"github.com/metal-stack/metal-robot/pkg/clients"
"github.com/metal-stack/metal-robot/pkg/config"
"github.com/metal-stack/metal-robot/pkg/git"
Expand Down Expand Up @@ -113,17 +113,12 @@ func (r *AggregateReleases) AggregateRelease(ctx context.Context, p *AggregateRe

tag := p.TagName
trimmed := strings.TrimPrefix(tag, "v")
parsedVersion, err := semver.NewVersion(trimmed)
_, err := semver.NewVersion(trimmed)
if err != nil {
r.logger.Infow("skip applying release actions to aggregation repo because not a valid semver release tag", "target-repo", r.repoName, "source-repo", p.RepositoryName, "tag", p.TagName)
return nil //nolint:nilerr
}

if parsedVersion.Prerelease() != "" {
r.logger.Infow("skip applying release actions to aggregation repo because is a pre-release", "target-repo", r.repoName, "source-repo", p.RepositoryName, "tag", p.TagName)
return nil //nolint:nilerr
}

// preventing concurrent git repo modifications
var once sync.Once
r.lock.Lock()
Expand Down
16 changes: 15 additions & 1 deletion pkg/webhooks/github/actions/distribute_releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (

"errors"

"github.com/Masterminds/semver/v3"
"github.com/atedja/go-multilock"
v3 "github.com/google/go-github/v56/github"
v3 "github.com/google/go-github/v57/github"
"github.com/metal-stack/metal-robot/pkg/clients"
"github.com/metal-stack/metal-robot/pkg/config"
"github.com/metal-stack/metal-robot/pkg/git"
Expand Down Expand Up @@ -113,6 +114,19 @@ func (d *distributeReleases) DistributeRelease(ctx context.Context, p *distribut
return nil
}

trimmed := strings.TrimPrefix(tag, "v")

parsedVersion, err := semver.NewVersion(trimmed)
if err != nil {
d.logger.Infow("skip applying release actions to target repos because not a valid semver release tag", "source-repo", d.repoName, "trigger-repo", p.RepositoryName, "tag", p.TagName)
return nil //nolint:nilerr
}

if parsedVersion.Prerelease() != "" {
d.logger.Infow("skip applying release actions to target repos because is a pre-release", "source-repo", d.repoName, "trigger-repo", p.RepositoryName, "tag", p.TagName)
return nil //nolint:nilerr
}

token, err := d.client.GitToken(ctx)
if err != nil {
return fmt.Errorf("error creating git token %w", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhooks/github/actions/docs_preview_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

v3 "github.com/google/go-github/v56/github"
v3 "github.com/google/go-github/v57/github"
"github.com/metal-stack/metal-robot/pkg/clients"
"github.com/metal-stack/metal-robot/pkg/config"
"github.com/mitchellh/mapstructure"
Expand Down
4 changes: 2 additions & 2 deletions pkg/webhooks/github/actions/release_drafter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
"strings"

"github.com/Masterminds/semver/v3"
"github.com/google/go-github/v56/github"
"github.com/google/go-github/v57/github"
"github.com/metal-stack/metal-robot/pkg/clients"
"github.com/metal-stack/metal-robot/pkg/config"
"github.com/metal-stack/metal-robot/pkg/markdown"
"github.com/metal-stack/metal-robot/pkg/utils"
"github.com/mitchellh/mapstructure"
"go.uber.org/zap"

v3 "github.com/google/go-github/v56/github"
v3 "github.com/google/go-github/v57/github"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhooks/github/actions/release_drafter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/Masterminds/semver/v3"
"github.com/google/go-cmp/cmp"
v3 "github.com/google/go-github/v56/github"
v3 "github.com/google/go-github/v57/github"
"go.uber.org/zap/zaptest"
)

Expand Down
4 changes: 2 additions & 2 deletions pkg/webhooks/github/actions/repository_maintainers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"strings"

v3 "github.com/google/go-github/v56/github"
v3 "github.com/google/go-github/v57/github"
"github.com/metal-stack/metal-robot/pkg/clients"
"github.com/metal-stack/metal-robot/pkg/config"
"github.com/mitchellh/mapstructure"
Expand Down Expand Up @@ -88,7 +88,7 @@ func (r *repositoryMaintainers) CreateRepositoryMaintainers(ctx context.Context,
for _, additionalTeam := range r.additionalTeams {
additionalTeam := additionalTeam

_, err := r.client.GetV3Client().Teams.AddTeamRepoBySlug(ctx, r.client.Organization(), additionalTeam.teamSlug, r.client.Organization(), p.RepositoryName, &v3.TeamAddTeamRepoOptions{
_, err := r.client.GetV3Client().Teams.AddTeamRepoBySlug(ctx, r.client.Organization(), additionalTeam.teamSlug, r.client.Owner(), p.RepositoryName, &v3.TeamAddTeamRepoOptions{
Permission: additionalTeam.permission,
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhooks/github/actions/yaml_translate_releases.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/Masterminds/semver/v3"
"github.com/atedja/go-multilock"
v3 "github.com/google/go-github/v56/github"
v3 "github.com/google/go-github/v57/github"
"github.com/metal-stack/metal-robot/pkg/clients"
"github.com/metal-stack/metal-robot/pkg/config"
"github.com/metal-stack/metal-robot/pkg/git"
Expand Down

0 comments on commit 345e57a

Please sign in to comment.