Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#119): add new home for configuration files #144

Merged
merged 34 commits into from
May 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
cb5a4da
chore: ignore .dockerignore and .ike-prow directory
dipak-pawar May 17, 2018
7cb818a
chore: update path to take .ike-prow dir for configuration
dipak-pawar May 17, 2018
a2c1115
chore: update doc for plugin hint configuration
dipak-pawar May 17, 2018
96604b8
chore: move our test-keeper configuration in .ike-prow dir
dipak-pawar May 17, 2018
5e2f45c
Merge branch 'master' of https://github.com/arquillian/ike-prow-plugi…
dipak-pawar May 17, 2018
c32f52a
Merge branch 'master' into issue_119
MatousJobanek May 17, 2018
64e63f2
chore: removes test-keeper.yaml from root dir
dipak-pawar May 18, 2018
3acc1b8
chore: removes unnecessary regex test-keeper.yaml from config
dipak-pawar May 18, 2018
6ec0087
fix: modify test to new use new config location
dipak-pawar May 18, 2018
e4eb40c
Merge branch 'master' of https://github.com/arquillian/ike-prow-plugi…
dipak-pawar May 18, 2018
1d3531f
chore: update test-fixture with new location for config file
dipak-pawar May 18, 2018
fb4f0d4
feat: load hint file from .ike-prow/ by default
dipak-pawar May 18, 2018
9b05d43
resolved conflicts
dipak-pawar May 21, 2018
4f6d727
fix: update test to use single function
dipak-pawar May 21, 2018
5ccc521
chore: update glide.lock
dipak-pawar May 21, 2018
3b3efa4
Merge branch 'master' into issue_119
dipak-pawar May 22, 2018
1821514
Merge branch 'master' of https://github.com/arquillian/ike-prow-plugi…
dipak-pawar May 23, 2018
1f3d490
fix: add const for .ike-prow/ and removes config file eager loading
dipak-pawar May 23, 2018
bf096fd
fix: remove unnecasary code from test
dipak-pawar May 23, 2018
fd03a90
fix: add comment for exported constant
dipak-pawar May 23, 2018
61fff53
chore: remove unnecessary mocking in test and use const variable
dipak-pawar May 23, 2018
12a8d5e
chore: use format function for all part
dipak-pawar May 24, 2018
f6e7fea
chore: extract configFilePath variable in test
dipak-pawar May 24, 2018
cca4a27
fix: add missing scenario - no config file, but hint file
dipak-pawar May 24, 2018
5e5bd42
doc: add doc for default loading behaviour of config hint file
dipak-pawar May 24, 2018
d584a4b
Merge branch 'master' of https://github.com/arquillian/ike-prow-plugi…
dipak-pawar May 24, 2018
1530326
fix: fix failing tests after merge
dipak-pawar May 24, 2018
9fd8d2e
fix: modified CreateCommentMessage to not use nested else
dipak-pawar May 24, 2018
317e2f8
modifies documentation
MatousJobanek May 24, 2018
264f938
brings back the string in defaultFileContent method to keep the
MatousJobanek May 24, 2018
6b6d360
removes location url in test case where it should be missing
MatousJobanek May 24, 2018
856bd0a
changes documentation so the content in plugins chapters reflects the
MatousJobanek May 24, 2018
78a84b4
Merge branch 'master' into issue_119
MatousJobanek May 24, 2018
4611126
removed unnecessary conversion
MatousJobanek May 24, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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