Skip to content

Commit

Permalink
Add source column
Browse files Browse the repository at this point in the history
  • Loading branch information
kutluhanmetin committed Aug 24, 2023
1 parent b34723b commit 01b7617
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions base/commands/project/project_list_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"net/http"
"os"
"path/filepath"
"strconv"
"strings"
"time"
Expand All @@ -30,11 +31,13 @@ const (
nextFetchTimeKey = "project.templates.nextFetchTime"
templatesKey = "project.templates"
cacheRefreshInterval = 10 * time.Minute
storeFolder = "store"
)

var storeFolder = filepath.Join("caches", "templates")

type Template struct {
Name string `json:"name"`
Name string `json:"name"`
Source string
}

func (lc ListCmd) Init(cc plug.InitContext) error {
Expand Down Expand Up @@ -67,6 +70,11 @@ func (lc ListCmd) Exec(ctx context.Context, ec plug.ExecContext) error {
rows := make([]output.Row, len(tss))
for i, t := range tss {
rows[i] = output.Row{
output.Column{
Name: "Template Source",
Type: serialization.TypeString,
Value: t.Source,
},
output.Column{
Name: "Template Name",
Type: serialization.TypeString,
Expand Down Expand Up @@ -107,7 +115,7 @@ func listLocalTemplates() ([]Template, error) {
return nil, err
}
for _, t := range ts {
templates = append(templates, Template{Name: t})
templates = append(templates, Template{Name: t, Source: "local"})
}
return templates, nil
}
Expand All @@ -133,7 +141,10 @@ func fetchTemplates() ([]Template, error) {
if tName, ok = d["full_name"].(string); !ok {
return []Template{}, errors.New("error fetching repositories in the organization")
}
templates = append(templates, Template{Name: tName})
sName := strings.Split(tName, "/")
source := fmt.Sprintf("%s/%s", "github.com", sName[0])
name := sName[1]
templates = append(templates, Template{Name: name, Source: source})
}
return templates, nil
}
Expand Down

0 comments on commit 01b7617

Please sign in to comment.