Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename sync to engine #31

Merged
merged 1 commit into from
Aug 30, 2023
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sync
package engine

type Comparable interface {
*GithubTeam | *GithubRepoComparable | *GithubRuleSet
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sync
package engine

import (
"encoding/json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sync
package engine

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sync
package engine

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion internal/sync/local.go → internal/engine/local.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sync
package engine

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sync
package engine

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sync
package engine

import (
"github.com/Alayacare/goliac/internal/slugify"
Expand Down
2 changes: 1 addition & 1 deletion internal/sync/plugins.go → internal/engine/plugins.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sync
package engine

import (
"github.com/Alayacare/goliac/internal/config"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sync
package engine

type ReconciliatorExecutor interface {
AddUserToOrg(ghuserid string)
Expand Down
2 changes: 1 addition & 1 deletion internal/sync/remote.go → internal/engine/remote.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sync
package engine

import (
"encoding/json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sync
package engine

import (
"encoding/json"
Expand Down
46 changes: 23 additions & 23 deletions internal/github_batch_executor.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package internal

import (
"github.com/Alayacare/goliac/internal/sync"
"github.com/Alayacare/goliac/internal/engine"
"github.com/sirupsen/logrus"
)

Expand All @@ -25,12 +25,12 @@ type GithubCommand interface {
* gal.Commit()
*/
type GithubBatchExecutor struct {
client sync.ReconciliatorExecutor
client engine.ReconciliatorExecutor
maxChangesets int
commands []GithubCommand
}

func NewGithubBatchExecutor(client sync.ReconciliatorExecutor, maxChangesets int) *GithubBatchExecutor {
func NewGithubBatchExecutor(client engine.ReconciliatorExecutor, maxChangesets int) *GithubBatchExecutor {
gal := GithubBatchExecutor{
client: client,
maxChangesets: maxChangesets,
Expand Down Expand Up @@ -147,14 +147,14 @@ func (g *GithubBatchExecutor) DeleteRepository(reponame string) {
})
}

func (g *GithubBatchExecutor) AddRuleset(ruleset *sync.GithubRuleSet) {
func (g *GithubBatchExecutor) AddRuleset(ruleset *engine.GithubRuleSet) {
g.commands = append(g.commands, &GithubCommandAddRuletset{
client: g.client,
ruleset: ruleset,
})
}

func (g *GithubBatchExecutor) UpdateRuleset(ruleset *sync.GithubRuleSet) {
func (g *GithubBatchExecutor) UpdateRuleset(ruleset *engine.GithubRuleSet) {
g.commands = append(g.commands, &GithubCommandUpdateRuletset{
client: g.client,
ruleset: ruleset,
Expand Down Expand Up @@ -186,7 +186,7 @@ func (g *GithubBatchExecutor) Commit() {
}

type GithubCommandAddUserToOrg struct {
client sync.ReconciliatorExecutor
client engine.ReconciliatorExecutor
ghuserid string
}

Expand All @@ -195,7 +195,7 @@ func (g *GithubCommandAddUserToOrg) Apply() {
}

type GithubCommandCreateRepository struct {
client sync.ReconciliatorExecutor
client engine.ReconciliatorExecutor
reponame string
description string
writers []string
Expand All @@ -208,7 +208,7 @@ func (g *GithubCommandCreateRepository) Apply() {
}

type GithubCommandCreateTeam struct {
client sync.ReconciliatorExecutor
client engine.ReconciliatorExecutor
teamname string
description string
members []string
Expand All @@ -219,7 +219,7 @@ func (g *GithubCommandCreateTeam) Apply() {
}

type GithubCommandDeleteRepository struct {
client sync.ReconciliatorExecutor
client engine.ReconciliatorExecutor
reponame string
}

Expand All @@ -228,7 +228,7 @@ func (g *GithubCommandDeleteRepository) Apply() {
}

type GithubCommandDeleteTeam struct {
client sync.ReconciliatorExecutor
client engine.ReconciliatorExecutor
teamslug string
}

Expand All @@ -237,7 +237,7 @@ func (g *GithubCommandDeleteTeam) Apply() {
}

type GithubCommandRemoveUserFromOrg struct {
client sync.ReconciliatorExecutor
client engine.ReconciliatorExecutor
ghuserid string
}

Expand All @@ -246,7 +246,7 @@ func (g *GithubCommandRemoveUserFromOrg) Apply() {
}

type GithubCommandUpdateRepositoryRemoveTeamAccess struct {
client sync.ReconciliatorExecutor
client engine.ReconciliatorExecutor
reponame string
teamslug string
}
Expand All @@ -256,7 +256,7 @@ func (g *GithubCommandUpdateRepositoryRemoveTeamAccess) Apply() {
}

type GithubCommandUpdateRepositoryAddTeamAccess struct {
client sync.ReconciliatorExecutor
client engine.ReconciliatorExecutor
reponame string
teamslug string
permission string
Expand All @@ -267,7 +267,7 @@ func (g *GithubCommandUpdateRepositoryAddTeamAccess) Apply() {
}

type GithubCommandUpdateRepositoryUpdateTeamAccess struct {
client sync.ReconciliatorExecutor
client engine.ReconciliatorExecutor
reponame string
teamslug string
permission string
Expand All @@ -278,7 +278,7 @@ func (g *GithubCommandUpdateRepositoryUpdateTeamAccess) Apply() {
}

type GithubCommandUpdateRepositoryUpdateArchived struct {
client sync.ReconciliatorExecutor
client engine.ReconciliatorExecutor
reponame string
archived bool
}
Expand All @@ -288,7 +288,7 @@ func (g *GithubCommandUpdateRepositoryUpdateArchived) Apply() {
}

type GithubCommandUpdateRepositoryUpdatePrivate struct {
client sync.ReconciliatorExecutor
client engine.ReconciliatorExecutor
reponame string
private bool
}
Expand All @@ -298,7 +298,7 @@ func (g *GithubCommandUpdateRepositoryUpdatePrivate) Apply() {
}

type GithubCommandUpdateTeamAddMember struct {
client sync.ReconciliatorExecutor
client engine.ReconciliatorExecutor
teamslug string
member string
role string
Expand All @@ -309,7 +309,7 @@ func (g *GithubCommandUpdateTeamAddMember) Apply() {
}

type GithubCommandUpdateTeamRemoveMember struct {
client sync.ReconciliatorExecutor
client engine.ReconciliatorExecutor
teamslug string
member string
}
Expand All @@ -319,25 +319,25 @@ func (g *GithubCommandUpdateTeamRemoveMember) Apply() {
}

type GithubCommandAddRuletset struct {
client sync.ReconciliatorExecutor
ruleset *sync.GithubRuleSet
client engine.ReconciliatorExecutor
ruleset *engine.GithubRuleSet
}

func (g *GithubCommandAddRuletset) Apply() {
g.client.AddRuleset(g.ruleset)
}

type GithubCommandUpdateRuletset struct {
client sync.ReconciliatorExecutor
ruleset *sync.GithubRuleSet
client engine.ReconciliatorExecutor
ruleset *engine.GithubRuleSet
}

func (g *GithubCommandUpdateRuletset) Apply() {
g.client.UpdateRuleset(g.ruleset)
}

type GithubCommandDeleteRuletset struct {
client sync.ReconciliatorExecutor
client engine.ReconciliatorExecutor
rulesetid int
}

Expand Down
24 changes: 15 additions & 9 deletions internal/goliac.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"strings"

"github.com/Alayacare/goliac/internal/config"
"github.com/Alayacare/goliac/internal/engine"
"github.com/Alayacare/goliac/internal/entity"
"github.com/Alayacare/goliac/internal/github"
"github.com/Alayacare/goliac/internal/sync"
"github.com/Alayacare/goliac/internal/usersync"
"github.com/sirupsen/logrus"
"github.com/spf13/afero"
Expand Down Expand Up @@ -37,11 +37,13 @@ type Goliac interface {

// flush remote cache
FlushCache()

GetLocal() engine.GoliacLocal
}

type GoliacImpl struct {
local sync.GoliacLocal
remote sync.GoliacRemoteExecutor
local engine.GoliacLocal
remote engine.GoliacRemoteExecutor
githubClient github.GitHubClient
repoconfig *config.RepositoryConfig
}
Expand All @@ -58,18 +60,22 @@ func NewGoliacImpl() (Goliac, error) {
return nil, err
}

remote := sync.NewGoliacRemoteImpl(githubClient)
remote := engine.NewGoliacRemoteImpl(githubClient)

usersync.InitPlugins(githubClient)

return &GoliacImpl{
local: sync.NewGoliacLocalImpl(),
local: engine.NewGoliacLocalImpl(),
githubClient: githubClient,
remote: remote,
repoconfig: &config.RepositoryConfig{},
}, nil
}

func (g *GoliacImpl) GetLocal() engine.GoliacLocal {
return g.local
}

func (g *GoliacImpl) FlushCache() {
g.remote.FlushCache()
}
Expand Down Expand Up @@ -122,7 +128,7 @@ func (g *GoliacImpl) ApplyToGithub(dryrun bool, teamreponame string, branch stri
commits, err := g.local.ListCommitsFromTag(GOLIAC_GIT_TAG)
if err != nil {
ga := NewGithubBatchExecutor(g.remote, g.repoconfig.MaxChangesets)
reconciliator := sync.NewGoliacReconciliatorImpl(ga, g.repoconfig)
reconciliator := engine.NewGoliacReconciliatorImpl(ga, g.repoconfig)

ctx := context.TODO()
err = reconciliator.Reconciliate(ctx, g.local, g.remote, teamreponame, dryrun)
Expand All @@ -133,9 +139,9 @@ func (g *GoliacImpl) ApplyToGithub(dryrun bool, teamreponame string, branch stri
for _, commit := range commits {
if err := g.local.CheckoutCommit(commit); err == nil {
ga := NewGithubBatchExecutor(g.remote, g.repoconfig.MaxChangesets)
reconciliator := sync.NewGoliacReconciliatorImpl(ga, g.repoconfig)
reconciliator := engine.NewGoliacReconciliatorImpl(ga, g.repoconfig)

ctx := context.WithValue(context.TODO(), sync.KeyAuthor, commit.Author.Email)
ctx := context.WithValue(context.TODO(), engine.KeyAuthor, commit.Author.Email)
err = reconciliator.Reconciliate(ctx, g.local, g.remote, teamreponame, dryrun)
if err != nil {
return fmt.Errorf("Error when reconciliating: %v", err)
Expand Down Expand Up @@ -179,7 +185,7 @@ func (g *GoliacImpl) UsersUpdate(repositoryUrl, branch string) error {
return fmt.Errorf("unable to read goliac.yaml config file: %v", err)
}

userplugin, found := sync.GetUserSyncPlugin(g.repoconfig.UserSync.Plugin)
userplugin, found := engine.GetUserSyncPlugin(g.repoconfig.UserSync.Plugin)
if !found {
return fmt.Errorf("User Sync Plugin %s not found", g.repoconfig.UserSync.Plugin)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/goliac_light.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

"github.com/Alayacare/goliac/internal/config"
"github.com/Alayacare/goliac/internal/sync"
"github.com/Alayacare/goliac/internal/engine"
"github.com/sirupsen/logrus"
"github.com/spf13/afero"
)
Expand All @@ -15,13 +15,13 @@ type GoliacLight interface {
}

type GoliacLightImpl struct {
local sync.GoliacLocal
local engine.GoliacLocal
repoconfig *config.RepositoryConfig
}

func NewGoliacLightImpl() (GoliacLight, error) {
return &GoliacLightImpl{
local: sync.NewGoliacLocalImpl(),
local: engine.NewGoliacLocalImpl(),
repoconfig: &config.RepositoryConfig{},
}, nil
}
Expand Down
8 changes: 4 additions & 4 deletions internal/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"strings"

"github.com/Alayacare/goliac/internal/config"
"github.com/Alayacare/goliac/internal/engine"
"github.com/Alayacare/goliac/internal/entity"
"github.com/Alayacare/goliac/internal/github"
"github.com/Alayacare/goliac/internal/sync"
"github.com/sirupsen/logrus"
"github.com/spf13/afero"
"gopkg.in/yaml.v3"
Expand All @@ -17,7 +17,7 @@ import (
type LoadGithubSamlUsers func() (map[string]*entity.User, error)

type Scaffold struct {
remote sync.GoliacRemote
remote engine.GoliacRemote
loadUsersFromGithubOrgSaml LoadGithubSamlUsers
}

Expand All @@ -33,12 +33,12 @@ func NewScaffold() (*Scaffold, error) {
return nil, err
}

remote := sync.NewGoliacRemoteImpl(githubClient)
remote := engine.NewGoliacRemoteImpl(githubClient)

return &Scaffold{
remote: remote,
loadUsersFromGithubOrgSaml: func() (map[string]*entity.User, error) {
return sync.LoadUsersFromGithubOrgSaml(githubClient)
return engine.LoadUsersFromGithubOrgSaml(githubClient)
},
}, nil
}
Expand Down
Loading