Skip to content

Commit

Permalink
feat(#292): add pr build config (key and url)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanHCB committed Jun 7, 2024
1 parent d5732e5 commit 94a9b9c
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ the [`local-config.yaml`][config] can be used to set the variables.
| | | |
| `BITBUCKET_USERNAME` | | Name of the user used for basic git authentication to pull and update the metadata repository. |
| `BITBUCKET_PASSWORD` | | Password of the user used for basic git authentication to pull and update the metadata repository. |
| `PULL_REQUEST_BUILD_URL` | | Url to link to on pull request builds. Should probably be the public URL of this service. |
| `PULL_REQUEST_BUILD_KEY` | `metadata-service` | Key for pull request builds on pull requests in the underlying git repository. Changed files are syntactically validated. |
| | | |
| `GIT_COMMITTER_NAME` | | Name of the user used to create the Git commits. |
| `GIT_COMMITTER_EMAIL` | | E-Mail of the user used to create the Git commits. |
Expand Down
5 changes: 5 additions & 0 deletions internal/acorn/config/customconfigint.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ type CustomConfiguration interface {

RedisUrl() string
RedisPassword() string

PullRequestBuildUrl() string
PullRequestBuildKey() string
}

type NotificationConsumerConfig struct {
Expand Down Expand Up @@ -125,4 +128,6 @@ const (
KeyAllowedFileCategories = "ALLOWED_FILE_CATEGORIES"
KeyRedisUrl = "REDIS_URL"
KeyRedisPassword = "REDIS_PASSWORD"
KeyPullRequestBuildUrl = "PULL_REQUEST_BUILD_URL"
KeyPullRequestBuildKey = "PULL_REQUEST_BUILD_KEY"
)
8 changes: 8 additions & 0 deletions internal/repository/config/accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,11 @@ func (c *CustomConfigImpl) MetadataRepoName() string {
}
return ""
}

func (c *CustomConfigImpl) PullRequestBuildUrl() string {
return c.VPullRequestBuildUrl
}

func (c *CustomConfigImpl) PullRequestBuildKey() string {
return c.VPullRequestBuildKey
}
14 changes: 14 additions & 0 deletions internal/repository/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,18 @@ var CustomConfigItems = []auconfigapi.ConfigItem{
Description: "password used to access the redis",
Validate: auconfigapi.ConfigNeedsNoValidation,
},
{
Key: config.KeyPullRequestBuildUrl,
EnvName: config.KeyPullRequestBuildUrl,
Default: "",
Description: "Url that pull request builds should link to.",
Validate: auconfigenv.ObtainPatternValidator("^https?://.*$"),
},
{
Key: config.KeyPullRequestBuildKey,
EnvName: config.KeyPullRequestBuildKey,
Default: "metadata-service",
Description: "Key to use for pull request builds.",
Validate: auconfigapi.ConfigNeedsNoValidation,
},
}
4 changes: 4 additions & 0 deletions internal/repository/config/plumbing.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ type CustomConfigImpl struct {
VAllowedFileCategories []string
VRedisUrl string
VRedisPassword string
VPullRequestBuildUrl string
VPullRequestBuildKey string

VKafkaConfig *aukafka.Config
BitbucketGitUrlMatcher *regexp.Regexp
Expand Down Expand Up @@ -125,6 +127,8 @@ func (c *CustomConfigImpl) Obtain(getter func(key string) string) {
c.VAllowedFileCategories, _ = parseAllowedFileCategories(getter(config.KeyAllowedFileCategories))
c.VRedisUrl = getter(config.KeyRedisUrl)
c.VRedisPassword = getter(config.KeyRedisPassword)
c.VPullRequestBuildUrl = getter(config.KeyPullRequestBuildUrl)
c.VPullRequestBuildKey = getter(config.KeyPullRequestBuildKey)

c.VKafkaConfig.Obtain(getter)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/repository/config/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestValidate_LotsOfErrors(t *testing.T) {
_, err := tstSetupCutAndLogRecorder(t, "invalid-config-values.yaml")

require.NotNil(t, err)
require.Contains(t, err.Error(), "some configuration values failed to validate or parse. There were 27 error(s). See details above")
require.Contains(t, err.Error(), "some configuration values failed to validate or parse. There were 28 error(s). See details above")

actualLog := goauzerolog.RecordedLogForTesting.String()

Expand Down
3 changes: 3 additions & 0 deletions local-config.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ BITBUCKET_SERVER: https://bitbucket.subdomain.com
BITBUCKET_CACHE_SIZE: 1000
BITBUCKET_CACHE_RETENTION_SECONDS: 3600

# Url to this service, used as link in Pull Request validation builds
PULL_REQUEST_BUILD_URL: https://metadata-service.example.com

GIT_COMMITTER_NAME: <YOU MUST ADD SOME COMMITTER NAME HERE - SEE README>
GIT_COMMITTER_EMAIL: <YOU MUST ADD SOME COMMITTER EMAIL HERE - SEE README>

Expand Down
8 changes: 8 additions & 0 deletions test/mock/configmock/configmock.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,11 @@ func (c *MockConfig) MetadataRepoProject() string {
func (c *MockConfig) MetadataRepoName() string {
return "sample-repo"
}

func (c *MockConfig) PullRequestBuildUrl() string {
return "https://example.com"
}

func (c *MockConfig) PullRequestBuildKey() string {
return "metadata-service"
}
1 change: 1 addition & 0 deletions test/resources/valid-config-unique.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ BASIC_AUTH_PASSWORD: some-basic-auth-password
BITBUCKET_USERNAME: some-bitbucket-username
BITBUCKET_PASSWORD: some-bitbucket-password
BITBUCKET_REVIEWER_FALLBACK: username
PULL_REQUEST_BUILD_URL: https://metadata-service.example.com

GIT_COMMITTER_NAME: 'Body, Some'
GIT_COMMITTER_EMAIL: 'somebody@somewhere.com'
Expand Down
1 change: 1 addition & 0 deletions test/resources/valid-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ LOGSTYLE: plain

BITBUCKET_USERNAME: localuser
BITBUCKET_REVIEWER_FALLBACK: username
PULL_REQUEST_BUILD_URL: https://metadata-service.example.com

AUTH_OIDC_TOKEN_AUDIENCE: some-audience
AUTH_GROUP_WRITE: admin
Expand Down

0 comments on commit 94a9b9c

Please sign in to comment.