Skip to content

Commit

Permalink
Support remote references in default config (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
asvoboda committed Aug 23, 2021
1 parent 1ca1ce1 commit 9aaeeac
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions appconfig/appconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,18 @@ func (ld *Loader) loadDefaultConfig(ctx context.Context, client *github.Client,
continue
}

// if remote refs are enabled, see if the file is a remote reference
if ld.parser != nil {
remote, err := ld.parser(p, content)
if err != nil {
return c, err
}
if remote != nil {
logger.Debug().Msgf("Found remote default configuration at %s in %s", p, c.Source)
return ld.loadRemoteConfig(ctx, client, *remote, c)
}
}

// non-remote content found, don't try any other paths
logger.Debug().Msgf("Found default configuration at %s in %s", c.Path, c.Source)
c.Content = content
Expand Down
17 changes: 17 additions & 0 deletions appconfig/appconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ func TestLoadConfig(t *testing.T) {
Path: "test-app.yml",
},
},
"defaultConfigRemoteReference": {
Paths: []string{".github-remote/test-app.yml"},
Options: []Option{
WithOwnerDefault(".github-remote", []string{"test-app.yml"}),
},
Repo: "default-config-remote-ref",
Expected: Config{
Content: []byte("message: hello\n"),
Source: "remote/config@develop",
Path: "config/test-app.yml",
IsRemote: true,
},
},
}

ctx := context.Background()
Expand Down Expand Up @@ -147,6 +160,10 @@ func makeTestClient() *github.Client {
"/repos/test/default-config/contents/.github/test-app.yml": "404.yml",
"/repos/test/.github": "dot-github.yml",
"/repos/test/.github/contents/test-app.yml": "dot-github-contents.yml",

"/repos/test/default-config-remote-ref/contents/.github-remote/test-app.yml": "404.yml",
"/repos/test/.github-remote": "remote-config.yml",
"/repos/test/config/contents/test-app.yml": "remote-ref-contents.yml",
} {
rp.AddRule(ExactPathMatcher(route), filepath.Join("testdata", f))
}
Expand Down

0 comments on commit 9aaeeac

Please sign in to comment.