Skip to content

Commit

Permalink
fix(#119): adds new home for configuration files (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
dipak-pawar authored and MatousJobanek committed May 24, 2018
1 parent 8d968da commit 1748860
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 46 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/fragments/test-keeper.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ NOTE: If we missed some important patterns feel free to open an link:https://git

=== Plugin Configuration [[test-keeper-config]]

To configure Test Keeper plugin place `test-keeper.yml` (or `test-keeper.yaml`) file in the root of your project and use properties described below.
To configure Test Keeper plugin place `test-keeper.yml` (or `test-keeper.yaml`) file inside of the directory `.ike-prow/` in your project and use properties described below.

.test-keeper.yaml
[source, yml, indent=0]
Expand Down
2 changes: 1 addition & 1 deletion docs/fragments/work-in-progress.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ If the PR title starts with any of the default prefixes such as `WIP`, `DO NOT M

=== Plugin Configuration [[work-in-progress-config]]

To configure Work In Progress plugin place `work-in-progress.yml` (or `work-in-progress.yaml`) file in the root of your project and use properties described below.
To configure Work In Progress plugin place `work-in-progress.yml` (or `work-in-progress.yaml`) file inside of the directory `.ike-prow/` in your project and use properties described below.

.work-in-progress.yaml
[source, yml, indent=0]
Expand Down
7 changes: 4 additions & 3 deletions docs/plugins.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ organization. Be aware however, that adding an external plugin both to the repos
Customized comment message can be configured as `plugin hint` to express suggestions regarding the plugin's intented behavior. +
Eg. Configuring `plugin hint` for the `test-keeper` plugin adds comment message to the Pull Request when no test is found.

To enable customized plugin hint comment messages edit plugin's configuration file (eg. test-keeper.yaml) adding the `plugin_hint` property.
By default, the custom plugin hint message is loaded from a file `PLUGINNAME_HINT.md` located in `.ike-prow/` directory (if present). The `PLUGINNAME` is a name of the plugin you want to set the custom hint message for, so for example `.ike-prow/test-keeper_hint.md`.
It is also possible to set other location of the hint file or directly the content of the message by editing plugin's configuration file (eg. test-keeper.yaml) and adding the `plugin_hint` property there:

.test-keeper.yaml
[source, yml, indent=0]
----
plugin_hint: plugins/test-keeper_hint.md
plugin_hint: plugins/test-keeper_hint.md
----

The `plugin_hint` property can either have an inline string directly written inside of the config file or another file with case insensitive filename PLUGINNAME_HINT.md that contains the hint. The location of the file can be set by either a relative path or an absolute URL. If nothing is set then a default message is used.
The `plugin_hint` property can either have an inline string directly written inside of the config file or another file with case insensitive filename PLUGINNAME_HINT.md that contains the hint. The location of the file can be set by either a relative path or an absolute URL.

==== GitHub settings [[gh-settings]]

Expand Down
14 changes: 7 additions & 7 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/assets/config/test-keeper.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ skip_validation_for:
## Docker
- 'regex{{docker-compose.*\.y[a]?ml$}}'
- 'Dockerfile*'
- '.dockerignore'

## Others
- 'Makefile'
Expand Down Expand Up @@ -133,4 +134,4 @@ skip_validation_for:
- '*.bat'

# Our own configurations
- 'regex{{test-keeper\.y[a]?ml$}}'
- '.ike-prow/'
10 changes: 7 additions & 3 deletions pkg/github/service/config_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ import (

const githubBaseURL = "https://github.com/"

// ConfigHome is a directory to keep prow configuration files
const ConfigHome = ".ike-prow/"

// LoadableConfig holds information about the plugin name, repository change and pointer to base config
type LoadableConfig struct {
PluginName string
Change scm.RepositoryChange
BaseConfig *config.PluginConfiguration
}

// Sources provides default loading strategies for a plugin looking it up in the root of the repository for a given
// Sources provides default loading strategies for a plugin looking it up in the .ike-prow directory of the repository for a given
// revision. Two files are expected to be found there plugin-name.yml or plugin-name.yaml (in that order)
func (l *LoadableConfig) Sources() []config.Source {
return []config.Source{
l.loadFromRawFile("%s.yml"),
l.loadFromRawFile("%s.yaml"),
l.loadFromRawFile(ConfigHome + "%s.yml"),
l.loadFromRawFile(ConfigHome + "%s.yaml"),
}
}

Expand All @@ -44,6 +47,7 @@ func (l *LoadableConfig) loadFromRawFile(pathTemplate string) config.Source {

l.BaseConfig.LocationURL = githubBaseURL + rawFileService.GetRelativePath(filePath)
l.BaseConfig.PluginName = l.PluginName

return downloadedConfig, nil
}
}
20 changes: 17 additions & 3 deletions pkg/plugin/test-keeper/comment_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ const (
// CreateCommentMessage creates a comment message for the test-keeper plugin. If the comment message is set in config then it takes that one, the default otherwise.
func CreateCommentMessage(configuration PluginConfiguration, change scm.RepositoryChange) string {
var msg string
if configuration.LocationURL == "" {
msg = sadIke + paragraph + beginning + paragraph + noConfig
} else if configuration.PluginHint != "" {
if configuration.PluginHint != "" {
msg = getMsgFromConfigHint(configuration, change)
} else if content := defaultFileContent(configuration, change); content != "" {
msg = content
} else if configuration.LocationURL == "" {
msg = sadIke + paragraph + beginning + paragraph + noConfig
} else {
msg = sadIke + paragraph + getMsgWithConfigRef(configuration.LocationURL)
}
Expand All @@ -56,6 +58,18 @@ func getMsgFromConfigHint(configuration PluginConfiguration, change scm.Reposito
return configuration.PluginHint
}

func defaultFileContent(configuration PluginConfiguration, change scm.RepositoryChange) string {
pluginHintPath := fmt.Sprintf("%s%s_hint.md", ghservice.ConfigHome, configuration.PluginName)
ghFileService := ghservice.RawFileService{Change: change}
hintURL := ghFileService.GetRawFileURL(pluginHintPath)

content, e := utils.GetFileFromURL(hintURL)
if e != nil {
return ""
}
return string(content)
}

func getMsgFromFile(configuration PluginConfiguration, change scm.RepositoryChange) string {
_, err := url.ParseRequestURI(configuration.PluginHint)

Expand Down
67 changes: 67 additions & 0 deletions pkg/plugin/test-keeper/comment_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,73 @@ var _ = Describe("Test keeper comment message creation", func() {
})
})

Context("Creation of default comment messages from default location when config plugin hint is not set", func() {

BeforeEach(func() {
defer gock.OffAll()
})

It("should create message taken from a default hint file if plugin hint url is missing", func() {
// given
NonExistingRawGitHubFiles("test-keeper.yaml", "test-keeper.yml")

gock.New("https://raw.githubusercontent.com").
Get("owner/repo/46cb8fac44709e4ccaae97448c65e8f7320cfea7/.ike-prow/test-keeper_hint.md").
Reply(200).
BodyString("Custom message")

url := "http://github.com/my/repo/test-keeper.yaml"
conf := testkeeper.PluginConfiguration{
PluginConfiguration: config.PluginConfiguration{
LocationURL: url,
PluginName: testkeeper.ProwPluginName,
},
}

change := scm.RepositoryChange{
Owner: "owner",
RepoName: "repo",
Hash: "46cb8fac44709e4ccaae97448c65e8f7320cfea7",
}

// when
msg := testkeeper.CreateCommentMessage(conf, change)
sanitizedMsg := removeHtmlElements(msg)

// then
Expect(sanitizedMsg).To(Equal("Custom message"))
})

It("should create message taken from a default hint file if location url is missing", func() {
// given
NonExistingRawGitHubFiles("test-keeper.yaml", "test-keeper.yml")

gock.New("https://raw.githubusercontent.com").
Get("owner/repo/46cb8fac44709e4ccaae97448c65e8f7320cfea7/.ike-prow/test-keeper_hint.md").
Reply(200).
BodyString("Custom message")

conf := testkeeper.PluginConfiguration{
PluginConfiguration: config.PluginConfiguration{
PluginName: testkeeper.ProwPluginName,
},
}

change := scm.RepositoryChange{
Owner: "owner",
RepoName: "repo",
Hash: "46cb8fac44709e4ccaae97448c65e8f7320cfea7",
}

// when
msg := testkeeper.CreateCommentMessage(conf, change)
sanitizedMsg := removeHtmlElements(msg)

// then
Expect(sanitizedMsg).To(Equal("Custom message"))
})
})

Context("Creation of default comment messages that are sent to a validated PR when custom message file is set", func() {

BeforeEach(func() {
Expand Down
16 changes: 9 additions & 7 deletions pkg/plugin/test-keeper/configuration_gh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"gopkg.in/h2non/gock.v1"
"github.com/arquillian/ike-prow-plugins/pkg/github/service"
)

var _ = Describe("Test keeper config loader features", func() {
Expand All @@ -21,11 +22,12 @@ var _ = Describe("Test keeper config loader features", func() {
Context("Loading test-keeper configuration file from GitHub repository", func() {

logger := log.NewTestLogger()
configFilePath := ghservice.ConfigHome + testkeeper.ProwPluginName

It("should load test-keeper configuration yml file", func() {
// given
gock.New("https://raw.githubusercontent.com").
Get("owner/repo/46cb8fac44709e4ccaae97448c65e8f7320cfea7/" + testkeeper.ProwPluginName + ".yml").
Get("owner/repo/46cb8fac44709e4ccaae97448c65e8f7320cfea7/" + configFilePath + ".yml").
Reply(200).
BodyString("test_patterns: ['*my', 'test.go', 'pattern.js']\n" +
"skip_validation_for: ['pom.xml', 'regex{{*\\.adoc}}']\n" +
Expand All @@ -41,15 +43,15 @@ var _ = Describe("Test keeper config loader features", func() {
configuration := testkeeper.LoadConfiguration(logger, change)

// then
Expect(configuration.LocationURL).To(Equal("https://github.com/owner/repo/46cb8fac44709e4ccaae97448c65e8f7320cfea7/test-keeper.yml"))
Expect(configuration.LocationURL).To(Equal("https://github.com/owner/repo/46cb8fac44709e4ccaae97448c65e8f7320cfea7/.ike-prow/test-keeper.yml"))
Expect(configuration.PluginName).To(Equal(testkeeper.ProwPluginName))
Expect(configuration.PluginHint).To(Equal("http://my.server.com/message.md"))
})

It("should load test-keeper configuration yml file", func() {
// given
gock.New("https://raw.githubusercontent.com").
Get("owner/repo/46cb8fac44709e4ccaae97448c65e8f7320cfea7/" + testkeeper.ProwPluginName + ".yml").
Get("owner/repo/46cb8fac44709e4ccaae97448c65e8f7320cfea7/" + configFilePath + ".yml").
Reply(200).
BodyString("test_patterns: ['*my', 'test.go', 'pattern.js']\n" +
"skip_validation_for: ['pom.xml', 'regex{{*\\.adoc}}']\n" +
Expand All @@ -73,10 +75,10 @@ var _ = Describe("Test keeper config loader features", func() {

It("should load test-keeper configuration yaml file", func() {
// given
NonExistingRawGitHubFiles("test-keeper.yml")
NonExistingRawGitHubFiles(".ike-prow/test-keeper.yml")

gock.New("https://raw.githubusercontent.com").
Get("owner/repo/46cb8fac44709e4ccaae97448c65e8f7320cfea7/" + testkeeper.ProwPluginName + ".yaml").
Get("owner/repo/46cb8fac44709e4ccaae97448c65e8f7320cfea7/" + configFilePath + ".yaml").
Reply(200).
BodyString("test_patterns: ['*my', 'test.go', 'pattern.js']\n" +
"skip_validation_for: ['pom.xml', 'regex{{*\\.adoc}}']\n" +
Expand All @@ -100,10 +102,10 @@ var _ = Describe("Test keeper config loader features", func() {

It("should not load test-keeper configuration yaml file and return empty url when config is not accessible", func() {
// given
NonExistingRawGitHubFiles("test-keeper.yml")
NonExistingRawGitHubFiles(".ike-prow/test-keeper.yml")

gock.New("https://raw.githubusercontent.com").
Get("owner/repo/46cb8fac44709e4ccaae97448c65e8f7320cfea7/" + testkeeper.ProwPluginName + ".yaml").
Get("owner/repo/46cb8fac44709e4ccaae97448c65e8f7320cfea7/" + configFilePath + ".yaml").
Reply(404)

change := scm.RepositoryChange{
Expand Down
Loading

0 comments on commit 1748860

Please sign in to comment.