Rename gitlab to remotes
This commit is contained in:
parent
b944af140a
commit
da209c53e3
@ -7,8 +7,8 @@ import (
|
||||
"github.com/pterm/pterm"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/gitlab"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/projects"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes"
|
||||
)
|
||||
|
||||
var aliasAddCmd = &cobra.Command{
|
||||
@ -21,7 +21,7 @@ var aliasAddCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func runAddAliasCmd(cmd *cobra.Command, args []string) {
|
||||
var project *gitlab.Project
|
||||
var project *remotes.Project
|
||||
|
||||
// Check by flag
|
||||
if projectID := viper.GetInt("alias.add.projectid"); projectID > 0 {
|
||||
@ -76,7 +76,7 @@ func addNewAliases(projectID int) {
|
||||
}
|
||||
}
|
||||
|
||||
func promptAliasesForProject(p *gitlab.Project) []string {
|
||||
func promptAliasesForProject(p *remotes.Project) []string {
|
||||
aliases := cache.GetProjectAliases(p)
|
||||
if len(aliases) > 0 {
|
||||
plog.Info("Adding aliases to project", plog.Args(
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"github.com/pterm/pterm"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/gitlab"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes"
|
||||
)
|
||||
|
||||
var aliasDeleteCmd = &cobra.Command{
|
||||
@ -19,7 +19,7 @@ var aliasDeleteCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func runDeleteAliasCmd(cmd *cobra.Command, args []string) {
|
||||
var project *gitlab.Project
|
||||
var project *remotes.Project
|
||||
var err error
|
||||
|
||||
fzfOpts := &fzfProjectOpts{
|
||||
|
@ -3,8 +3,8 @@ package cmd
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/gitlab"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/projects"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes"
|
||||
)
|
||||
|
||||
var projectCmd = &cobra.Command{
|
||||
@ -19,7 +19,7 @@ var projectCmd = &cobra.Command{
|
||||
// Run: projectGoCmdRun,
|
||||
}
|
||||
|
||||
func getProject(args []string) *gitlab.Project {
|
||||
func getProject(args []string) *remotes.Project {
|
||||
gitlabs := viper.GetStringSlice("project.gitlabs")
|
||||
fzfOpts := &fzfProjectOpts{
|
||||
Ctx: rootCmd.Context(),
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"github.com/pterm/pterm"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/gitlab"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes"
|
||||
)
|
||||
|
||||
var projectShowCmd = &cobra.Command{
|
||||
@ -20,7 +20,7 @@ var projectShowCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func projectShowCmdRun(cmd *cobra.Command, args []string) {
|
||||
var project *gitlab.Project
|
||||
var project *remotes.Project
|
||||
var inCwd bool
|
||||
|
||||
gitlabs := viper.GetStringSlice("project.gitlabs")
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"context"
|
||||
|
||||
fzf "github.com/ktr0731/go-fuzzyfinder"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/gitlab"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/projects"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
@ -18,8 +18,8 @@ type fzfProjectOpts struct {
|
||||
|
||||
// This will try to find a project by alias if a search term
|
||||
// is given, otherwise will fuzzy find by project
|
||||
func fzfFindProject(opts *fzfProjectOpts) *gitlab.Project {
|
||||
var project *gitlab.Project
|
||||
func fzfFindProject(opts *fzfProjectOpts) *remotes.Project {
|
||||
var project *remotes.Project
|
||||
|
||||
if opts.Search != "" {
|
||||
project = fzfSearchProjectAliases(opts)
|
||||
@ -37,8 +37,8 @@ func fzfFindProject(opts *fzfProjectOpts) *gitlab.Project {
|
||||
// If . is given as a project, will open project from the
|
||||
// current working directory. Otherwise, will attempt to fuzzy-find
|
||||
// a project given a search term if provided
|
||||
func fzfCwdOrSearchProjectAliases(opts *fzfProjectOpts) *gitlab.Project {
|
||||
var project *gitlab.Project
|
||||
func fzfCwdOrSearchProjectAliases(opts *fzfProjectOpts) *remotes.Project {
|
||||
var project *remotes.Project
|
||||
if opts.Search == "." {
|
||||
project, _ = cache.GetProjectFromCwd()
|
||||
} else {
|
||||
@ -49,8 +49,8 @@ func fzfCwdOrSearchProjectAliases(opts *fzfProjectOpts) *gitlab.Project {
|
||||
|
||||
// This will fuzzy search only aliases, preferring an exact
|
||||
// match if one is given
|
||||
func fzfSearchProjectAliases(opts *fzfProjectOpts) *gitlab.Project {
|
||||
var project *gitlab.Project
|
||||
func fzfSearchProjectAliases(opts *fzfProjectOpts) *remotes.Project {
|
||||
var project *remotes.Project
|
||||
var alias *projects.ProjectAlias
|
||||
if alias = cache.GetAliasByName(opts.Search, opts.Gitlabs...); alias != nil {
|
||||
project = cache.GetProjectByAlias(alias)
|
||||
@ -96,7 +96,7 @@ func fzfAliasFromAliases(opts *fzfProjectOpts, aliases []*projects.ProjectAlias)
|
||||
// Given a list of aliases, merge them together and use the resulting
|
||||
// list of projects to return a project
|
||||
func fzfProjectFromAliases(opts *fzfProjectOpts, aliases []*projects.ProjectAlias) (
|
||||
*gitlab.Project, error) {
|
||||
*remotes.Project, error) {
|
||||
mergedProjects := projectsFromAliases(aliases)
|
||||
if len(mergedProjects) == 1 {
|
||||
return mergedProjects[0], nil
|
||||
@ -104,8 +104,8 @@ func fzfProjectFromAliases(opts *fzfProjectOpts, aliases []*projects.ProjectAlia
|
||||
return fzfProjectFromProjects(opts, mergedProjects)
|
||||
}
|
||||
|
||||
func projectsFromAliases(aliases []*projects.ProjectAlias) []*gitlab.Project {
|
||||
projects := make([]*gitlab.Project, 0)
|
||||
func projectsFromAliases(aliases []*projects.ProjectAlias) []*remotes.Project {
|
||||
projects := make([]*remotes.Project, 0)
|
||||
|
||||
ALIASES:
|
||||
for _, a := range aliases {
|
||||
@ -123,8 +123,8 @@ ALIASES:
|
||||
|
||||
// If opts.MustHaveAlias, will only allow selection of projects
|
||||
// that have at least one alias defined
|
||||
func fzfProject(opts *fzfProjectOpts) (*gitlab.Project, error) {
|
||||
var searchableProjects []*gitlab.Project
|
||||
func fzfProject(opts *fzfProjectOpts) (*remotes.Project, error) {
|
||||
var searchableProjects []*remotes.Project
|
||||
if opts.MustHaveAlias {
|
||||
searchableProjects = cache.GetProjectsWithAliases()
|
||||
} else {
|
||||
@ -136,8 +136,8 @@ func fzfProject(opts *fzfProjectOpts) (*gitlab.Project, error) {
|
||||
}
|
||||
|
||||
// Takes a list of projects and performs a fuzzyfind
|
||||
func fzfProjectFromProjects(opts *fzfProjectOpts, projects []*gitlab.Project) (
|
||||
*gitlab.Project, error) {
|
||||
func fzfProjectFromProjects(opts *fzfProjectOpts, projects []*remotes.Project) (
|
||||
*remotes.Project, error) {
|
||||
i, err := fzf.Find(projects,
|
||||
func(i int) string {
|
||||
// Display the project along with its aliases
|
||||
@ -162,8 +162,8 @@ func fzfPreviewWindow(i, w, h int) string {
|
||||
return cache.ProjectString(p)
|
||||
}
|
||||
|
||||
func filterProjectsWithGitlabs(projects []*gitlab.Project, gitlabs ...string) []*gitlab.Project {
|
||||
filteredProjects := make([]*gitlab.Project, 0, len(projects))
|
||||
func filterProjectsWithGitlabs(projects []*remotes.Project, gitlabs ...string) []*remotes.Project {
|
||||
filteredProjects := make([]*remotes.Project, 0, len(projects))
|
||||
if len(gitlabs) > 0 {
|
||||
for _, p := range projects {
|
||||
if slices.Contains(gitlabs, p.Remote) {
|
||||
|
@ -8,8 +8,8 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/config"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/gitlab"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/projects"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
@ -23,10 +23,10 @@ func initProjectCache(cmd *cobra.Command, args []string) {
|
||||
conf.Cache.File = conf.ProjectPath + "/.cache.yaml"
|
||||
|
||||
// Backwards-compatible support for singular instance
|
||||
opts := make([]*gitlab.ClientOpts, 0)
|
||||
opts := make([]*remotes.ClientOpts, 0)
|
||||
|
||||
if conf.GitlabHost != "" {
|
||||
opts = append(opts, &gitlab.ClientOpts{
|
||||
opts = append(opts, &remotes.ClientOpts{
|
||||
Ctx: cmd.Context(),
|
||||
Host: conf.GitlabHost, // deprecated, switch to gitlabs
|
||||
Token: conf.GitlabToken, // deprecated, switch to gitlabs
|
||||
@ -36,7 +36,7 @@ func initProjectCache(cmd *cobra.Command, args []string) {
|
||||
|
||||
// If defined, load additional instances
|
||||
for _, g := range conf.Gitlabs {
|
||||
opts = append(opts, &gitlab.ClientOpts{
|
||||
opts = append(opts, &remotes.ClientOpts{
|
||||
Ctx: cmd.Context(),
|
||||
Name: g.Name,
|
||||
Host: g.Host,
|
||||
@ -51,9 +51,9 @@ func initProjectCache(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
|
||||
// Load all gitlab configs into clients
|
||||
var gitlabs *gitlab.Clients
|
||||
var gitlabs *remotes.Clients
|
||||
var err error
|
||||
gitlabs, err = gitlab.NewGitlabClients(opts)
|
||||
gitlabs, err = remotes.NewGitlabClients(opts)
|
||||
if err != nil {
|
||||
plog.Error("Failed to create GitLab clients", plog.Args("error", err))
|
||||
os.Exit(1)
|
||||
|
@ -8,12 +8,12 @@ import (
|
||||
|
||||
"github.com/pterm/pterm"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/config"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/gitlab"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type Cache struct {
|
||||
Projects []*gitlab.Project
|
||||
Projects []*remotes.Project
|
||||
Aliases []*ProjectAlias
|
||||
Updated time.Time
|
||||
config *config.Config
|
||||
@ -24,7 +24,7 @@ type Cache struct {
|
||||
file string
|
||||
log *pterm.Logger
|
||||
path string
|
||||
gitlabs *gitlab.Clients
|
||||
gitlabs *remotes.Clients
|
||||
}
|
||||
|
||||
type CacheOpts struct {
|
||||
@ -32,7 +32,7 @@ type CacheOpts struct {
|
||||
ProjectsPath string
|
||||
TTL time.Duration
|
||||
Logger *pterm.Logger
|
||||
Gitlabs *gitlab.Clients
|
||||
Gitlabs *remotes.Clients
|
||||
Config *config.Config
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ func (c *Cache) Read() error {
|
||||
// project aliase cache. Writes to disk.
|
||||
func (c *Cache) clear(clearAliases bool) {
|
||||
c.log.Info("Clearing project cache")
|
||||
c.Projects = make([]*gitlab.Project, 0)
|
||||
c.Projects = make([]*remotes.Project, 0)
|
||||
if clearAliases {
|
||||
c.log.Info("Clearing project alias cache")
|
||||
c.Aliases = make([]*ProjectAlias, 0)
|
||||
@ -193,15 +193,15 @@ func NewProjectCache(opts *CacheOpts) (*Cache, error) {
|
||||
}
|
||||
|
||||
// Combine old-and-new gitlabs
|
||||
var gitlabs *gitlab.Clients
|
||||
var gitlabs *remotes.Clients
|
||||
if opts.Gitlabs != nil {
|
||||
gitlabs = opts.Gitlabs
|
||||
} else {
|
||||
gitlabs = gitlab.NewCLients()
|
||||
gitlabs = remotes.NewCLients()
|
||||
}
|
||||
|
||||
cache := &Cache{
|
||||
Projects: make([]*gitlab.Project, 0),
|
||||
Projects: make([]*remotes.Project, 0),
|
||||
Aliases: make([]*ProjectAlias, 0),
|
||||
config: opts.Config,
|
||||
file: opts.Path,
|
||||
|
@ -3,7 +3,7 @@ package projects
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/gitlab"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
@ -42,8 +42,8 @@ func (c *Cache) AddAlias(alias string, projectID int, remote string) error {
|
||||
return c.addAlias(alias, projectID, remote)
|
||||
}
|
||||
|
||||
func (c *Cache) GetProjectsWithAliases() []*gitlab.Project {
|
||||
projectList := make([]*gitlab.Project, 0)
|
||||
func (c *Cache) GetProjectsWithAliases() []*remotes.Project {
|
||||
projectList := make([]*remotes.Project, 0)
|
||||
projectsFound := make([]int, 0)
|
||||
for _, a := range c.Aliases {
|
||||
if !slices.Contains(projectsFound, a.ProjectID) {
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/pterm/pterm"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/gitlab"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes"
|
||||
)
|
||||
|
||||
func (c *Cache) LoadGitlabs() {
|
||||
@ -18,7 +18,7 @@ func (c *Cache) LoadGitlabs() {
|
||||
"name", gl.Config.Name,
|
||||
))
|
||||
|
||||
opts := *gitlab.DefaultListOpts
|
||||
opts := *remotes.DefaultListOpts
|
||||
opts.Owned = &c.config.Cache.Load.OwnerOnly
|
||||
projects := gl.GetTotalProjects(&opts)
|
||||
|
||||
@ -43,7 +43,7 @@ func (c *Cache) LoadGitlabs() {
|
||||
fmt.Println("")
|
||||
}
|
||||
|
||||
func (c *Cache) LoadGitlab(client *gitlab.Client, wg *sync.WaitGroup, pBar *pterm.ProgressbarPrinter, projects int) {
|
||||
func (c *Cache) LoadGitlab(client *remotes.Client, wg *sync.WaitGroup, pBar *pterm.ProgressbarPrinter, projects int) {
|
||||
defer wg.Done()
|
||||
progressInfo := client.StreamProjects(c.config.Cache.Load.OwnerOnly, projects)
|
||||
|
||||
|
@ -4,15 +4,15 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/pterm/pterm"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/gitlab"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
func (c *Cache) AddProjects(projects ...*gitlab.Project) {
|
||||
func (c *Cache) AddProjects(projects ...*remotes.Project) {
|
||||
c.contentLock.Lock()
|
||||
defer c.contentLock.Unlock()
|
||||
for _, p := range projects {
|
||||
var existing *gitlab.Project
|
||||
var existing *remotes.Project
|
||||
sameID := c.GetProjectsByID(p.ID)
|
||||
|
||||
// If there is only one by ID, we don't
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/lithammer/fuzzysearch/fuzzy"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/gitlab"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes"
|
||||
)
|
||||
|
||||
// Performs a fuzzy find on the input string, returning the closest
|
||||
@ -39,8 +39,8 @@ func (c *Cache) FuzzyFindAlias(name string) []*ProjectAlias {
|
||||
|
||||
// Returns all matching projects by fuzzy find term
|
||||
// Matches NameWithNamespace and Aliases
|
||||
func (c *Cache) FuzzyFindProjects(search string) []*gitlab.Project {
|
||||
projects := make([]*gitlab.Project, 0, len(c.Projects))
|
||||
func (c *Cache) FuzzyFindProjects(search string) []*remotes.Project {
|
||||
projects := make([]*remotes.Project, 0, len(c.Projects))
|
||||
for _, p := range c.Projects {
|
||||
if fuzzy.MatchFold(search, p.NameWithNamespace) {
|
||||
projects = append(projects, p)
|
||||
|
@ -4,11 +4,11 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/pterm/pterm"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/gitlab"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
func (c *Cache) ProjectString(p *gitlab.Project) string {
|
||||
func (c *Cache) ProjectString(p *remotes.Project) string {
|
||||
info := strings.Builder{}
|
||||
|
||||
info.WriteString(pterm.LightGreen("\n--------------\n"))
|
||||
@ -42,7 +42,7 @@ func (c *Cache) ProjectStrings(prefix string) []string {
|
||||
return slices.Clip(projects)
|
||||
}
|
||||
|
||||
func (c *Cache) GetProjectByPath(path string) *gitlab.Project {
|
||||
func (c *Cache) GetProjectByPath(path string) *remotes.Project {
|
||||
for _, p := range c.Projects {
|
||||
if p.PathWithNamespace == path {
|
||||
return p
|
||||
@ -51,7 +51,7 @@ func (c *Cache) GetProjectByPath(path string) *gitlab.Project {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cache) GetProjectByRemoteAndId(remote string, id int) *gitlab.Project {
|
||||
func (c *Cache) GetProjectByRemoteAndId(remote string, id int) *remotes.Project {
|
||||
for _, p := range c.Projects {
|
||||
if p.ID == id && p.Remote == remote {
|
||||
return p
|
||||
@ -60,7 +60,7 @@ func (c *Cache) GetProjectByRemoteAndId(remote string, id int) *gitlab.Project {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cache) GetProjectByID(id int) *gitlab.Project {
|
||||
func (c *Cache) GetProjectByID(id int) *remotes.Project {
|
||||
for _, p := range c.Projects {
|
||||
if p.ID == id {
|
||||
return p
|
||||
@ -72,8 +72,8 @@ func (c *Cache) GetProjectByID(id int) *gitlab.Project {
|
||||
// Plural form of GetProjectByID
|
||||
// Since multiple remotes may have the same project ID,
|
||||
// this will return all matching
|
||||
func (c *Cache) GetProjectsByID(id int) []*gitlab.Project {
|
||||
projects := make([]*gitlab.Project, 0)
|
||||
func (c *Cache) GetProjectsByID(id int) []*remotes.Project {
|
||||
projects := make([]*remotes.Project, 0)
|
||||
for _, p := range c.Projects {
|
||||
if p.ID == id {
|
||||
projects = append(projects, p)
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/pterm/pterm"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/gitlab"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
@ -17,7 +17,7 @@ type ProjectAlias struct {
|
||||
Remote string
|
||||
}
|
||||
|
||||
func (c *Cache) GetProjectAliasStrings(project *gitlab.Project) []string {
|
||||
func (c *Cache) GetProjectAliasStrings(project *remotes.Project) []string {
|
||||
aliases := c.GetProjectAliases(project)
|
||||
strings := make([]string, len(aliases))
|
||||
for i, a := range c.GetProjectAliases(project) {
|
||||
@ -26,7 +26,7 @@ func (c *Cache) GetProjectAliasStrings(project *gitlab.Project) []string {
|
||||
return strings
|
||||
}
|
||||
|
||||
func (c *Cache) GetProjectStringWithAliases(project *gitlab.Project) string {
|
||||
func (c *Cache) GetProjectStringWithAliases(project *remotes.Project) string {
|
||||
aliases := c.GetProjectAliasStrings(project)
|
||||
return fmt.Sprintf("%s (%s) -> %s",
|
||||
project.Name,
|
||||
@ -83,7 +83,7 @@ func (c *Cache) GetAliasByName(name string, gitlabs ...string) *ProjectAlias {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cache) GetProjectByAlias(alias *ProjectAlias) *gitlab.Project {
|
||||
func (c *Cache) GetProjectByAlias(alias *ProjectAlias) *remotes.Project {
|
||||
if alias == nil {
|
||||
return nil
|
||||
}
|
||||
@ -95,7 +95,7 @@ func (c *Cache) GetProjectByAlias(alias *ProjectAlias) *gitlab.Project {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cache) GetProjectAliases(project *gitlab.Project) []*ProjectAlias {
|
||||
func (c *Cache) GetProjectAliases(project *remotes.Project) []*ProjectAlias {
|
||||
aliases := make([]*ProjectAlias, 0)
|
||||
for _, alias := range c.Aliases {
|
||||
if alias.ProjectID == project.ID {
|
||||
|
@ -6,10 +6,10 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/gitlab"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes"
|
||||
)
|
||||
|
||||
func (c *Cache) GoTo(project *gitlab.Project) {
|
||||
func (c *Cache) GoTo(project *remotes.Project) {
|
||||
pPath := c.GetProjectPath(project)
|
||||
|
||||
c.log.Debug("Going to project", c.log.Args(
|
||||
@ -25,8 +25,8 @@ func (c *Cache) GoTo(project *gitlab.Project) {
|
||||
os.Chdir(filepath.Dir(pPath))
|
||||
}
|
||||
|
||||
func (c *Cache) GetProjectFromCwd() (*gitlab.Project, error) {
|
||||
var project *gitlab.Project
|
||||
func (c *Cache) GetProjectFromCwd() (*remotes.Project, error) {
|
||||
var project *remotes.Project
|
||||
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
@ -46,7 +46,7 @@ func (c *Cache) GetProjectFromCwd() (*gitlab.Project, error) {
|
||||
return project, nil
|
||||
}
|
||||
|
||||
func (c *Cache) IsProjectCloned(p *gitlab.Project) bool {
|
||||
func (c *Cache) IsProjectCloned(p *remotes.Project) bool {
|
||||
_, err := os.Stat(c.GetProjectPath(p) + "/.git")
|
||||
if err == nil {
|
||||
return true
|
||||
@ -63,6 +63,6 @@ func (c *Cache) PrepProjectPath(path string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cache) GetProjectPath(p *gitlab.Project) string {
|
||||
func (c *Cache) GetProjectPath(p *remotes.Project) string {
|
||||
return c.path + "/" + p.SanitizedPath()
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
git "github.com/go-git/go-git/v5"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/gitlab"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes"
|
||||
)
|
||||
|
||||
const gitCloneTimeoutSecs = 30
|
||||
@ -13,7 +13,7 @@ const gitCloneTimeoutSecs = 30
|
||||
// Will either read in the current repo, preparing a report
|
||||
// on its current state, or will clone the project if it has not
|
||||
// already been cloned in its path
|
||||
func (c *Cache) OpenProject(ctx context.Context, project *gitlab.Project) *git.Repository {
|
||||
func (c *Cache) OpenProject(ctx context.Context, project *remotes.Project) *git.Repository {
|
||||
path := c.GetProjectPath(project)
|
||||
cloneCtx, cncl := context.WithDeadline(ctx, time.Now().Add(gitCloneTimeoutSecs*time.Second))
|
||||
defer cncl()
|
||||
@ -31,7 +31,7 @@ func (c *Cache) OpenProject(ctx context.Context, project *gitlab.Project) *git.R
|
||||
// Check to make sure we can connect before we time out
|
||||
// shouldn't be necessary, but go-git does not properly
|
||||
// honor its context
|
||||
if err := project.CheckHost(gitlab.GitlabProtoSSH); err != nil {
|
||||
if err := project.CheckHost(remotes.GitlabProtoSSH); err != nil {
|
||||
c.log.Fatal("Git remote unreachable, giving up", c.log.Args("error", err))
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package gitlab
|
||||
package remotes
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -1,4 +1,4 @@
|
||||
package gitlab
|
||||
package remotes
|
||||
|
||||
import (
|
||||
"context"
|
@ -1,4 +1,4 @@
|
||||
package gitlab
|
||||
package remotes
|
||||
|
||||
import "github.com/pterm/pterm"
|
||||
|
@ -1,4 +1,4 @@
|
||||
package gitlab
|
||||
package remotes
|
||||
|
||||
import (
|
||||
"sync"
|
@ -1,4 +1,4 @@
|
||||
package gitlab
|
||||
package remotes
|
||||
|
||||
import (
|
||||
"errors"
|
Loading…
Reference in New Issue
Block a user