From 3153a61e7c46cfed0a51b165fa0afee576e5df45 Mon Sep 17 00:00:00 2001 From: Jeff Ortel Date: Tue, 13 Aug 2024 10:22:19 -0500 Subject: [PATCH] :ghost: Better modeling of SCM and maven. (#53) 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 --- repository/factory.go | 35 +++++++++++++++-------------------- repository/git.go | 5 +++-- repository/maven.go | 2 +- repository/subversion.go | 5 +++-- 4 files changed, 22 insertions(+), 25 deletions(-) diff --git a/repository/factory.go b/repository/factory.go index 2cb40ea..fe65bfa 100644 --- a/repository/factory.go +++ b/repository/factory.go @@ -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 @@ -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 { diff --git a/repository/git.go b/repository/git.go index 498e7b0..384b460 100644 --- a/repository/git.go +++ b/repository/git.go @@ -17,8 +17,9 @@ import ( // Git repository. type Git struct { - Remote - Path string + Authenticated + Remote api.Repository + Path string } // Validate settings. diff --git a/repository/maven.go b/repository/maven.go index 48f22fd..2350bdd 100644 --- a/repository/maven.go +++ b/repository/maven.go @@ -21,7 +21,7 @@ const emptySettings = ` // Maven repository. type Maven struct { - Remote + Authenticated BinDir string M2Dir string } diff --git a/repository/subversion.go b/repository/subversion.go index 5344dcc..f4102dd 100644 --- a/repository/subversion.go +++ b/repository/subversion.go @@ -18,8 +18,9 @@ import ( // Subversion repository. type Subversion struct { - Remote - Path string + Authenticated + Remote api.Repository + Path string } // Validate settings.