Skip to content

Commit

Permalink
switch slug library
Browse files Browse the repository at this point in the history
  • Loading branch information
nzin committed Sep 4, 2023
1 parent d6f59f8 commit 717ce36
Show file tree
Hide file tree
Showing 11 changed files with 1,075 additions and 106 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ require (
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/gosimple/slug v1.13.1 // indirect
github.com/gosimple/unidecode v1.0.1 // 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
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
github.com/gosimple/slug v1.13.1 h1:bQ+kpX9Qa6tHRaK+fZR0A0M2Kd7Pa5eHPPsb1JpHD+Q=
github.com/gosimple/slug v1.13.1/go.mod h1:UiRaFH+GEilHstLUmcBgWcI42viBN7mAb818JrYOeFQ=
github.com/gosimple/unidecode v1.0.1 h1:hZzFTMMqSswvf0LBJZCZgThIZrpDHFXux9KeGmn6T/o=
github.com/gosimple/unidecode v1.0.1/go.mod h1:CP0Cr1Y1kogOtx0bJblKzsVWrqYaqfNOnHzpgWw4Awc=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down
12 changes: 6 additions & 6 deletions internal/engine/goliac_reconciliator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/Alayacare/goliac/internal/config"
"github.com/Alayacare/goliac/internal/entity"
"github.com/Alayacare/goliac/internal/slugify"
"github.com/gosimple/slug"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -119,7 +119,7 @@ func (r *GoliacReconciliatorImpl) reconciliateTeams(ctx context.Context, local G
members = append(members, teamvalue.Data.Members...)
members = append(members, teamvalue.Data.Owners...)

teamslug := slugify.Make(teamname)
teamslug := slug.Make(teamname)
slugTeams[teamslug] = &GithubTeam{
Name: teamname,
Slug: teamslug,
Expand Down Expand Up @@ -250,21 +250,21 @@ func (r *GoliacReconciliatorImpl) reconciliateRepositories(ctx context.Context,
for reponame, lRepo := range local.Repositories() {
writers := make([]string, 0)
for _, w := range lRepo.Data.Writers {
writers = append(writers, slugify.Make(w))
writers = append(writers, slug.Make(w))
}
// add the team owner's name ;-)
if lRepo.Owner != nil {
writers = append(writers, slugify.Make(*lRepo.Owner))
writers = append(writers, slug.Make(*lRepo.Owner))
}
readers := make([]string, 0)
for _, r := range lRepo.Data.Readers {
readers = append(readers, slugify.Make(r))
readers = append(readers, slug.Make(r))
}

// special case for the Goliac "teams" repo
if reponame == teamsreponame {
for teamname := range local.Teams() {
writers = append(writers, slugify.Make(teamname)+"-owners")
writers = append(writers, slug.Make(teamname)+"-owners")
}
}

Expand Down
8 changes: 4 additions & 4 deletions internal/engine/goliac_reconciliator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (

"github.com/Alayacare/goliac/internal/config"
"github.com/Alayacare/goliac/internal/entity"
"github.com/Alayacare/goliac/internal/slugify"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/gosimple/slug"
"github.com/spf13/afero"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -94,7 +94,7 @@ func (m *GoliacRemoteMock) Users() map[string]string {
func (m *GoliacRemoteMock) TeamSlugByName() map[string]string {
slugs := make(map[string]string)
for _, v := range m.teams {
slugs[v.Name] = slugify.Make(v.Name)
slugs[v.Name] = slug.Make(v.Name)
}
return slugs
}
Expand Down Expand Up @@ -306,8 +306,8 @@ func TestReconciliation(t *testing.T) {
r.Reconciliate(context.TODO(), &local, &remote, "teams", false)

// 2 members created
assert.Equal(t, 2, len(recorder.TeamsCreated["nouveaut"]))
assert.Equal(t, 1, len(recorder.TeamsCreated["nouveaut-owners"]))
assert.Equal(t, 2, len(recorder.TeamsCreated["nouveaute"]))
assert.Equal(t, 1, len(recorder.TeamsCreated["nouveaute-owners"]))
})

t.Run("happy path: existing team with new members", func(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions internal/engine/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (

"github.com/Alayacare/goliac/internal/config"
"github.com/Alayacare/goliac/internal/entity"
"github.com/Alayacare/goliac/internal/slugify"
"github.com/go-git/go-git/v5"
goconfig "github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/go-git/go-git/v5/plumbing/transport"
"github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/gosimple/slug"
"github.com/sirupsen/logrus"
"github.com/spf13/afero"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -290,7 +290,7 @@ func (g *GoliacLocalImpl) LoadRepoConfig() (error, *config.RepositoryConfig) {

func (g *GoliacLocalImpl) codeowners_regenerate(adminteam string) string {
codeowners := "# DO NOT MODIFY THIS FILE MANUALLY\n"
codeowners += fmt.Sprintf("* @%s/%s\n", config.Config.GithubAppOrganization, slugify.Make(adminteam))
codeowners += fmt.Sprintf("* @%s/%s\n", config.Config.GithubAppOrganization, slug.Make(adminteam))

teamsnames := make([]string, 0)
for _, t := range g.teams {
Expand All @@ -299,7 +299,7 @@ func (g *GoliacLocalImpl) codeowners_regenerate(adminteam string) string {
sort.Strings(teamsnames)

for _, t := range teamsnames {
codeowners += fmt.Sprintf("/teams/%s/* @%s/%s-owners @%s/%s\n", t, config.Config.GithubAppOrganization, slugify.Make(t), config.Config.GithubAppOrganization, slugify.Make(adminteam))
codeowners += fmt.Sprintf("/teams/%s/* @%s/%s-owners @%s/%s\n", t, config.Config.GithubAppOrganization, slug.Make(t), config.Config.GithubAppOrganization, slug.Make(adminteam))
}

return codeowners
Expand Down
6 changes: 2 additions & 4 deletions internal/engine/mutable_remote.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package engine

import (
"github.com/Alayacare/goliac/internal/slugify"
)
import "github.com/gosimple/slug"

/*
* MutableGoliacRemoteImpl is used by GoliacReconciliatorImpl to update
Expand Down Expand Up @@ -106,7 +104,7 @@ func (m *MutableGoliacRemoteImpl) RemoveUserFromOrg(ghuserid string) {
}

func (m *MutableGoliacRemoteImpl) CreateTeam(teamname string, description string, members []string) {
teamslug := slugify.Make(teamname)
teamslug := slug.Make(teamname)
t := GithubTeam{
Name: teamname,
Slug: teamslug,
Expand Down
Loading

0 comments on commit 717ce36

Please sign in to comment.