Skip to content

Commit

Permalink
feat: fill in github repository for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeyheath committed Sep 13, 2023
1 parent 13bf494 commit 9f332c4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
28 changes: 28 additions & 0 deletions config/v2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"bytes"
"encoding/json"
"fmt"
"os/exec"
"path/filepath"
"strings"
"time"

"github.com/chanzuckerberg/fogg/errs"
"github.com/chanzuckerberg/fogg/plugins"
"github.com/sirupsen/logrus"
"github.com/spf13/afero"
yaml "gopkg.in/yaml.v3"
)
Expand Down Expand Up @@ -52,6 +54,32 @@ func (c *Config) Write(fs afero.Fs, path string) error {
return encoder.Encode(c)
}

func getGitRemoteOriginURL(cwd ...string) string {
dir := "."
if len(cwd) > 0 {
dir = cwd[0]
}
cmd := exec.Command("git", "remote", "get-url", "--push", "origin")
cmd.Dir = dir
out, err := cmd.Output()
if err != nil {
logrus.Warnf("unable to get git output: %s", err)
return ""
}
return strings.TrimSpace(string(out))
}

// TODO: write out functions to generate tag data
func (c *Config) GenerateStamp(fs afero.Fs, configFile string) {
stamp := Stamp{}
stamp.Date = DateAsTag()
stamp.FilePath = fs.Name()
stamp.FoggUser = ""
stamp.GitRepository = getGitRemoteOriginURL()
stamp.CommitHash = ""
c.Stamp = stamp
}

// TODO: write out functions to generate tag data
func (c *Config) GenerateStamp(fs afero.Fs, configFile string) {

Check failure on line 84 in config/v2/config.go

View workflow job for this annotation

GitHub Actions / test

method Config.GenerateStamp already declared at config/v2/config.go:73:18
stamp := Stamp{}
Expand Down
16 changes: 16 additions & 0 deletions config/v2/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ import (
"github.com/stretchr/testify/require"
)

type testGitRemote struct {
path string
expectedRemote string
}

func TestGetGitRemoveOriginURL(t *testing.T) {
r := require.New(t)
tests := []testGitRemote{
{path: ".", expectedRemote: "[email protected]:chanzuckerberg/fogg"},
}
for _, test := range tests {
remote := getGitRemoteOriginURL(test.path)
r.Equal(test.expectedRemote, remote)
}
}

func TestReadConfig(t *testing.T) {
r := require.New(t)

Expand Down

0 comments on commit 9f332c4

Please sign in to comment.