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 patchin repository to include archived #232

Merged
merged 1 commit into from
Nov 15, 2023
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
1 change: 1 addition & 0 deletions internal/service/repositories/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ func patchConfiguration(patch *openapi.RepositoryConfigurationDto, original *ope
Watchers: patchStringSlice(patch.Watchers, original.Watchers),
DefaultReviewers: patchStringSlice(patch.DefaultReviewers, original.DefaultReviewers),
SignedApprovers: patchStringSlice(patch.SignedApprovers, original.SignedApprovers),
Archived: patchPtr[bool](patch.Archived, original.Archived),
}
} else {
return original
Expand Down
74 changes: 37 additions & 37 deletions internal/service/repositories/repositories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ import (
"time"
)

func p(v string) *string {
return &v
}

func b(v bool) *bool {
func ptr[T any](v T) *T {
return &v
}

Expand All @@ -32,20 +28,20 @@ func createRepositoryDto() openapi.RepositoryDto {
Owner: "owner",
Url: "url",
Mainline: "mainline",
Generator: p("generator"),
Unittest: b(true),
Generator: ptr("generator"),
Unittest: ptr(true),
Configuration: &openapi.RepositoryConfigurationDto{
AccessKeys: []openapi.RepositoryConfigurationAccessKeyDto{
{
Key: "KEY",
Permission: p("REPO_WRITE"),
Permission: ptr("REPO_WRITE"),
},
},
CommitMessageType: p("SEMANTIC"),
RequireIssue: b(false),
CommitMessageType: ptr("SEMANTIC"),
RequireIssue: ptr(false),
RequireSuccessfulBuilds: i(1),
Webhooks: &openapi.RepositoryConfigurationWebhooksDto{
PipelineTrigger: b(false),
PipelineTrigger: ptr(false),
Additional: []openapi.RepositoryConfigurationWebhookDto{
{
Name: "webhookname",
Expand All @@ -58,6 +54,7 @@ func createRepositoryDto() openapi.RepositoryDto {
Approvers: &map[string][]string{"group": {"approver1"}},
DefaultReviewers: []string{"defaultreviewer1"},
SignedApprovers: []string{"signedapprover1"},
Archived: ptr(false),
},
Filecategory: &map[string][]string{"a": {"path/a.yaml"}},
TimeStamp: "ts",
Expand Down Expand Up @@ -105,23 +102,23 @@ func TestPatchRepository_WithConfig_And_EmptyOriginal(t *testing.T) {
func TestPatchRepository_ReplaceAll(t *testing.T) {
docs.Description("patching of repositories works with an all fields patch")
assertPatchRepository(t, createRepositoryDto(), openapi.RepositoryPatchDto{
Owner: p("newowner"),
Url: p("newurl"),
Mainline: p("newmainline"),
Generator: p("newgenerator"),
Unittest: b(false),
Owner: ptr("newowner"),
Url: ptr("newurl"),
Mainline: ptr("newmainline"),
Generator: ptr("newgenerator"),
Unittest: ptr(false),
Configuration: &openapi.RepositoryConfigurationDto{
AccessKeys: []openapi.RepositoryConfigurationAccessKeyDto{
{
Key: "DEPLOYMENT",
Permission: p("REPO_READ"),
Permission: ptr("REPO_READ"),
},
},
CommitMessageType: p("DEFAULT"),
RequireIssue: b(true),
CommitMessageType: ptr("DEFAULT"),
RequireIssue: ptr(true),
RequireSuccessfulBuilds: i(2),
Webhooks: &openapi.RepositoryConfigurationWebhooksDto{
PipelineTrigger: b(false),
PipelineTrigger: ptr(false),
Additional: []openapi.RepositoryConfigurationWebhookDto{
{
Name: "newwebhookname",
Expand All @@ -134,6 +131,7 @@ func TestPatchRepository_ReplaceAll(t *testing.T) {
Approvers: &map[string][]string{"group": {"newapprover1"}},
DefaultReviewers: []string{"newdefaultreviewer1"},
SignedApprovers: []string{"newsignedapprover1"},
Archived: ptr(true),
},
Filecategory: &map[string][]string{"b": {"b.yaml", "b.json"}},
TimeStamp: "newts",
Expand All @@ -142,20 +140,20 @@ func TestPatchRepository_ReplaceAll(t *testing.T) {
Owner: "newowner",
Url: "newurl",
Mainline: "newmainline",
Generator: p("newgenerator"),
Unittest: b(false),
Generator: ptr("newgenerator"),
Unittest: ptr(false),
Configuration: &openapi.RepositoryConfigurationDto{
AccessKeys: []openapi.RepositoryConfigurationAccessKeyDto{
{
Key: "DEPLOYMENT",
Permission: p("REPO_READ"),
Permission: ptr("REPO_READ"),
},
},
CommitMessageType: p("DEFAULT"),
RequireIssue: b(true),
CommitMessageType: ptr("DEFAULT"),
RequireIssue: ptr(true),
RequireSuccessfulBuilds: i(2),
Webhooks: &openapi.RepositoryConfigurationWebhooksDto{
PipelineTrigger: b(false),
PipelineTrigger: ptr(false),
Additional: []openapi.RepositoryConfigurationWebhookDto{
{
Name: "newwebhookname",
Expand All @@ -168,6 +166,7 @@ func TestPatchRepository_ReplaceAll(t *testing.T) {
Approvers: &map[string][]string{"group": {"newapprover1"}},
DefaultReviewers: []string{"newdefaultreviewer1"},
SignedApprovers: []string{"newsignedapprover1"},
Archived: ptr(true),
},
Filecategory: &map[string][]string{"b": {"b.yaml", "b.json"}},
TimeStamp: "newts",
Expand All @@ -178,13 +177,13 @@ func TestPatchRepository_ReplaceAll(t *testing.T) {
func TestPatchRepository_ClearFields(t *testing.T) {
docs.Description("patching of repositories works with a patch that clears fields (result would not validate)")
assertPatchRepository(t, createRepositoryDto(), openapi.RepositoryPatchDto{
Owner: p(""),
Url: p(""),
Mainline: p(""),
Generator: p(""),
Owner: ptr(""),
Url: ptr(""),
Mainline: ptr(""),
Generator: ptr(""),
Configuration: &openapi.RepositoryConfigurationDto{
AccessKeys: []openapi.RepositoryConfigurationAccessKeyDto{},
CommitMessageType: p(""),
CommitMessageType: ptr(""),
Webhooks: &openapi.RepositoryConfigurationWebhooksDto{
Additional: []openapi.RepositoryConfigurationWebhookDto{},
},
Expand All @@ -200,19 +199,20 @@ func TestPatchRepository_ClearFields(t *testing.T) {
Url: "",
Mainline: "",
Generator: nil,
Unittest: b(true),
Unittest: ptr(true),
Configuration: &openapi.RepositoryConfigurationDto{
AccessKeys: nil,
CommitMessageType: nil,
RequireIssue: b(false),
RequireIssue: ptr(false),
RequireSuccessfulBuilds: i(1),
Webhooks: &openapi.RepositoryConfigurationWebhooksDto{
PipelineTrigger: b(false),
PipelineTrigger: ptr(false),
Additional: nil,
},
Approvers: nil,
DefaultReviewers: nil,
SignedApprovers: nil,
Archived: ptr(false),
},
Filecategory: nil,
TimeStamp: "",
Expand Down Expand Up @@ -369,7 +369,7 @@ func TestValidate_Url(t *testing.T) {
create.Url = "https://no.this.is.not.correct.git"

patch := openapi.RepositoryPatchDto{
Url: p("https://no.this.is.not.correct.git"),
Url: ptr("https://no.this.is.not.correct.git"),
}

expectedMessage := "validation error: field url must contain ssh git url"
Expand All @@ -387,7 +387,7 @@ func TestValidate_Mainline(t *testing.T) {
create.Mainline = "feature/hello"

patch := openapi.RepositoryPatchDto{
Mainline: p("feature/hello"),
Mainline: ptr("feature/hello"),
}

expectedMessage := "validation error: mainline must be one of master, main, develop"
Expand All @@ -396,7 +396,7 @@ func TestValidate_Mainline(t *testing.T) {

data.Mainline = ""
create.Mainline = ""
patch.Mainline = p("")
patch.Mainline = ptr("")

expectedMessage = "validation error: field mainline is mandatory"

Expand Down
Loading