-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configuration file with comments (#18)
* feature: generate configuration from templates * test: jira config template test * docs: Improve default-config documentation * docs: header documentation on generated template * test: metadata template test * feat: add comment title in config * refactor: use built in format instead of printf * docs: remove sections already present in default config
- Loading branch information
Showing
11 changed files
with
257 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,77 @@ | ||
# Jira configuration -----------------------------------# | ||
#============================= GH SHERPA CONFIG ===============================# | ||
# # | ||
# This is the default configuration file for GH Sherpa. These values will be # | ||
# set if no other configuration override those values. You can override # | ||
# the values by setting them in your `$HOME/.config/sherpa/config.yml` file. # | ||
# # | ||
#==============================================================================# | ||
|
||
# GH Sherpa issue types ------------------------------------------------------# | ||
# You can use the following issue types in the sections below that indicate it. | ||
# - bugfix | ||
# - dependency | ||
# - deprecation | ||
# - documentation | ||
# - feature | ||
# - hotfix | ||
# - improvement | ||
# - internal | ||
# - refactoring | ||
# - release | ||
# - removal | ||
# - revert | ||
# - security | ||
#-----------------------------------------------------------------------------# | ||
|
||
# Jira configuration ---------------------------------------------------------# | ||
jira: | ||
# Jira authentication configuration | ||
auth: | ||
# Jira authentication url to generate PAT | ||
# WARNING: Replace it with your actual Jira authentication url | ||
host: https://jira.example.com | ||
# Jira already generated PAT | ||
# WARNING: Replace it with your actual Jira PAT | ||
token: <Jira PAT> | ||
# Jira insecure TLS configuration | ||
# The URL to connect to your Jira instance. | ||
host: "" | ||
# This token will be used to authenticate to Jira. | ||
# You can generate a PAT in your Jira instance if you didn't already | ||
# have one generated by GH Sherpa. | ||
token: "" | ||
# Enable this setting to skip TLS verification. | ||
# This is useful when you are using self-signed certificates | ||
# or when you are authenticating to a non-HTTPS Jira instance. | ||
# WARNING: It is not recommended to enable this option unless | ||
# you are in a trusted network. | ||
skip_tls_verify: false | ||
|
||
# Jira issue types configuration | ||
# You can find the issue types in your Jira instance by navigating to | ||
# `https://{your-jira-domain}/jira/rest/api/2/issuetype`. More info in | ||
# https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issue-types/#api-group-issue-types | ||
issue_types: | ||
# Jira issue types for bugfix | ||
bugfix: ["1"] | ||
# Jira issue types for features | ||
feature: ["3", "5"] | ||
# Jira issue types for improvements | ||
improvement: ["4"] | ||
# You can map here other issue types. | ||
|
||
# Github configuration --------------------------------# | ||
# Github configuration -------------------------------------------------------# | ||
github: | ||
# Github issue labels configuration | ||
# Here you can configure the issue labels mapping between Github issues and | ||
# GH Sherpa issue types. | ||
issue_labels: | ||
bugfix: ["kind/bug"] | ||
feature: ["kind/feature"] | ||
refactoring: ["kind/refactoring"] | ||
documentation: ["kind/documentation"] | ||
feature: ["kind/feature"] | ||
improvement: ["kind/improvement"] | ||
refactoring: ["kind/refactoring"] | ||
# You can map here other issue types. | ||
|
||
# Branches configuration -----------------------------------------------------# | ||
branches: | ||
# Branch prefixes configuration | ||
# Here you can set the prefixes that will be used when creating the branches | ||
# for the issues. By default it will use the issue type as prefix. | ||
prefixes: | ||
# We provide some examples below to help you configure your prefixes, select one | ||
# issue type and map it to a custom prefix. | ||
# Example: map `bugfix` type to a branch prefix `myfix/xxxx`: | ||
# bugfix: myfix | ||
# Example: map `feature` type to a branch prefix `feat/xxxx`: | ||
# feature: feat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package config | ||
|
||
import ( | ||
"embed" | ||
"io" | ||
"text/template" | ||
"time" | ||
) | ||
|
||
//go:embed templates/*.tmpl | ||
var embeddedTemplates embed.FS | ||
|
||
type configFileTemplateData struct { | ||
Metadata MetadataConfiguration | ||
JiraData JiraTemplateConfiguration | ||
GithubData GithubTemplateConfiguration | ||
BranchesData BranchesTemplateConfiguration | ||
} | ||
|
||
type MetadataConfiguration struct { | ||
Version string | ||
GeneratedAt time.Time | ||
} | ||
|
||
type JiraTemplateConfiguration struct { | ||
Jira | ||
} | ||
|
||
type GithubTemplateConfiguration struct { | ||
Github | ||
} | ||
|
||
type BranchesTemplateConfiguration struct { | ||
Branches | ||
} | ||
|
||
func writeTemplatedConfigFile(wr io.Writer, templateData configFileTemplateData) error { | ||
t, err := template.ParseFS(embeddedTemplates, "templates/*.tmpl") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := t.ExecuteTemplate(wr, "configuration", templateData); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package config | ||
|
||
import ( | ||
"bytes" | ||
"strings" | ||
"testing" | ||
"text/template" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestMetedataTemplateConfiguration(t *testing.T) { | ||
tmpl, err := template.ParseFS(embeddedTemplates, "templates/*.tmpl") | ||
require.NoError(t, err) | ||
|
||
t.Run("Should render metadata", func(t *testing.T) { | ||
var buff bytes.Buffer | ||
templateCfg := configFileTemplateData{ | ||
Metadata: MetadataConfiguration{ | ||
Version: "1.0.0", | ||
GeneratedAt: time.Date(2023, 10, 2, 17, 30, 0, 0, time.UTC), | ||
}, | ||
} | ||
err := tmpl.ExecuteTemplate(&buff, "configuration", templateCfg) | ||
require.NoError(t, err) | ||
assert.True(t, strings.Contains(buff.String(), "# This file was generated by GH Sherpa CLI v1.0.0 at 2023-10-02 17:30:00 +0000 UTC")) | ||
}) | ||
} | ||
|
||
func TestJiraTemplateConfiguration(t *testing.T) { | ||
tmpl, err := template.ParseFS(embeddedTemplates, "templates/*.tmpl") | ||
require.NoError(t, err) | ||
|
||
t.Run("Should generate empty configuration", func(t *testing.T) { | ||
jiraData := JiraTemplateConfiguration{ | ||
Jira: Jira{}, | ||
} | ||
|
||
var buff bytes.Buffer | ||
err := tmpl.ExecuteTemplate(&buff, "jiraConfiguration", jiraData) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, `jira: | ||
auth: | ||
host: | ||
token: | ||
skip_tls_verify: false | ||
`, buff.String()) | ||
}) | ||
|
||
t.Run("Should generate configuration with values", func(t *testing.T) { | ||
jiraData := JiraTemplateConfiguration{ | ||
Jira: Jira{ | ||
Auth: JiraAuth{ | ||
Host: "https://jira.example.com", | ||
Token: "jira-pat", | ||
InsecureTLS: true, | ||
}, | ||
}, | ||
} | ||
|
||
var buff bytes.Buffer | ||
err := tmpl.ExecuteTemplate(&buff, "jiraConfiguration", jiraData) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, `jira: | ||
auth: | ||
host: https://jira.example.com | ||
token: jira-pat | ||
skip_tls_verify: true | ||
`, buff.String()) | ||
|
||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{{define "configuration" -}} | ||
#=============================== GH SHERPA CONFIG =================================# | ||
# You can find more information about the configuration file in the documentation: # | ||
# https://github.com/InditexTech/gh-sherpa/blob/main/docs/configuration.md # | ||
#==================================================================================# | ||
# This file was generated by GH Sherpa CLI v{{.Metadata.Version}} at {{.Metadata.GeneratedAt.Format "2006-01-02 15:04:05 -0700 MST"}} | ||
|
||
{{if .JiraData.Auth.Host}}{{template "jiraConfiguration" .JiraData}}{{end}} | ||
{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{{ define "jiraConfiguration" -}} | ||
jira: | ||
auth: | ||
host: {{.Auth.Host}} | ||
token: {{.Auth.Token}} | ||
skip_tls_verify: {{.Auth.InsecureTLS}} | ||
{{end }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.