Skip to content

Commit

Permalink
👻 Better modeling of SCM and maven. (#53)
Browse files Browse the repository at this point in the history
The Remote currently contains a *api.Repository which is good for the
SCM repositories but not relevant for Maven. After this is removed,
Remote only provides common _authentication_ attributes/operations. This
is the only thing SCM and Maven repositories have in common.

---------

Signed-off-by: Jeff Ortel <[email protected]>
  • Loading branch information
jortel authored Aug 13, 2024
1 parent f117cd5 commit 3153a61
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
35 changes: 15 additions & 20 deletions repository/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,23 @@ func New(destDir string, remote *api.Repository, identities []api.Ref) (r SCM, e
if err != nil {
return
}
r = &Subversion{
Path: destDir,
Remote: Remote{
Repository: remote,
Identities: identities,
Insecure: insecure,
},
}
svn := &Subversion{}
svn.Path = destDir
svn.Remote = *remote
svn.Identities = identities
svn.Insecure = insecure
r = svn
default:
insecure, err = addon.Setting.Bool("git.insecure.enabled")
if err != nil {
return
}
r = &Git{
Path: destDir,
Remote: Remote{
Repository: remote,
Identities: identities,
Insecure: insecure,
},
}
git := &Git{}
git.Path = destDir
git.Remote = *remote
git.Identities = identities
git.Insecure = insecure
r = git
}
err = r.Validate()
return
Expand All @@ -60,15 +56,14 @@ type SCM interface {
Head() (commit string, err error)
}

// Remote repository.
type Remote struct {
*api.Repository
// Authenticated repository.
type Authenticated struct {
Identities []api.Ref
Insecure bool
}

// FindIdentity by kind.
func (r *Remote) findIdentity(kind string) (matched *api.Identity, found bool, err error) {
func (r *Authenticated) findIdentity(kind string) (matched *api.Identity, found bool, err error) {
for _, ref := range r.Identities {
identity, nErr := addon.Identity.Get(ref.ID)
if nErr != nil {
Expand Down
5 changes: 3 additions & 2 deletions repository/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import (

// Git repository.
type Git struct {
Remote
Path string
Authenticated
Remote api.Repository
Path string
}

// Validate settings.
Expand Down
2 changes: 1 addition & 1 deletion repository/maven.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const emptySettings = `

// Maven repository.
type Maven struct {
Remote
Authenticated
BinDir string
M2Dir string
}
Expand Down
5 changes: 3 additions & 2 deletions repository/subversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import (

// Subversion repository.
type Subversion struct {
Remote
Path string
Authenticated
Remote api.Repository
Path string
}

// Validate settings.
Expand Down

0 comments on commit 3153a61

Please sign in to comment.