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

RELTEC-12278: support raw approvers/watchers #360

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions api/generated_model_repository_configuration_dto.go

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

18 changes: 18 additions & 0 deletions api/openapi-v3-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2061,6 +2061,15 @@ components:
type: array
items:
type: string
rawApprovers:
description: 'Raw data of approvers'
type: object
examples:
- some-owner: { }
additionalProperties:
type: array
items:
type: string
watchers:
description: 'List of strings (list of watchers, either usernames or group identifier), which are added as reviewers but require no approval.'
type: array
Expand All @@ -2070,6 +2079,15 @@ components:
- - someUser
- anotherUser
- '@owner.users'
rawWatchers:
description: 'Raw data of watchers'
type: array
items:
type: string
examples:
- - someUser
- anotherUser
- '@owner.users'
archived:
description: Moves the repository into the archive.
type: boolean
Expand Down
26 changes: 23 additions & 3 deletions internal/service/repositories/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,16 @@ func (s *Impl) GetRepository(ctx context.Context, repoKey string) (openapi.Repos

if err == nil && repositoryDto.Configuration != nil {
repoConfig := *repositoryDto.Configuration
repoConfig.RawApprovers = s.copyApprovers(repoConfig.Approvers)
s.expandApprovers(ctx, repoConfig.Approvers)
if repoConfig.Watchers != nil {
repoConfig.RawWatchers = s.copyStringList(repoConfig.Watchers)
repoConfig.Watchers = s.expandUserGroups(ctx, repoConfig.Watchers)
repositoryDto.Configuration = &repoConfig
}
if repoConfig.RefProtections != nil {
repoConfig.RefProtections = s.expandRefProtectionsExemptionLists(ctx, repoConfig.RefProtections)
repositoryDto.Configuration = &repoConfig
}

repositoryDto.Configuration = &repoConfig
}

if err == nil && repositoryDto.Filecategory != nil {
Expand Down Expand Up @@ -210,6 +210,26 @@ func (s *Impl) expandUserGroups(ctx context.Context, userList []string) []string
return util.RemoveDuplicateStr(filteredApprovers)
}

func (s *Impl) copyApprovers(approvers map[string][]string) map[string][]string {
if approvers != nil {
copyApprovers := map[string][]string{}
for name, approversList := range approvers {
copyApprovers[name] = s.copyStringList(approversList)
}
return copyApprovers
}
return nil
}

func (s *Impl) copyStringList(list []string) []string {
if len(list) > 0 {
copyList := make([]string, len(list))
copy(copyList, list)
return copyList
}
return nil
}

func (s *Impl) CreateRepository(ctx context.Context, key string, repositoryCreateDto openapi.RepositoryCreateDto) (openapi.RepositoryDto, error) {
repositoryDto := s.mapRepoCreateDtoToRepoDto(repositoryCreateDto)
if err := s.validateRepositoryCreateDto(ctx, key, repositoryCreateDto); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions test/acceptance/repositoryctl_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func TestPOSTRepository_Success(t *testing.T) {

docs.Then("And the repository has been cached and can be read again")
readAgain, err := tstPerformGet("/rest/api/v1/repositories/new-repository.api", tstUnauthenticated())
tstAssert(t, readAgain, err, http.StatusOK, "repository-create.json")
tstAssert(t, readAgain, err, http.StatusOK, "repository-create-cache.json")

docs.Then("And a kafka message notifying other instances of the creation has been sent")
require.Equal(t, 1, len(kafkaImpl.Recording))
Expand Down Expand Up @@ -363,7 +363,7 @@ func TestPUTRepository_Success(t *testing.T) {

docs.Then("And the repository has been cached and can be read again")
readAgain, err := tstPerformGet("/rest/api/v1/repositories/karma-wrapper.helm-chart", tstUnauthenticated())
tstAssert(t, readAgain, err, http.StatusOK, "repository-update.json")
tstAssert(t, readAgain, err, http.StatusOK, "repository-update-cache.json")

docs.Then("And a kafka message notifying other instances of the update has been sent")
require.Equal(t, 1, len(kafkaImpl.Recording))
Expand Down Expand Up @@ -617,7 +617,7 @@ func TestPUTRepository_ChangeOwner(t *testing.T) {

docs.Then("And the repository has been cached and can be read again, returning the correct owner")
readAgain, err := tstPerformGet("/rest/api/v1/repositories/karma-wrapper.helm-chart", tstUnauthenticated())
tstAssert(t, readAgain, err, http.StatusOK, "repository-update-newowner.json")
tstAssert(t, readAgain, err, http.StatusOK, "repository-update-newowner-cache.json")

docs.Then("And a kafka message notifying other instances of the update has been sent")
require.Equal(t, 1, len(kafkaImpl.Recording))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
}
]
},
"rawApprovers": {
"testing": [
"some-user"
]
},
"requireIssue": true
},
"generator": "third-party-software",
Expand Down
13 changes: 13 additions & 0 deletions test/resources/acceptance-expected/repositories.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@
}
]
},
"rawApprovers": {
"testing": [
"@some-owner.users"
]
},
"rawWatchers": [
"@some-owner.users"
],
"refProtections": {
"branches": {
"requirePR": [
Expand Down Expand Up @@ -118,6 +126,11 @@
}
]
},
"rawApprovers": {
"testing": [
"some-user"
]
},
"requireIssue": true
},
"generator": "third-party-software",
Expand Down
52 changes: 52 additions & 0 deletions test/resources/acceptance-expected/repository-create-cache.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"commitHash": "6c8ac2c35791edf9979623c717a2430000000000",
"configuration": {
"accessKeys": [
{
"key": "KEY",
"permission": "REPO_WRITE"
}
],
"approvers": {
"testing": [
"some-user"
]
},
"commitMessageType": "SEMANTIC",
"rawApprovers": {
"testing": [
"some-user"
]
},
"requireConditions": {
"snyk-key": {
"refMatcher": "master"
}
},
"requireIssue": false,
"requireSuccessfulBuilds": 1,
"webhooks": {
"additional": [
{
"events": [
"event"
],
"name": "webhookname",
"url": "webhookurl"
}
]
}
},
"filecategory": {
"cached-template": [
"cached-templates/tpl1.yaml",
"more/cached/templates/tpl2.yaml"
]
},
"jiraIssue": "ISSUE-2345",
"mainline": "master",
"owner": "some-owner",
"timeStamp": "2022-11-06T18:14:10Z",
"unittest": false,
"url": "ssh://[email protected]:7999/helm/karma-wrapper.git"
}
6 changes: 5 additions & 1 deletion test/resources/acceptance-expected/repository-create.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@
]
},
"commitMessageType": "SEMANTIC",
"requireConditions": {
"snyk-key": {
"refMatcher": "master"
}
},
"requireIssue": false,
"requireSuccessfulBuilds": 1,
"requireConditions":{"snyk-key":{"refMatcher":"master"}},
"webhooks": {
"additional": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,19 @@
}
]
},
"rawApprovers": {
"testing": [
"@some-owner.users"
]
},
"rawWatchers": [
"@some-owner.users"
],
"refProtections": {
"branches": {
"requirePR": [
{
"exemptions": [
"exemptions": [
"some-other-user",
"a-very-special-user"
],
Expand Down
52 changes: 52 additions & 0 deletions test/resources/acceptance-expected/repository-update-cache.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"commitHash": "6c8ac2c35791edf9979623c717a2430000000000",
"configuration": {
"accessKeys": [
{
"key": "KEY",
"permission": "REPO_WRITE"
}
],
"approvers": {
"testing": [
"some-user"
]
},
"commitMessageType": "SEMANTIC",
"rawApprovers": {
"testing": [
"some-user"
]
},
"requireConditions": {
"snyk-key": {
"refMatcher": "master"
}
},
"requireIssue": false,
"requireSuccessfulBuilds": 1,
"webhooks": {
"additional": [
{
"events": [
"event"
],
"name": "webhookname",
"url": "webhookurl"
}
]
}
},
"filecategory": {
"cached-template": [
"cached-templates/tpl1.yaml",
"more/cached/templates/tpl2.yaml"
]
},
"jiraIssue": "ISSUE-2345",
"mainline": "master",
"owner": "some-owner",
"timeStamp": "2022-11-06T18:14:10Z",
"unittest": false,
"url": "ssh://[email protected]:7999/helm/karma-wrapper.git"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"commitHash": "6c8ac2c35791edf9979623c717a2430000000000",
"configuration": {
"accessKeys": [
{
"key": "KEY",
"permission": "REPO_WRITE"
}
],
"approvers": {
"testing": [
"some-user"
]
},
"commitMessageType": "SEMANTIC",
"rawApprovers": {
"testing": [
"some-user"
]
},
"requireConditions": {
"snyk-key": {
"refMatcher": "master"
}
},
"requireIssue": false,
"requireSuccessfulBuilds": 1,
"webhooks": {
"additional": [
{
"events": [
"event"
],
"name": "webhookname",
"url": "webhookurl"
}
]
}
},
"filecategory": {
"cached-template": [
"cached-templates/tpl1.yaml",
"more/cached/templates/tpl2.yaml"
]
},
"jiraIssue": "ISSUE-2345",
"mainline": "master",
"owner": "deleteme",
"timeStamp": "2022-11-06T18:14:10Z",
"unittest": false,
"url": "ssh://[email protected]:7999/helm/karma-wrapper.git"
}
6 changes: 5 additions & 1 deletion test/resources/acceptance-expected/repository-update.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
"commitMessageType": "SEMANTIC",
"requireIssue": false,
"requireSuccessfulBuilds": 1,
"requireConditions":{"snyk-key":{"refMatcher":"master"}},
"requireConditions": {
"snyk-key": {
"refMatcher": "master"
}
},
"webhooks": {
"additional": [
{
Expand Down
5 changes: 5 additions & 0 deletions test/resources/acceptance-expected/repository.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
}
]
},
"rawApprovers": {
"testing": [
"some-user"
]
},
"requireIssue": true
},
"generator": "third-party-software",
Expand Down
Loading