Skip to content

Commit debfc8c

Browse files
authored
fix: removing .git from inside git template urls (#103)
* test: fix tests to run offline without a network connection * refactor: serves me right for resolving conflicts in the GitHub Editor * fix: removing .git from inside git template urls * refactor: remove unused slackdeps/http
1 parent 4406cb0 commit debfc8c

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

internal/pkg/create/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ func InstallProjectDependencies(
524524

525525
// generateGitZipFileURL will return the GitHub zip URL for a templateURL.
526526
func generateGitZipFileURL(httpClient slackhttp.HTTPClient, templateURL string, gitBranch string) string {
527-
zipURL := strings.ReplaceAll(templateURL, ".git", "") + "/archive/refs/heads/"
527+
zipURL := strings.TrimSuffix(templateURL, ".git") + "/archive/refs/heads/"
528528

529529
if gitBranch == "" {
530530
mainURL := zipURL + "main.zip"

internal/pkg/create/create_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,24 @@ func Test_generateGitZipFileURL(t *testing.T) {
128128
httpClientMock.On("Get", mock.Anything).Return(nil, fmt.Errorf("HTTPClient error"))
129129
},
130130
},
131+
"Returns the zip URL with .git suffix removed": {
132+
templateURL: "https://github.com/slack-samples/deno-starter-template.git",
133+
gitBranch: "",
134+
expectedURL: "https://github.com/slack-samples/deno-starter-template/archive/refs/heads/main.zip",
135+
setupHTTPClientMock: func(httpClientMock *slackhttp.HTTPClientMock) {
136+
res := slackhttp.MockHTTPResponse(http.StatusOK, "OK")
137+
httpClientMock.On("Get", mock.Anything).Return(res, nil)
138+
},
139+
},
140+
"Returns the zip URL with .git inside URL preserved": {
141+
templateURL: "https://github.com/slack-samples/deno.git-starter-template",
142+
gitBranch: "",
143+
expectedURL: "https://github.com/slack-samples/deno.git-starter-template/archive/refs/heads/main.zip",
144+
setupHTTPClientMock: func(httpClientMock *slackhttp.HTTPClientMock) {
145+
res := slackhttp.MockHTTPResponse(http.StatusOK, "OK")
146+
httpClientMock.On("Get", mock.Anything).Return(res, nil)
147+
},
148+
},
131149
}
132150
for name, tt := range tests {
133151
t.Run(name, func(t *testing.T) {

0 commit comments

Comments
 (0)