Skip to content

Commit a299d7e

Browse files
authored
Adds support for VCS source_directory and tag_prefix options (#1154)
1 parent fd41a1e commit a299d7e

File tree

6 files changed

+171
-1
lines changed

6 files changed

+171
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Unreleased
22

3+
## Enhancements
4+
* Adds support for `RegistryModule` VCS source_directory and tag_prefix options, by @jillrami [#1154] (https://github.com/hashicorp/go-tfe/pull/1154)
5+
36
# v1.89.0
47

58
## Enhancements
@@ -15,7 +18,6 @@
1518
* Adds BETA support for reading, testing and updating Organization Audit Configuration by @glennsarti-hashi [#1151](https://github.com/hashicorp/go-tfe/pull/1151)
1619
* Adds `Completed` status to `StackConfiguration` by @hwatkins05-hashicorp [#1163](https://github.com/hashicorp/go-tfe/pull/1163)
1720

18-
1921
# v1.87.0
2022

2123
## Bug Fixes

helper_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,15 @@ func createOrganization(t *testing.T, client *Client) (*Organization, func()) {
991991
})
992992
}
993993

994+
func createOrganizationWithMonorepoSupport(t *testing.T, client *Client) (*Organization, func()) {
995+
return createOrganizationWithOptions(t, client, OrganizationCreateOptions{
996+
Name: String("tst-" + randomString(t)),
997+
Email: String(fmt.Sprintf("%[email protected]", randomString(t))),
998+
CostEstimationEnabled: Bool(true),
999+
RegistryMonorepoSupportEnabled: Bool(true),
1000+
})
1001+
}
1002+
9941003
func createOrganizationWithOptions(t *testing.T, client *Client, options OrganizationCreateOptions) (*Organization, func()) {
9951004
ctx := context.Background()
9961005
org, err := client.Organizations.Create(ctx, options)

organization.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ type OrganizationCreateOptions struct {
258258
// Optional: StacksEnabled toggles whether stacks are enabled for the organization. This setting
259259
// is considered BETA, SUBJECT TO CHANGE, and likely unavailable to most users.
260260
StacksEnabled *bool `jsonapi:"attr,stacks-enabled,omitempty"`
261+
262+
// Optional: RegistryMonorepoSupportEnabled toggles whether monorepo support is enabled for the organization
263+
RegistryMonorepoSupportEnabled *bool `jsonapi:"attr,registry-monorepo-support-enabled,omitempty"`
261264
}
262265

263266
// OrganizationUpdateOptions represents the options for updating an organization.
@@ -313,6 +316,9 @@ type OrganizationUpdateOptions struct {
313316
// Optional: StacksEnabled toggles whether stacks are enabled for the organization. This setting
314317
// is considered BETA, SUBJECT TO CHANGE, and likely unavailable to most users.
315318
StacksEnabled *bool `jsonapi:"attr,stacks-enabled,omitempty"`
319+
320+
// Optional: RegistryMonorepoSupportEnabled toggles whether monorepo support is enabled for the organization
321+
RegistryMonorepoSupportEnabled *bool `jsonapi:"attr,registry-monorepo-support-enabled,omitempty"`
316322
}
317323

318324
// ReadRunQueueOptions represents the options for showing the queue.

registry_module.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,10 @@ type RegistryModuleVCSRepoOptions struct {
370370
// **Note: This field is still in BETA and subject to change.**
371371
Branch *string `json:"branch,omitempty"`
372372
Tags *bool `json:"tags,omitempty"`
373+
374+
// Optional: If set, the registry module will be branch-based or tag-based
375+
SourceDirectory *string `json:"source-directory,omitempty"`
376+
TagPrefix *string `json:"tag-prefix,omitempty"`
373377
}
374378

375379
type RegistryModuleVCSRepoUpdateOptions struct {
@@ -380,6 +384,10 @@ type RegistryModuleVCSRepoUpdateOptions struct {
380384
// **Note: This field is still in BETA and subject to change.**
381385
Branch *string `json:"branch,omitempty"`
382386
Tags *bool `json:"tags,omitempty"`
387+
388+
// Optional: If set, the registry module will be branch-based or tag-based
389+
SourceDirectory *string `json:"source-directory,omitempty"`
390+
TagPrefix *string `json:"tag-prefix,omitempty"`
383391
}
384392

385393
// List all the registry modules within an organization.

registry_module_integration_test.go

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,149 @@ func TestRegistryModulesCreateBranchBasedWithVCSConnection(t *testing.T) {
962962
})
963963
}
964964

965+
func TestRegistryModulesCreateMonorepoBranchBasedWithVCSConnection(t *testing.T) {
966+
skipUnlessBeta(t)
967+
968+
githubIdentifier := os.Getenv("GITHUB_REGISTRY_MODULE_IDENTIFIER")
969+
if githubIdentifier == "" {
970+
t.Skip("Export a valid GITHUB_REGISTRY_MODULE_IDENTIFIER before running this test")
971+
}
972+
repositoryName := strings.Split(githubIdentifier, "/")[1]
973+
registryModuleProvider := strings.SplitN(repositoryName, "-", 3)[1]
974+
registryModuleName := strings.SplitN(repositoryName, "-", 3)[2]
975+
976+
githubBranch := os.Getenv("GITHUB_REGISTRY_MODULE_BRANCH")
977+
if githubBranch == "" {
978+
githubBranch = "main"
979+
}
980+
981+
client := testClient(t)
982+
ctx := context.Background()
983+
984+
orgTest, orgTestCleanup := createOrganizationWithMonorepoSupport(t, client)
985+
t.Cleanup(orgTestCleanup)
986+
987+
oauthTokenTest, oauthTokenTestCleanup := createOAuthToken(t, client, orgTest)
988+
t.Cleanup(oauthTokenTestCleanup)
989+
990+
t.Run("with valid options including source directory", func(t *testing.T) {
991+
sourceDirectory := "src"
992+
993+
options := RegistryModuleCreateWithVCSConnectionOptions{
994+
VCSRepo: &RegistryModuleVCSRepoOptions{
995+
OrganizationName: String(orgTest.Name),
996+
Identifier: String(githubIdentifier),
997+
OAuthTokenID: String(oauthTokenTest.ID),
998+
DisplayIdentifier: String(githubIdentifier),
999+
Branch: String(githubBranch),
1000+
SourceDirectory: String(sourceDirectory),
1001+
},
1002+
}
1003+
rm, err := client.RegistryModules.CreateWithVCSConnection(ctx, options)
1004+
require.NoError(t, err)
1005+
assert.NotEmpty(t, rm.ID)
1006+
assert.Equal(t, registryModuleName, rm.Name)
1007+
assert.Equal(t, registryModuleProvider, rm.Provider)
1008+
assert.Equal(t, githubBranch, rm.VCSRepo.Branch)
1009+
assert.Equal(t, false, rm.VCSRepo.Tags)
1010+
assert.Equal(t, sourceDirectory, rm.VCSRepo.SourceDirectory)
1011+
})
1012+
}
1013+
1014+
func TestRegistryModulesCreateTagBasedWithVCSConnection(t *testing.T) {
1015+
skipUnlessBeta(t)
1016+
1017+
githubIdentifier := os.Getenv("GITHUB_REGISTRY_MODULE_IDENTIFIER")
1018+
if githubIdentifier == "" {
1019+
t.Skip("Export a valid GITHUB_REGISTRY_MODULE_IDENTIFIER before running this test")
1020+
}
1021+
repositoryName := strings.Split(githubIdentifier, "/")[1]
1022+
registryModuleProvider := strings.SplitN(repositoryName, "-", 3)[1]
1023+
registryModuleName := strings.SplitN(repositoryName, "-", 3)[2]
1024+
1025+
githubBranch := os.Getenv("GITHUB_REGISTRY_MODULE_BRANCH")
1026+
if githubBranch == "" {
1027+
githubBranch = "main"
1028+
}
1029+
1030+
client := testClient(t)
1031+
ctx := context.Background()
1032+
1033+
orgTest, orgTestCleanup := createOrganizationWithMonorepoSupport(t, client)
1034+
t.Cleanup(orgTestCleanup)
1035+
1036+
oauthTokenTest, oauthTokenTestCleanup := createOAuthToken(t, client, orgTest)
1037+
t.Cleanup(oauthTokenTestCleanup)
1038+
1039+
t.Run("with monorepo publishing", func(t *testing.T) {
1040+
sourceDirectory := "src"
1041+
tagPrefix := "v"
1042+
1043+
options := RegistryModuleCreateWithVCSConnectionOptions{
1044+
VCSRepo: &RegistryModuleVCSRepoOptions{
1045+
Identifier: String(githubIdentifier),
1046+
OAuthTokenID: String(oauthTokenTest.ID),
1047+
DisplayIdentifier: String(githubIdentifier),
1048+
Branch: String(githubBranch),
1049+
SourceDirectory: String(sourceDirectory),
1050+
TagPrefix: String(tagPrefix),
1051+
},
1052+
}
1053+
rm, err := client.RegistryModules.CreateWithVCSConnection(ctx, options)
1054+
require.NoError(t, err)
1055+
assert.NotEmpty(t, rm.ID)
1056+
assert.Equal(t, registryModuleName, rm.Name)
1057+
assert.Equal(t, registryModuleProvider, rm.Provider)
1058+
assert.Equal(t, rm.VCSRepo.Branch, githubBranch)
1059+
assert.Equal(t, rm.VCSRepo.Identifier, githubIdentifier)
1060+
assert.Equal(t, rm.VCSRepo.IngressSubmodules, true)
1061+
assert.Equal(t, rm.VCSRepo.OAuthTokenID, oauthTokenTest.ID)
1062+
assert.Equal(t, rm.VCSRepo.RepositoryHTTPURL, fmt.Sprintf("https://github.com/%s", githubIdentifier))
1063+
assert.Equal(t, rm.VCSRepo.ServiceProvider, string(ServiceProviderGithub))
1064+
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)
1065+
1066+
if rm.VCSRepo.SourceDirectory != sourceDirectory {
1067+
t.Errorf("expected SourceDirectory %q, got %q", sourceDirectory, rm.VCSRepo.SourceDirectory)
1068+
}
1069+
if rm.VCSRepo.TagPrefix != tagPrefix {
1070+
t.Errorf("expected TagPrefix %q, got %q", tagPrefix, rm.VCSRepo.TagPrefix)
1071+
}
1072+
})
1073+
1074+
t.Run("without monorepo publishing", func(t *testing.T) {
1075+
tagPrefix := "v"
1076+
1077+
options := RegistryModuleCreateWithVCSConnectionOptions{
1078+
VCSRepo: &RegistryModuleVCSRepoOptions{
1079+
Identifier: String(githubIdentifier),
1080+
OAuthTokenID: String(oauthTokenTest.ID),
1081+
DisplayIdentifier: String(githubIdentifier),
1082+
Branch: String(githubBranch),
1083+
TagPrefix: String(tagPrefix),
1084+
},
1085+
}
1086+
rm, err := client.RegistryModules.CreateWithVCSConnection(ctx, options)
1087+
require.NoError(t, err)
1088+
assert.NotEmpty(t, rm.ID)
1089+
assert.Equal(t, registryModuleName, rm.Name)
1090+
assert.Equal(t, registryModuleProvider, rm.Provider)
1091+
assert.Equal(t, rm.VCSRepo.Branch, githubBranch)
1092+
assert.Equal(t, rm.VCSRepo.Identifier, githubIdentifier)
1093+
assert.Equal(t, rm.VCSRepo.IngressSubmodules, true)
1094+
assert.Equal(t, rm.VCSRepo.OAuthTokenID, oauthTokenTest.ID)
1095+
assert.Equal(t, rm.VCSRepo.RepositoryHTTPURL, fmt.Sprintf("https://github.com/%s", githubIdentifier))
1096+
assert.Equal(t, rm.VCSRepo.ServiceProvider, string(ServiceProviderGithub))
1097+
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)
1098+
1099+
if rm.VCSRepo.SourceDirectory != "" {
1100+
t.Errorf("expected SourceDirectory %q, got %q", "", rm.VCSRepo.SourceDirectory)
1101+
}
1102+
if rm.VCSRepo.TagPrefix != tagPrefix {
1103+
t.Errorf("expected TagPrefix %q, got %q", tagPrefix, rm.VCSRepo.TagPrefix)
1104+
}
1105+
})
1106+
}
1107+
9651108
func TestRegistryModulesCreateBranchBasedWithVCSConnectionWithTesting(t *testing.T) {
9661109
skipUnlessBeta(t)
9671110

workspace.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ type VCSRepo struct {
273273
Tags bool `jsonapi:"attr,tags"`
274274
TagsRegex string `jsonapi:"attr,tags-regex"`
275275
WebhookURL string `jsonapi:"attr,webhook-url"`
276+
SourceDirectory string `jsonapi:"attr,source-directory"`
277+
TagPrefix string `jsonapi:"attr,tag-prefix"`
276278
}
277279

278280
// Note: the fields of this struct are bool pointers instead of bool values, in order to simplify support for

0 commit comments

Comments
 (0)