Skip to content

Commit

Permalink
Links to environments
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrizic committed Mar 2, 2024
1 parent bc99e49 commit d6ef23c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
7 changes: 7 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
keyRepositories = "REPOSITORIES"
keyGithubToken = "GITHUB_TOKEN"
keyEnvironments = "ENVIRONMENTS"
keyEnvironmentLinks = "ENVIRONMENT_LINKS"
keyVerbose = "VERBOSE"
keyTemplateFile = "TEMPLATE_FILE"
keyTitle = "TITLE"
Expand All @@ -29,6 +30,7 @@ type Config struct {
TargetRepositoryFile string
Repositories string
Environments string
EnvironmentLinks string
GithubToken string
TemplateFile string
Title string
Expand All @@ -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.")
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions result/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions template/default.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}

Expand Down

0 comments on commit d6ef23c

Please sign in to comment.