Skip to content

Commit

Permalink
chore: merge upstream
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Phelps <[email protected]>
  • Loading branch information
markphelps committed Nov 20, 2024
2 parents 80b6f73 + 826a872 commit f8d8737
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 8 deletions.
7 changes: 4 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"log/slog"
"strings"
"time"

"github.com/get-glu/glu/internal/git"
"github.com/get-glu/glu/internal/oci"
Expand Down Expand Up @@ -71,7 +70,6 @@ func (c *Config) GitRepository(ctx context.Context, name string) (_ *git.Reposit
method transport.AuthMethod
srcOpts = []containers.Option[git.Repository]{
git.WithDefaultBranch(conf.DefaultBranch),
git.WithInterval(10 * time.Second),
}
)

Expand All @@ -82,7 +80,10 @@ func (c *Config) GitRepository(ctx context.Context, name string) (_ *git.Reposit
if conf.Remote != nil {
slog.Debug("configuring remote", "remote", conf.Remote.Name)

srcOpts = append(srcOpts, git.WithRemote(conf.Remote.Name, conf.Remote.URL))
srcOpts = append(srcOpts,
git.WithRemote(conf.Remote.Name, conf.Remote.URL),
git.WithInterval(conf.Remote.Interval),
)

if conf.Remote.Credential != "" {
creds, err := c.creds.Get(conf.Remote.Credential)
Expand Down
4 changes: 4 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ The URL of the remote.

The name of the credential to use for the remote.

#### `sources.<name>.git.<repository>.remote.interval`

The period between automatic fetches from the remote.

#### `sources.<name>.git.<repository>.proposals`

The configuration for the proposals for the git repository.
Expand Down
103 changes: 103 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package config

import (
"errors"
"os"
"path/filepath"
"reflect"
"testing"
"time"
)

type testDefaulter struct {
Expand Down Expand Up @@ -155,3 +158,103 @@ func TestProcessValue(t *testing.T) {
})
}
}

type testGitExpected struct {
remoteName string
url string
credential string
interval time.Duration
}

func TestConfigGit(t *testing.T) {
configDir := t.TempDir()

tests := []struct {
name string
input string
expected GitRepository
}{
{
name: "default",
input: `sources:
git:
default:
remote:
name: upstream
url: https://corp-repos/default.git
`,
expected: GitRepository{
Remote: &Remote{
Name: "upstream",
URL: "https://corp-repos/default.git",
Interval: 10 * time.Second,
},
DefaultBranch: "main",
},
},
{
name: "custom",
input: `sources:
git:
custom:
remote:
name: origin
url: https://corp-repos/custom
credential: vault
interval: 1m
path: v1
default_branch: release-v1
`,
expected: GitRepository{
Remote: &Remote{
Name: "origin",
URL: "https://corp-repos/custom",
Credential: "vault",
Interval: time.Minute,
},
Path: "v1",
DefaultBranch: "release-v1",
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
configPath := filepath.Join(configDir, tt.name+"-glu.yaml")
err := os.WriteFile(configPath, []byte(tt.input), 0600)
if err != nil {
t.Fatalf("failed to write configuration file: %v", err)
}

c, err := ReadFromPath(configPath)
if err != nil {
t.Errorf("expected no error, got %v", err)
}
repos := c.Sources.Git
if len(repos) == 0 {
t.Fatalf("expected at least one repo, got zero")
}
repo, ok := repos[tt.name]
if !ok {
t.Fatalf("expected repo %s to exist", tt.name)
}

if !reflect.DeepEqual(tt.expected.Remote, repo.Remote) {
t.Errorf("expected remote %v, got %v", tt.expected.Remote, repo.Remote)
}
if tt.expected.Path != repo.Path {
t.Errorf("expected path %v, got %v", tt.expected.Path, repo.Path)
}
if tt.expected.DefaultBranch != repo.DefaultBranch {
t.Errorf("expected default branch %v, got %v", tt.expected.DefaultBranch, repo.DefaultBranch)
}
})
}
}

func TestReadFromFileWhenNoConfig(t *testing.T) {
_, err := ReadFromPath(filepath.Join(t.TempDir(), "non-existent-file.yaml"))
if err != nil {
t.Fatalf("expected no error, got %v", err)
}
}
15 changes: 11 additions & 4 deletions pkg/config/git.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package config

import "log/slog"
import (
"log/slog"
"time"
)

var (
_ validater = (*GitRepositories)(nil)
Expand Down Expand Up @@ -53,15 +56,19 @@ func (r *GitRepository) setDefaults() error {

remote.Name = "origin"
}
if remote.Interval < 1 {
remote.Interval = 10 * time.Second
}
}

return nil
}

type Remote struct {
Name string `glu:"name"`
URL string `glu:"url"`
Credential string `glu:"credential"`
Name string `glu:"name"`
URL string `glu:"url"`
Credential string `glu:"credential"`
Interval time.Duration `glu:"interval"`
}

type Proposals struct {
Expand Down
5 changes: 5 additions & 0 deletions ui/.proxyrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"/api": {
"target": "http://localhost:8080"
}
}
2 changes: 1 addition & 1 deletion ui/src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Pipeline } from '@/types/pipeline';
import { System } from '@/types/system';

const api = axios.create({
baseURL: 'http://localhost:8080/api/v1'
baseURL: '/api/v1'
});

export const getSystem = async (): Promise<System> => {
Expand Down

0 comments on commit f8d8737

Please sign in to comment.