From 76c51017256c7e35440b4b64da23154441a6afc0 Mon Sep 17 00:00:00 2001 From: Richard Gee Date: Sun, 17 Apr 2022 14:02:08 +0100 Subject: [PATCH] Force local headings to over-ride remote A recent issue (https://github.com/alexellis/go-execute/issues/10) indirectly highlighted that the merging of local and remote configs was producing a superset which included duplicate headings. The intended mode of operation for the Issue template headings was for the local to over-ride the remote. This is diffent to the other fields, such as maintainers. This change adds the test to highlight the issue and addresses the issue in MergeDerekRepoConfigs. Signed-off-by: Richard Gee --- USER_GUIDE.md | 2 ++ types/merge.go | 4 ++++ types/merge_test.go | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/USER_GUIDE.md b/USER_GUIDE.md index 544a3c8..36ed737 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -274,3 +274,5 @@ You can specify a `redirect` URL in the .DEREK.yml file, this instructs derek to apply local overrides and additions to the config set in the remote file. For example, to add a contributor to that repo (in addition to the existing contributors) you can specify the remote file and also add the `maintainers` section to your local file. These lists will then be merged, giving all users in the merged set access to derek. + +The exception to the rule in the merging of configs is in the `required_in_issues` feature where the locally configured values will fully override any and all values set in the remote config. diff --git a/types/merge.go b/types/merge.go index 0916249..431d06e 100644 --- a/types/merge.go +++ b/types/merge.go @@ -11,5 +11,9 @@ func MergeDerekRepoConfigs(localConfig, remoteConfig DerekRepoConfig) (DerekRepo return remoteConfig, mergeErr } + if len(localConfig.RequiredInIssues) > 0 { + remoteConfig.RequiredInIssues = localConfig.RequiredInIssues + } + return remoteConfig, nil } diff --git a/types/merge_test.go b/types/merge_test.go index 1590755..acc8bbc 100644 --- a/types/merge_test.go +++ b/types/merge_test.go @@ -78,3 +78,27 @@ func Test_mergeDerekRepoConfigs_ConfigValuesAppendedToList(t *testing.T) { } } + +func Test_mergeDerekRepoConfigs_UseLocalHeadings(t *testing.T) { + + remote := DerekRepoConfig{ + RequiredInIssues: []string{ + "#1", + "#2", + }, + } + local := DerekRepoConfig{ + RequiredInIssues: []string{ + "#2", + }, + } + + got, err := MergeDerekRepoConfigs(local, remote) + + if err != nil { + t.Errorf("Got error for a single plan, expected no error: %s", err.Error()) + } + if len(got.RequiredInIssues) != len(local.RequiredInIssues) { + t.Errorf("RequiredInIssues want %s, but got %s", local.RequiredInIssues, got.RequiredInIssues) + } +}