Skip to content

Commit 92449fd

Browse files
isometrykfcampbell
andauthored
fix: support repository autolink references on non-default ports (#1552)
Resolves #1551 Co-authored-by: Keegan Campbell <[email protected]>
1 parent bd36a1f commit 92449fd

2 files changed

+55
-14
lines changed

github/resource_github_repository_autolink_reference.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func resourceGithubRepositoryAutolinkReference() *schema.Resource {
5151
Required: true,
5252
ForceNew: true,
5353
Description: "The template of the target URL used for the links; must be a valid URL and contain `<num>` for the reference number",
54-
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^http[s]?:\/\/[a-z0-9-.]*\/.*?<num>.*?$`), "must be a valid URL and contain <num> token"),
54+
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^http[s]?:\/\/[a-z0-9-.]*(:[0-9]+)?\/.*?<num>.*?$`), "must be a valid URL and contain <num> token"),
5555
},
5656
"is_alphanumeric": {
5757
Type: schema.TypeBool,

github/resource_github_repository_autolink_reference_test.go

+54-13
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,39 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) {
1616

1717
config := fmt.Sprintf(`
1818
resource "github_repository" "test" {
19-
name = "test-%s"
20-
description = "Test autolink creation"
19+
name = "test-%s"
20+
description = "Test autolink creation"
2121
}
2222
2323
resource "github_repository_autolink_reference" "autolink_default" {
2424
repository = github_repository.test.name
2525
26-
key_prefix = "TEST1-"
26+
key_prefix = "TEST1-"
2727
target_url_template = "https://example.com/TEST-<num>"
2828
}
2929
3030
resource "github_repository_autolink_reference" "autolink_alphanumeric" {
3131
repository = github_repository.test.name
3232
33-
key_prefix = "TEST2-"
33+
key_prefix = "TEST2-"
3434
target_url_template = "https://example.com/TEST-<num>"
3535
is_alphanumeric = true
3636
}
3737
3838
resource "github_repository_autolink_reference" "autolink_numeric" {
3939
repository = github_repository.test.name
4040
41-
key_prefix = "TEST3-"
41+
key_prefix = "TEST3-"
4242
target_url_template = "https://example.com/TEST-<num>"
4343
is_alphanumeric = false
4444
}
45+
46+
resource "github_repository_autolink_reference" "autolink_with_port" {
47+
repository = github_repository.test.name
48+
49+
key_prefix = "TEST4-"
50+
target_url_template = "https://example.com:8443/TEST-<num>"
51+
}
4552
`, randomID)
4653

4754
check := resource.ComposeTestCheckFunc(
@@ -75,6 +82,16 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) {
7582
resource.TestCheckResourceAttr(
7683
"github_repository_autolink_reference.autolink_numeric", "is_alphanumeric", "false",
7784
),
85+
// autolink_with_port
86+
resource.TestCheckResourceAttr(
87+
"github_repository_autolink_reference.autolink_with_port", "key_prefix", "TEST4-",
88+
),
89+
resource.TestCheckResourceAttr(
90+
"github_repository_autolink_reference.autolink_with_port", "target_url_template", "https://example.com:8443/TEST-<num>",
91+
),
92+
resource.TestCheckResourceAttr(
93+
"github_repository_autolink_reference.autolink_with_port", "is_alphanumeric", "true",
94+
),
7895
)
7996

8097
testCase := func(t *testing.T, mode string) {
@@ -108,32 +125,39 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) {
108125

109126
config := fmt.Sprintf(`
110127
resource "github_repository" "test" {
111-
name = "test-%s"
112-
description = "Test autolink creation"
128+
name = "test-%s"
129+
description = "Test autolink creation"
113130
}
114131
115132
resource "github_repository_autolink_reference" "autolink_default" {
116133
repository = github_repository.test.name
117134
118-
key_prefix = "TEST1-"
135+
key_prefix = "TEST1-"
119136
target_url_template = "https://example.com/TEST-<num>"
120137
}
121138
122139
resource "github_repository_autolink_reference" "autolink_alphanumeric" {
123140
repository = github_repository.test.name
124141
125-
key_prefix = "TEST2-"
142+
key_prefix = "TEST2-"
126143
target_url_template = "https://example.com/TEST-<num>"
127144
is_alphanumeric = true
128145
}
129146
130147
resource "github_repository_autolink_reference" "autolink_numeric" {
131148
repository = github_repository.test.name
132149
133-
key_prefix = "TEST3-"
150+
key_prefix = "TEST3-"
134151
target_url_template = "https://example.com/TEST-<num>"
135152
is_alphanumeric = false
136153
}
154+
155+
resource "github_repository_autolink_reference" "autolink_with_port" {
156+
repository = github_repository.test.name
157+
158+
key_prefix = "TEST4-"
159+
target_url_template = "https://example.com:8443/TEST-<num>"
160+
}
137161
`, randomID)
138162

139163
check := resource.ComposeTestCheckFunc(
@@ -167,6 +191,16 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) {
167191
resource.TestCheckResourceAttr(
168192
"github_repository_autolink_reference.autolink_numeric", "is_alphanumeric", "false",
169193
),
194+
// autolink_with_port
195+
resource.TestCheckResourceAttr(
196+
"github_repository_autolink_reference.autolink_with_port", "key_prefix", "TEST4-",
197+
),
198+
resource.TestCheckResourceAttr(
199+
"github_repository_autolink_reference.autolink_with_port", "target_url_template", "https://example.com:8443/TEST-<num>",
200+
),
201+
resource.TestCheckResourceAttr(
202+
"github_repository_autolink_reference.autolink_with_port", "is_alphanumeric", "true",
203+
),
170204
)
171205

172206
testCase := func(t *testing.T, mode string) {
@@ -199,6 +233,13 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) {
199233
ImportStateVerify: true,
200234
ImportStateIdPrefix: fmt.Sprintf("test-%s/", randomID),
201235
},
236+
// autolink_with_port
237+
{
238+
ResourceName: "github_repository_autolink_reference.autolink_with_port",
239+
ImportState: true,
240+
ImportStateVerify: true,
241+
ImportStateIdPrefix: fmt.Sprintf("test-%s/", randomID),
242+
},
202243
},
203244
})
204245
}
@@ -221,14 +262,14 @@ func TestAccGithubRepositoryAutolinkReference(t *testing.T) {
221262

222263
config := fmt.Sprintf(`
223264
resource "github_repository" "test" {
224-
name = "test-%s"
225-
description = "Test autolink creation"
265+
name = "test-%s"
266+
description = "Test autolink creation"
226267
}
227268
228269
resource "github_repository_autolink_reference" "autolink_default" {
229270
repository = github_repository.test.name
230271
231-
key_prefix = "TEST1-"
272+
key_prefix = "TEST1-"
232273
target_url_template = "https://example.com/TEST-<num>"
233274
}
234275
`, randomID)

0 commit comments

Comments
 (0)