Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
feat: generate all the sally config
Browse files Browse the repository at this point in the history
  • Loading branch information
jwillker committed May 23, 2022
1 parent 63753e7 commit 464b19d
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 15 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog

## v0.1.0 - 2022-05-22
## v0.2.0 - 2022-05-22

- feat: generate all the sally config

## v0.1.1 - 2022-05-22

- Fix tooling

Expand Down
38 changes: 33 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![build](https://github.com/jwillker/sherlock/actions/workflows/build.yml/badge.svg)](https://github.com/jwillker/sherlock/actions/workflows/build.yml)
[![golangci-lint](https://github.com/jwillker/sherlock/actions/workflows/lint.yml/badge.svg)](https://github.com/jwillker/sherlock/actions/workflows/lint.yml)

A tool to search and index Golang projetcs in Sally vanity config
A tool to search and index Golang projects in [Sally](https://github.com/uber-go/sally) vanity config

## Install

Expand All @@ -24,12 +24,40 @@ Usage:
sherlock investigate [flags]
Flags:
-u, --base-url string GitLab api url. Default https://gitlab.com/api/v4
-g, --group-id int GitLab group id
-h, --help help for investigate
-o, --output string Vanity packages config. Default: packages.yaml (default "packages.yaml")
-u, --base-url string GitLab api url. Default https://gitlab.com/api/v4
-d, --godoc string Godoc URL
-g, --group-id int GitLab group id
-h, --help help for investigate
-o, --output string Vanity packages config. Default: packages.yaml (default "packages.yaml")
-v, --vanity-url string Sally vanity URL
```


## Example

Running:

`sherlock investigate -u https://gitlab.my-company.com/api/v4 -g 123 -d godoc.my-company.com/pkg -v go.my-company.com`

Result:

`cat packages.yaml`

```yaml
godoc:
host: godoc.my-company.com/pkg
url: go.my-company.com
packages:
logs:
repo: https://gitlab.my-company.com/libs/golang/logs.git
sqs:
repo: https://gitlab.my-company.com/libs/golang/sqs.git
```

So you can host this using [Sally](https://github.com/uber-go/sally) vanity by running:

`sally -yml packages.yaml -port 8080`

## Developing
Use make help to see what to run, some options:

Expand Down
8 changes: 5 additions & 3 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package cmd
// Flags

var (
GroupID int
BaseURL string
Output string
GroupID int
BaseURL string
Output string
Godoc string
VanityURL string
)
6 changes: 5 additions & 1 deletion cmd/investigate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ func init() {
investigateCmd.Flags().IntVarP(&GroupID, "group-id", "g", 0, "GitLab group id")
investigateCmd.Flags().StringVarP(&BaseURL, "base-url", "u", "", "GitLab api url. Default https://gitlab.com/api/v4")
investigateCmd.Flags().StringVarP(&Output, "output", "o", "packages.yaml", "Vanity packages config. Default: packages.yaml")
investigateCmd.Flags().StringVarP(&Godoc, "godoc", "d", "", "Godoc URL")
investigateCmd.Flags().StringVarP(&VanityURL, "vanity-url", "v", "", "Sally vanity URL")
_ = investigateCmd.MarkFlagRequired("group-id")
_ = investigateCmd.MarkFlagRequired("godoc")
_ = investigateCmd.MarkFlagRequired("vanity-url")
}

func investigate() {
Expand All @@ -44,7 +48,7 @@ func investigate() {
}

log.Info("Generating config in " + Output)
err = vanity.GenSallyConf(Output, pkgs)
err = vanity.GenSallyConf(Output, Godoc, VanityURL, pkgs)

if err != nil {
log.Error(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "sherlock",
Short: "A tool to search and index Golang projetcs in Sally vanity config",
Short: "A tool to search and index Golang projects in Sally vanity config",
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand Down
23 changes: 20 additions & 3 deletions internal/vanity/sally.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ import (
yaml "gopkg.in/yaml.v3"
)

type Config struct {
URL string `yaml:"url"`
Packages map[string]Pkg `yaml:"packages"`
Godoc struct {
Host string `yaml:"host"`
} `yaml:"godoc"`
}

type Pkg struct {
Repo string `yaml:"repo"`
}

// GenSallyConf generate Sally packages config format
func GenSallyConf(output string, pkgs *[]entity.Package) error {

func GenSallyConf(output, godoc, url string, pkgs *[]entity.Package) error {
packages := map[string]Pkg{}

for _, p := range *pkgs {
Expand All @@ -22,7 +29,17 @@ func GenSallyConf(output string, pkgs *[]entity.Package) error {
}
}

data, err := yaml.Marshal(&packages)
config := Config{
URL: url,
Packages: packages,
Godoc: struct {
Host string "yaml:\"host\""
}{
Host: godoc,
},
}

data, err := yaml.Marshal(&config)

if err != nil {
return err
Expand Down
4 changes: 3 additions & 1 deletion internal/vanity/sally_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
func TestGenSallyConf(t *testing.T) {
type args struct {
output string
godoc string
url string
pkgs *[]entity.Package
}
tests := []struct {
Expand Down Expand Up @@ -49,7 +51,7 @@ func TestGenSallyConf(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.assertion(t, GenSallyConf(tt.args.output, tt.args.pkgs))
tt.assertion(t, GenSallyConf(tt.args.output, tt.args.godoc, tt.args.url, tt.args.pkgs))
})
}
}

0 comments on commit 464b19d

Please sign in to comment.