Skip to content

Commit

Permalink
Merge pull request #413 from kgns/feature/webhook_url
Browse files Browse the repository at this point in the history
Added WebhookURL to VCSRepo struct
  • Loading branch information
sebasslash committed Jun 9, 2022
2 parents 44a6190 + 4b777cf commit 7f5d83c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
35 changes: 17 additions & 18 deletions policy_set_integration_test.go
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"os"
"regexp"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -165,15 +166,14 @@ func TestPolicySetsCreate(t *testing.T) {
assert.Equal(t, ps.Description, "")
assert.False(t, ps.Global)
assert.Equal(t, ps.PoliciesPath, "/policy-sets/foo")
assert.Equal(t, ps.VCSRepo, &VCSRepo{
Branch: "policies",
DisplayIdentifier: githubIdentifier,
Identifier: githubIdentifier,
OAuthTokenID: oc.ID,
IngressSubmodules: true,
RepositoryHTTPURL: fmt.Sprintf("https://github.com/%s", githubIdentifier),
ServiceProvider: string(ServiceProviderGithub),
})
assert.Equal(t, ps.VCSRepo.Branch, "policies")
assert.Equal(t, ps.VCSRepo.DisplayIdentifier, githubIdentifier)
assert.Equal(t, ps.VCSRepo.Identifier, githubIdentifier)
assert.Equal(t, ps.VCSRepo.IngressSubmodules, true)
assert.Equal(t, ps.VCSRepo.OAuthTokenID, oc.ID)
assert.Equal(t, ps.VCSRepo.RepositoryHTTPURL, fmt.Sprintf("https://github.com/%s", githubIdentifier))
assert.Equal(t, ps.VCSRepo.ServiceProvider, string(ServiceProviderGithub))
assert.Regexp(t, fmt.Sprintf("^%s/webhooks/vcs/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", regexp.QuoteMeta(DefaultConfig().Address)), ps.VCSRepo.WebhookURL)
})

t.Run("with vcs policy updated", func(t *testing.T) {
Expand Down Expand Up @@ -203,15 +203,14 @@ func TestPolicySetsCreate(t *testing.T) {
assert.Equal(t, ps.Description, "")
assert.False(t, ps.Global)
assert.Equal(t, ps.PoliciesPath, "/policy-sets/bar")
assert.Equal(t, ps.VCSRepo, &VCSRepo{
Branch: "policies",
DisplayIdentifier: githubIdentifier,
Identifier: githubIdentifier,
OAuthTokenID: oc.ID,
IngressSubmodules: false,
RepositoryHTTPURL: fmt.Sprintf("https://github.com/%s", githubIdentifier),
ServiceProvider: string(ServiceProviderGithub),
})
assert.Equal(t, ps.VCSRepo.Branch, "policies")
assert.Equal(t, ps.VCSRepo.DisplayIdentifier, githubIdentifier)
assert.Equal(t, ps.VCSRepo.Identifier, githubIdentifier)
assert.Equal(t, ps.VCSRepo.IngressSubmodules, false)
assert.Equal(t, ps.VCSRepo.OAuthTokenID, oc.ID)
assert.Equal(t, ps.VCSRepo.RepositoryHTTPURL, fmt.Sprintf("https://github.com/%s", githubIdentifier))
assert.Equal(t, ps.VCSRepo.ServiceProvider, string(ServiceProviderGithub))
assert.Regexp(t, fmt.Sprintf("^%s/webhooks/vcs/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", regexp.QuoteMeta(DefaultConfig().Address)), ps.VCSRepo.WebhookURL)
})

t.Run("without a name provided", func(t *testing.T) {
Expand Down
20 changes: 11 additions & 9 deletions registry_module_integration_test.go
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/json"
"fmt"
"os"
"regexp"
"strings"
"testing"

Expand Down Expand Up @@ -310,15 +311,14 @@ func TestRegistryModulesCreateWithVCSConnection(t *testing.T) {
assert.NotEmpty(t, rm.ID)
assert.Equal(t, registryModuleName, rm.Name)
assert.Equal(t, registryModuleProvider, rm.Provider)
assert.Equal(t, &VCSRepo{
Branch: "",
Identifier: githubIdentifier,
OAuthTokenID: oauthTokenTest.ID,
DisplayIdentifier: githubIdentifier,
IngressSubmodules: true,
RepositoryHTTPURL: fmt.Sprintf("https://github.com/%s", githubIdentifier),
ServiceProvider: string(ServiceProviderGithub),
}, rm.VCSRepo)
assert.Equal(t, rm.VCSRepo.Branch, "")
assert.Equal(t, rm.VCSRepo.DisplayIdentifier, githubIdentifier)
assert.Equal(t, rm.VCSRepo.Identifier, githubIdentifier)
assert.Equal(t, rm.VCSRepo.IngressSubmodules, true)
assert.Equal(t, rm.VCSRepo.OAuthTokenID, oauthTokenTest.ID)
assert.Equal(t, rm.VCSRepo.RepositoryHTTPURL, fmt.Sprintf("https://github.com/%s", githubIdentifier))
assert.Equal(t, rm.VCSRepo.ServiceProvider, string(ServiceProviderGithub))
assert.Regexp(t, fmt.Sprintf("^%s/webhooks/vcs/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$", regexp.QuoteMeta(DefaultConfig().Address)), rm.VCSRepo.WebhookURL)

t.Run("permissions are properly decoded", func(t *testing.T) {
assert.True(t, rm.Permissions.CanDelete)
Expand Down Expand Up @@ -791,6 +791,7 @@ func TestRegistryModule_Unmarshal(t *testing.T) {
"oauth-token-id": "token",
"repository-http-url": "github.com",
"service-provider": "github",
"webhook-url": "https://app.terraform.io/webhooks/vcs/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
},
"version-statuses": []interface{}{
map[string]interface{}{
Expand Down Expand Up @@ -824,6 +825,7 @@ func TestRegistryModule_Unmarshal(t *testing.T) {
assert.Equal(t, rm.VCSRepo.OAuthTokenID, "token")
assert.Equal(t, rm.VCSRepo.RepositoryHTTPURL, "github.com")
assert.Equal(t, rm.VCSRepo.ServiceProvider, "github")
assert.Equal(t, rm.VCSRepo.WebhookURL, "https://app.terraform.io/webhooks/vcs/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")
assert.Equal(t, rm.Status, RegistryModuleStatusPending)
assert.Equal(t, rm.VersionStatuses[0].Version, "1.1.1")
assert.Equal(t, rm.VersionStatuses[0].Status, RegistryModuleVersionStatusPending)
Expand Down
1 change: 1 addition & 0 deletions workspace.go
Expand Up @@ -182,6 +182,7 @@ type VCSRepo struct {
OAuthTokenID string `jsonapi:"attr,oauth-token-id"`
RepositoryHTTPURL string `jsonapi:"attr,repository-http-url"`
ServiceProvider string `jsonapi:"attr,service-provider"`
WebhookURL string `jsonapi:"attr,webhook-url"`
}

// WorkspaceActions represents the workspace actions.
Expand Down
2 changes: 2 additions & 0 deletions workspace_integration_test.go
Expand Up @@ -1502,6 +1502,7 @@ func TestWorkspace_Unmarshal(t *testing.T) {
"oauth-token-id": "token",
"repository-http-url": "github.com",
"service-provider": "github",
"webhook-url": "https://app.terraform.io/webhooks/vcs/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
},
"actions": map[string]interface{}{
"is-destroyable": true,
Expand Down Expand Up @@ -1537,6 +1538,7 @@ func TestWorkspace_Unmarshal(t *testing.T) {
assert.Equal(t, ws.VCSRepo.OAuthTokenID, "token")
assert.Equal(t, ws.VCSRepo.RepositoryHTTPURL, "github.com")
assert.Equal(t, ws.VCSRepo.ServiceProvider, "github")
assert.Equal(t, ws.VCSRepo.WebhookURL, "https://app.terraform.io/webhooks/vcs/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")
assert.Equal(t, ws.Actions.IsDestroyable, true)
assert.Equal(t, ws.TriggerPrefixes, []string{"prefix-"})
assert.Equal(t, ws.TriggerPatterns, []string{"pattern1/**/*", "pattern2/**/submodule/*"})
Expand Down

0 comments on commit 7f5d83c

Please sign in to comment.