diff --git a/config/config.go b/config/config.go index 2dd1e3a..11fc18d 100644 --- a/config/config.go +++ b/config/config.go @@ -18,6 +18,7 @@ const ( keyRepositories = "REPOSITORIES" keyGithubToken = "GITHUB_TOKEN" keyEnvironments = "ENVIRONMENTS" + keyEnvironmentLinks = "ENVIRONMENT_LINKS" keyVerbose = "VERBOSE" keyTemplateFile = "TEMPLATE_FILE" keyTitle = "TITLE" @@ -29,6 +30,7 @@ type Config struct { TargetRepositoryFile string Repositories string Environments string + EnvironmentLinks string GithubToken string TemplateFile string Title string @@ -42,6 +44,7 @@ func CreateConfig(ctx context.Context) (*Config, error) { flag.StringVar(&config.Repositories, "repositories", lookupEnvOrString(keyRepositories, ""), "Repositories to query. Comma separated list.") flag.StringVar(&config.GithubToken, "github-token", lookupEnvOrString(keyGithubToken, ""), "The GitHub Token to use for authentication.") flag.StringVar(&config.Environments, "environments", lookupEnvOrString(keyEnvironments, ""), "Environments to query. Comma separated list.") + flag.StringVar(&config.EnvironmentLinks, "environment-links", lookupEnvOrString(keyEnvironmentLinks, ""), "Links to environments. Comma separated list.") flag.StringVar(&config.TemplateFile, "template-file", lookupEnvOrString(keyTemplateFile, "template/default.tpl"), "The template file to use for rendering the result. Defaults to 'template/default.tpl'.") flag.StringVar(&config.Title, "title", lookupEnvOrString(keyTitle, "Organization Overview"), "The title to use for the result. Defaults to 'Organization Overview'.") verbose := flag.Int("verbose", lookupEnvOrInt(keyVerbose, 0), "Verbosity level, 0=info, 1=debug. Overrides the environment variable VERBOSE.") @@ -92,6 +95,10 @@ func (c *Config) EnvironmentsAsList() []string { return strings.Split(c.Environments, ",") } +func (c *Config) EnvironmentLinksAsList() []string { + return strings.Split(c.EnvironmentLinks, ",") +} + func lookupEnvOrString(key string, defaultVal string) string { if val, ok := os.LookupEnv(key); ok { return val diff --git a/result/result.go b/result/result.go index 1bb4de5..cf79182 100644 --- a/result/result.go +++ b/result/result.go @@ -80,6 +80,7 @@ type Worfklow struct { type Environment struct { Name string `json:"Name"` + Link string `json:"Link"` Version string `json:"Version"` IsRelease bool `json:"IsRelease"` IsCurrent bool `json:"IsCurrent"` @@ -227,9 +228,10 @@ func (organization *Organization) IterateRepositories(ctx context.Context, gh *g func (repository *Repository) IterateEnvironments(ctx context.Context, gh *github.Client, config config.Config) (err error) { // split config.environments by comma - for _, env := range config.EnvironmentsAsList() { + envLinks := config.EnvironmentLinksAsList() + for i, env := range config.EnvironmentsAsList() { slog.InfoContext(ctx, "Processing environment", "organization", config.Organization, "repository", repository.Name, "environment", env) - environment := Environment{Name: env} + environment := Environment{Name: env, Link: envLinks[i]} deployments, _, err := gh.Repositories.ListDeployments(ctx, config.Organization, repository.Name, nil) if err != nil { diff --git a/template/default.tpl b/template/default.tpl index 8b77ab7..05fffa9 100644 --- a/template/default.tpl +++ b/template/default.tpl @@ -2,8 +2,8 @@ Component Status overview. Last update {{.LastUpdated}} -| Repository | Commits | PRs | Latest Release | [dev](https://dev-yasm.prodyna.com) | [staging](https://dev-yasm.prodyna.com) | [prod](https://yasm.prodyna.com) | -| --- | --- | --- | -- | --- | --- | --- | +| Repository | Commits | PRs | Latest Release | {{ range .Environments }} {{.Name}} | {{end}} | +| --- | --- | --- | -- | {{ range .Environments }} | --- | {{end}} | {{range .Repositories}}| [{{.Name}}]({{.Link}}) | {{if .Commits.Count}}:red_square:{{else}}:green_square:{{end}} {{.Commits.Count}} | {{if .PullRequests.Count}}:yellow_square:{{else}}:green_square:{{end}} {{.PullRequests.Count}} | {{.LatestRelease.Tag}} | {{range .Environments}} {{if .IsCurrent}}:green_square:{{else}}:red_square:{{end}} {{.Version}} | {{end}} {{end}}