Skip to content

Commit b572d58

Browse files
committed
Address git integration review feedback
1 parent 9b6f811 commit b572d58

File tree

5 files changed

+35
-7
lines changed

5 files changed

+35
-7
lines changed

internal/services/git_integration/api_git_integration.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ func (c *client) EnableSolutionSourceControlIntegration(ctx context.Context, env
709709

710710
apiURL := helpers.BuildDataverseApiUrl(environmentHost, fmt.Sprintf("/api/data/v9.0/solutions(%s)", solutionID), nil)
711711
resp, err := c.Api.Execute(ctx, nil, http.MethodPatch, apiURL, nil, updateSolutionSourceControlIntegrationDto{
712-
EnabledForSourceControlIntegration: "true",
712+
EnabledForSourceControlIntegration: true,
713713
}, []int{http.StatusNoContent, http.StatusForbidden, http.StatusNotFound}, nil)
714714
if err != nil {
715715
return err
@@ -769,7 +769,6 @@ func (c *client) SetSourceControlIntegrationScope(ctx context.Context, environme
769769

770770
updatedOrgSettings := setOrgDbOrgSettingValue(orgSettings.OrgDbOrgSettings, "SourceControlIntegrationScope", sourceControlIntegrationScopeToOrgDbValue(scope))
771771
updateDTO := organizationSettingsDto{
772-
OrganizationID: orgSettings.OrganizationID,
773772
OrgDbOrgSettings: updatedOrgSettings,
774773
}
775774

internal/services/git_integration/dto.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,5 @@ type preValidateGitComponentsResponseDto struct {
143143
}
144144

145145
type updateSolutionSourceControlIntegrationDto struct {
146-
EnabledForSourceControlIntegration string `json:"enabledforsourcecontrolintegration,omitempty"`
146+
EnabledForSourceControlIntegration bool `json:"enabledforsourcecontrolintegration,omitempty"`
147147
}

internal/services/git_integration/models.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,21 @@ type SolutionGitBranchResourceModel struct {
5757
}
5858

5959
func gitProviderToInt(value string) int {
60-
_ = strings.TrimSpace(value)
61-
return 0
60+
switch strings.TrimSpace(value) {
61+
case "", gitProviderAzureDevOps:
62+
return 0
63+
default:
64+
return -1
65+
}
6266
}
6367

6468
func gitProviderFromInt(value int) string {
65-
_ = value
66-
return gitProviderAzureDevOps
69+
switch value {
70+
case 0:
71+
return gitProviderAzureDevOps
72+
default:
73+
return ""
74+
}
6775
}
6876

6977
func convertSourceControlConfigurationDtoToModel(environmentID, scope string, dto sourceControlConfigurationDto) EnvironmentGitIntegrationResourceModel {

internal/services/git_integration/resource_environment_git_integration_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package git_integration_test
55

66
import (
77
"fmt"
8+
"io"
89
"net/http"
910
"regexp"
1011
"strings"
@@ -112,11 +113,30 @@ func TestUnitEnvironmentGitIntegrationResource_Validate_Create_And_Update(t *tes
112113

113114
httpmock.RegisterRegexpResponder("PATCH", regexp.MustCompile(`^https://00000000-0000-0000-0000-000000000001\.crm4\.dynamics\.com/api/data/v9\.0/organizations%28aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa%29$`),
114115
func(req *http.Request) (*http.Response, error) {
116+
body, err := io.ReadAll(req.Body)
117+
if err != nil {
118+
return nil, err
119+
}
120+
bodyText := string(body)
121+
if strings.Contains(bodyText, "organizationid") {
122+
return nil, fmt.Errorf("organization scope patch unexpectedly included organizationid: %s", bodyText)
123+
}
124+
if !strings.Contains(bodyText, "SourceControlIntegrationScope") {
125+
return nil, fmt.Errorf("organization scope patch missing SourceControlIntegrationScope: %s", bodyText)
126+
}
115127
return httpmock.NewStringResponse(http.StatusNoContent, ""), nil
116128
})
117129

118130
httpmock.RegisterRegexpResponder("PATCH", regexp.MustCompile(`^https://00000000-0000-0000-0000-000000000001\.crm4\.dynamics\.com/api/data/v9\.0/solutions(?:%28|\()(33333333-3333-3333-3333-333333333333|44444444-4444-4444-4444-444444444444)(?:%29|\))$`),
119131
func(req *http.Request) (*http.Response, error) {
132+
body, err := io.ReadAll(req.Body)
133+
if err != nil {
134+
return nil, err
135+
}
136+
bodyText := string(body)
137+
if !strings.Contains(bodyText, `"enabledforsourcecontrolintegration":true`) {
138+
return nil, fmt.Errorf("solution enablement patch did not send boolean true: %s", bodyText)
139+
}
120140
matched := false
121141
for _, id := range []string{
122142
"33333333-3333-3333-3333-333333333333",

internal/services/git_integration/validation.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func (r *EnvironmentGitIntegrationResource) validateRemoteConfiguration(ctx cont
4242
"Invalid project_name",
4343
fmt.Sprintf("The Git project `%s` was not returned by the Dataverse `gitprojects` endpoint for organization `%s`.", data.ProjectName.ValueString(), data.OrganizationName.ValueString()),
4444
)
45+
return
4546
}
4647

4748
repositories, err := r.GitIntegrationClient.ListGitRepositories(ctx, data.EnvironmentID.ValueString(), data.OrganizationName.ValueString(), data.ProjectName.ValueString())

0 commit comments

Comments
 (0)