From a026c31824db55794b0beb68043af9b245c19080 Mon Sep 17 00:00:00 2001 From: Jonathan Niesen Date: Thu, 9 Aug 2018 15:48:59 -0400 Subject: [PATCH 01/13] support github enterprise by allowing custom api and base urls --- README.md | 8 ++++++++ github.go | 30 +++++++++++++++++------------- main.go | 18 ++++++++++++++++-- 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 45098da..be44a36 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,14 @@ Download the release asset `foo.exe` from a GitHub release where the tag is exac fetch --repo="https://github.com/foo/bar" --tag="0.1.5" --release-asset="foo.exe" /tmp ``` +#### Usage Example 7 + +Download the release asset `foo.exe` from a GitHub release hosted on a GitHub Enterprise instance running at `ghe.mycompany.com` where the tag is exactly `0.1.5`, and save it to `/tmp`: + +``` +fetch --repo="https://github.com/foo/bar" --tag="0.1.5" --release-asset="foo.exe" --github-base-url="ghe.mycompany.com" --github-api-url="ghe.mycompany.com/api/v3" /tmp +``` + ## License This code is released under the MIT License. See [LICENSE.txt](/LICENSE.txt). diff --git a/github.go b/github.go index 55e2de7..354e03d 100644 --- a/github.go +++ b/github.go @@ -11,10 +11,12 @@ import ( ) type GitHubRepo struct { - Url string // The URL of the GitHub repo - Owner string // The GitHub account name under which the repo exists - Name string // The GitHub repo name - Token string // The personal access token to access this repo (if it's a private repo) + Url string // The URL of the GitHub repo + BaseUrl string // The Base URL of the GitHub Instance + ApiUrl string // The API Url of the GitHub Instance + Owner string // The GitHub account name under which the repo exists + Name string // The GitHub repo name + Token string // The personal access token to access this repo (if it's a private repo) } // Represents a specific git commit. @@ -63,10 +65,10 @@ type GitHubReleaseAsset struct { } // Fetch all tags from the given GitHub repo -func FetchTags(githubRepoUrl string, githubToken string) ([]string, *FetchError) { +func FetchTags(githubRepoUrl string, githubBaseUrl string, githubApiUrl string, githubToken string) ([]string, *FetchError) { var tagsString []string - repo, err := ParseUrlIntoGitHubRepo(githubRepoUrl, githubToken) + repo, err := ParseUrlIntoGitHubRepo(githubRepoUrl, githubBaseUrl, githubApiUrl, githubToken) if err != nil { return tagsString, wrapError(err) } @@ -96,10 +98,10 @@ func FetchTags(githubRepoUrl string, githubToken string) ([]string, *FetchError) } // Convert a URL into a GitHubRepo struct -func ParseUrlIntoGitHubRepo(url string, token string) (GitHubRepo, *FetchError) { +func ParseUrlIntoGitHubRepo(url string, githubBaseUrl string, githubApiUrl string, token string) (GitHubRepo, *FetchError) { var gitHubRepo GitHubRepo - regex, regexErr := regexp.Compile("https?://(?:www\\.)?github.com/(.+?)/(.+?)(?:$|\\?|#|/)") + regex, regexErr := regexp.Compile("https?://(?:www\\.)?" + githubBaseUrl + "/(.+?)/(.+?)(?:$|\\?|#|/)") if regexErr != nil { return gitHubRepo, newError(GITHUB_REPO_URL_MALFORMED_OR_NOT_PARSEABLE, fmt.Sprintf("GitHub Repo URL %s is malformed.", url)) } @@ -110,10 +112,12 @@ func ParseUrlIntoGitHubRepo(url string, token string) (GitHubRepo, *FetchError) } gitHubRepo = GitHubRepo{ - Url: url, - Owner: matches[1], - Name: matches[2], - Token: token, + Url: url, + BaseUrl: githubBaseUrl, + ApiUrl: githubApiUrl, + Owner: matches[1], + Name: matches[2], + Token: token, } return gitHubRepo, nil @@ -161,7 +165,7 @@ func createGitHubRepoUrlForPath(repo GitHubRepo, path string) string { func callGitHubApi(repo GitHubRepo, path string, customHeaders map[string]string) (*http.Response, *FetchError) { httpClient := &http.Client{} - request, err := http.NewRequest("GET", fmt.Sprintf("https://api.github.com/%s", path), nil) + request, err := http.NewRequest("GET", fmt.Sprintf("https://" + repo.ApiUrl + "/%s", path), nil) if err != nil { return nil, wrapError(err) } diff --git a/main.go b/main.go index 4502e28..cc41e35 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,8 @@ type FetchOptions struct { ReleaseAssetChecksum string ReleaseAssetChecksumAlgo string LocalDownloadPath string + GithubBaseUrl string + GithubApiUrl string } const OPTION_REPO = "repo" @@ -34,6 +36,8 @@ const OPTION_SOURCE_PATH = "source-path" const OPTION_RELEASE_ASSET = "release-asset" const OPTION_RELEASE_ASSET_CHECKSUM = "release-asset-checksum" const OPTION_RELEASE_ASSET_CHECKSUM_ALGO = "release-asset-checksum-algo" +const OPTION_GITHUB_BASE_URL = "github-base-url" +const OPTION_GITHUB_API_URL = "github-api-url" const ENV_VAR_GITHUB_TOKEN = "GITHUB_OAUTH_TOKEN" @@ -82,6 +86,14 @@ func main() { Name: OPTION_RELEASE_ASSET_CHECKSUM_ALGO, Usage: "The algorithm Fetch will use to compute a checksum of the release asset. Acceptable values\n\tare \"sha256\" and \"sha512\".", }, + cli.StringFlag{ + Name: OPTION_GITHUB_BASE_URL, + Usage: "The base url of the GitHub instance. If left blank, github.com will be used.", + }, + cli.StringFlag{ + Name: OPTION_GITHUB_API_URL, + Usage: "The api url of the GitHub instance. If left blank, api.github.com will be used.", + }, } app.Action = runFetchWrapper @@ -107,7 +119,7 @@ func runFetch(c *cli.Context) error { } // Get the tags for the given repo - tags, fetchErr := FetchTags(options.RepoUrl, options.GithubToken) + tags, fetchErr := FetchTags(options.RepoUrl, options.GithubBaseUrl, options.GithubApiUrl, options.GithubToken) if fetchErr != nil { if fetchErr.errorCode == INVALID_GITHUB_TOKEN_OR_ACCESS_DENIED { return errors.New(getErrorMessage(INVALID_GITHUB_TOKEN_OR_ACCESS_DENIED, fetchErr.details)) @@ -133,7 +145,7 @@ func runFetch(c *cli.Context) error { } // Prepare the vars we'll need to download - repo, fetchErr := ParseUrlIntoGitHubRepo(options.RepoUrl, options.GithubToken) + repo, fetchErr := ParseUrlIntoGitHubRepo(options.RepoUrl, options.GithubBaseUrl, options.GithubApiUrl, options.GithubToken) if fetchErr != nil { return fmt.Errorf("Error occurred while parsing GitHub URL: %s", fetchErr) } @@ -188,6 +200,8 @@ func parseOptions(c *cli.Context) FetchOptions { ReleaseAssetChecksum: c.String(OPTION_RELEASE_ASSET_CHECKSUM), ReleaseAssetChecksumAlgo: c.String(OPTION_RELEASE_ASSET_CHECKSUM_ALGO), LocalDownloadPath: localDownloadPath, + GithubBaseUrl: c.String(OPTION_GITHUB_BASE_URL), + GithubApiUrl: c.String(OPTION_GITHUB_API_URL), } } From a7f5d55d099a8d0a673a4f9da6df79136b6ed613 Mon Sep 17 00:00:00 2001 From: Jonathan Niesen Date: Thu, 9 Aug 2018 16:00:40 -0400 Subject: [PATCH 02/13] fix example 7 in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index be44a36..2e0d306 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ fetch --repo="https://github.com/foo/bar" --tag="0.1.5" --release-asset="foo.exe Download the release asset `foo.exe` from a GitHub release hosted on a GitHub Enterprise instance running at `ghe.mycompany.com` where the tag is exactly `0.1.5`, and save it to `/tmp`: ``` -fetch --repo="https://github.com/foo/bar" --tag="0.1.5" --release-asset="foo.exe" --github-base-url="ghe.mycompany.com" --github-api-url="ghe.mycompany.com/api/v3" /tmp +fetch --repo="https://ghe.mycompany.com/foo/bar" --tag="0.1.5" --release-asset="foo.exe" --github-base-url="ghe.mycompany.com" --github-api-url="ghe.mycompany.com/api/v3" /tmp ``` ## License From 253ddf51cec6b281e519ef331ab45625cc1d65de Mon Sep 17 00:00:00 2001 From: Jonathan Niesen Date: Fri, 10 Aug 2018 07:32:47 -0400 Subject: [PATCH 03/13] update test messages so that format verbs match arg types --- github_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/github_test.go b/github_test.go index 6f33c9a..acc6c44 100644 --- a/github_test.go +++ b/github_test.go @@ -156,7 +156,7 @@ func TestGetGitHubReleaseInfo(t *testing.T) { } if !reflect.DeepEqual(tc.expected, resp) { - t.Fatalf("Expected GitHub release %s but got GitHub release %s", tc.expected, resp) + t.Fatalf("Expected GitHub release %v but got GitHub release %v", tc.expected, resp) } } } @@ -188,13 +188,13 @@ func TestDownloadReleaseAsset(t *testing.T) { } if err := DownloadReleaseAsset(repo, tc.assetId, tmpFile.Name()); err != nil { - t.Fatalf("Failed to download asset %s to %s from GitHub URL %s due to error: %s", tc.assetId, tmpFile.Name(), tc.repoUrl, err.Error()) + t.Fatalf("Failed to download asset %d to %s from GitHub URL %s due to error: %s", tc.assetId, tmpFile.Name(), tc.repoUrl, err.Error()) } defer os.Remove(tmpFile.Name()) if !fileExists(tmpFile.Name()) { - t.Fatalf("Got no errors downloading asset %s to %s from GitHub URL %s, but %s does not exist!", tc.assetId, tmpFile.Name(), tc.repoUrl, tmpFile.Name()) + t.Fatalf("Got no errors downloading asset %d to %s from GitHub URL %s, but %s does not exist!", tc.assetId, tmpFile.Name(), tc.repoUrl, tmpFile.Name()) } } } From a273c3850c30cee2cc9c81757ea50a30e5ffa3cf Mon Sep 17 00:00:00 2001 From: Jonathan Niesen Date: Fri, 10 Aug 2018 10:06:17 -0400 Subject: [PATCH 04/13] add a type to represent a github instance and track the various urls for it --- github.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/github.go b/github.go index 354e03d..5fcba2f 100644 --- a/github.go +++ b/github.go @@ -19,6 +19,11 @@ type GitHubRepo struct { Token string // The personal access token to access this repo (if it's a private repo) } +type GitHubInstance struct { + BaseUrl string + ApiUrl string +} + // Represents a specific git commit. // Note that code using GitHub Commit should respect the following hierarchy: // - CommitSha > BranchName > GitTag From 813a51277be07e17d2fcb54afa9076ba40cb8338 Mon Sep 17 00:00:00 2001 From: Jonathan Niesen Date: Fri, 10 Aug 2018 10:06:59 -0400 Subject: [PATCH 05/13] use the repo url to decipher github instance urls --- github.go | 28 ++++++++++++++++++++++++++++ github_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/github.go b/github.go index 5fcba2f..dc565b0 100644 --- a/github.go +++ b/github.go @@ -69,6 +69,34 @@ type GitHubReleaseAsset struct { Name string } +func ParseUrlIntoGithubInstance(url string, apiv string) (GitHubInstance, *FetchError) { + var instance GitHubInstance + + regex, regexErr := regexp.Compile("https?://(?:www\\.)?(.+?\\.com).*") + if regexErr != nil { + return instance, newError(GITHUB_REPO_URL_MALFORMED_OR_NOT_PARSEABLE, fmt.Sprintf("GitHub Repo URL %s is malformed.", url)) + } + + matches := regex.FindStringSubmatch(url) + if len(matches) != 2 { + return instance, newError(GITHUB_REPO_URL_MALFORMED_OR_NOT_PARSEABLE, fmt.Sprintf("GitHub Repo URL %s could not be parsed correctly", url)) + } + + baseUrl := matches[1] + apiUrl := "api.github.com" + if baseUrl != "github.com" && baseUrl != "www.github.com" { + fmt.Printf("Assuming GitHub Enterprise since the provided url (%s) does not appear to be for GitHub.com\n", url) + apiUrl = baseUrl + "/api/" + apiv + } + + instance = GitHubInstance{ + BaseUrl: baseUrl, + ApiUrl: apiUrl, + } + + return instance, nil +} + // Fetch all tags from the given GitHub repo func FetchTags(githubRepoUrl string, githubBaseUrl string, githubApiUrl string, githubToken string) ([]string, *FetchError) { var tagsString []string diff --git a/github_test.go b/github_test.go index acc6c44..a5eaf9b 100644 --- a/github_test.go +++ b/github_test.go @@ -47,6 +47,54 @@ func TestGetListOfReleasesFromGitHubRepo(t *testing.T) { } } +func TestParseUrlIntoGithubInstance(t *testing.T) { + t.Parallel() + + ghTestInst := GitHubInstance{ + BaseUrl: "github.com", + ApiUrl: "api.github.com", + } + gheTestInst := GitHubInstance{ + BaseUrl: "ghe.mycompany.com", + ApiUrl: "ghe.mycompany.com/api/v3", + } + myCoTestInst := GitHubInstance{ + BaseUrl: "mycogithub.com", + ApiUrl: "mycogithub.com/api/v3", + } + + cases := []struct { + repoUrl string + apiv string + expectedInst GitHubInstance + }{ + {"http://www.github.com/gruntwork-io/script-modules/", "", ghTestInst}, + {"https://www.github.com/gruntwork-io/script-modules/", "", ghTestInst}, + {"http://github.com/gruntwork-io/script-modules/", "", ghTestInst}, + {"http://www.ghe.mycompany.com/gruntwork-io/script-modules", "v3", gheTestInst}, + {"https://www.ghe.mycompany.com/gruntwork-io/script-modules", "v3", gheTestInst}, + {"http://ghe.mycompany.com/gruntwork-io/script-modules", "v3", gheTestInst}, + {"http://www.mycogithub.com/gruntwork-io/script-modules", "v3", myCoTestInst}, + {"https://www.mycogithub.com/gruntwork-io/script-modules", "v3", myCoTestInst}, + {"http://mycogithub.com/gruntwork-io/script-modules", "v3", myCoTestInst}, + } + + for _, tc := range cases { + inst, err := ParseUrlIntoGithubInstance(tc.repoUrl, tc.apiv) + if err != nil { + t.Fatalf("error extracting url %s into a GitHubRepo struct: %s", tc.repoUrl, err) + } + + if inst.BaseUrl != tc.expectedInst.BaseUrl { + t.Fatalf("while extracting %s, expected owner %s, received %s", tc.repoUrl, tc.expectedInst.BaseUrl, inst.BaseUrl) + } + + if inst.ApiUrl != tc.expectedInst.ApiUrl { + t.Fatalf("while extracting %s, expected name %s, received %s", tc.repoUrl, tc.expectedInst.ApiUrl, inst.ApiUrl) + } + } +} + func TestParseUrlIntoGitHubRepo(t *testing.T) { t.Parallel() From 0696ca712d3fe5c4c4ddf1259db23326fdc59cd9 Mon Sep 17 00:00:00 2001 From: Jonathan Niesen Date: Fri, 10 Aug 2018 10:42:37 -0400 Subject: [PATCH 06/13] update FetchTags and ParseUrlIntoGitHubRepo to take a GitHubInstance --- github.go | 12 ++++++------ main.go | 9 +++++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/github.go b/github.go index dc565b0..8da179a 100644 --- a/github.go +++ b/github.go @@ -98,10 +98,10 @@ func ParseUrlIntoGithubInstance(url string, apiv string) (GitHubInstance, *Fetch } // Fetch all tags from the given GitHub repo -func FetchTags(githubRepoUrl string, githubBaseUrl string, githubApiUrl string, githubToken string) ([]string, *FetchError) { +func FetchTags(githubRepoUrl string, githubToken string, instance GitHubInstance) ([]string, *FetchError) { var tagsString []string - repo, err := ParseUrlIntoGitHubRepo(githubRepoUrl, githubBaseUrl, githubApiUrl, githubToken) + repo, err := ParseUrlIntoGitHubRepo(githubRepoUrl, githubToken, instance) if err != nil { return tagsString, wrapError(err) } @@ -131,10 +131,10 @@ func FetchTags(githubRepoUrl string, githubBaseUrl string, githubApiUrl string, } // Convert a URL into a GitHubRepo struct -func ParseUrlIntoGitHubRepo(url string, githubBaseUrl string, githubApiUrl string, token string) (GitHubRepo, *FetchError) { +func ParseUrlIntoGitHubRepo(url string, token string, instance GitHubInstance) (GitHubRepo, *FetchError) { var gitHubRepo GitHubRepo - regex, regexErr := regexp.Compile("https?://(?:www\\.)?" + githubBaseUrl + "/(.+?)/(.+?)(?:$|\\?|#|/)") + regex, regexErr := regexp.Compile("https?://(?:www\\.)?" + instance.BaseUrl + "/(.+?)/(.+?)(?:$|\\?|#|/)") if regexErr != nil { return gitHubRepo, newError(GITHUB_REPO_URL_MALFORMED_OR_NOT_PARSEABLE, fmt.Sprintf("GitHub Repo URL %s is malformed.", url)) } @@ -146,8 +146,8 @@ func ParseUrlIntoGitHubRepo(url string, githubBaseUrl string, githubApiUrl strin gitHubRepo = GitHubRepo{ Url: url, - BaseUrl: githubBaseUrl, - ApiUrl: githubApiUrl, + BaseUrl: instance.BaseUrl, + ApiUrl: instance.ApiUrl, Owner: matches[1], Name: matches[2], Token: token, diff --git a/main.go b/main.go index cc41e35..ee8da43 100644 --- a/main.go +++ b/main.go @@ -118,8 +118,13 @@ func runFetch(c *cli.Context) error { return err } + instance, fetchErr := ParseUrlIntoGithubInstance(options.RepoUrl, options.GithubApiVersion) + if fetchErr != nil { + return fetchErr + } + // Get the tags for the given repo - tags, fetchErr := FetchTags(options.RepoUrl, options.GithubBaseUrl, options.GithubApiUrl, options.GithubToken) + tags, fetchErr := FetchTags(options.RepoUrl, options.GithubToken, instance) if fetchErr != nil { if fetchErr.errorCode == INVALID_GITHUB_TOKEN_OR_ACCESS_DENIED { return errors.New(getErrorMessage(INVALID_GITHUB_TOKEN_OR_ACCESS_DENIED, fetchErr.details)) @@ -145,7 +150,7 @@ func runFetch(c *cli.Context) error { } // Prepare the vars we'll need to download - repo, fetchErr := ParseUrlIntoGitHubRepo(options.RepoUrl, options.GithubBaseUrl, options.GithubApiUrl, options.GithubToken) + repo, fetchErr := ParseUrlIntoGitHubRepo(options.RepoUrl, options.GithubToken, instance) if fetchErr != nil { return fmt.Errorf("Error occurred while parsing GitHub URL: %s", fetchErr) } From 1b85ff7d5edad389e57b2544868eb02a502bb908 Mon Sep 17 00:00:00 2001 From: Jonathan Niesen Date: Fri, 10 Aug 2018 10:43:23 -0400 Subject: [PATCH 07/13] add the optional github-api-version flag --- main.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index ee8da43..f82d251 100644 --- a/main.go +++ b/main.go @@ -23,8 +23,7 @@ type FetchOptions struct { ReleaseAssetChecksum string ReleaseAssetChecksumAlgo string LocalDownloadPath string - GithubBaseUrl string - GithubApiUrl string + GithubApiVersion string } const OPTION_REPO = "repo" @@ -36,8 +35,7 @@ const OPTION_SOURCE_PATH = "source-path" const OPTION_RELEASE_ASSET = "release-asset" const OPTION_RELEASE_ASSET_CHECKSUM = "release-asset-checksum" const OPTION_RELEASE_ASSET_CHECKSUM_ALGO = "release-asset-checksum-algo" -const OPTION_GITHUB_BASE_URL = "github-base-url" -const OPTION_GITHUB_API_URL = "github-api-url" +const OPTION_GITHUB_API_VERSION = "github-api-version" const ENV_VAR_GITHUB_TOKEN = "GITHUB_OAUTH_TOKEN" @@ -87,12 +85,9 @@ func main() { Usage: "The algorithm Fetch will use to compute a checksum of the release asset. Acceptable values\n\tare \"sha256\" and \"sha512\".", }, cli.StringFlag{ - Name: OPTION_GITHUB_BASE_URL, - Usage: "The base url of the GitHub instance. If left blank, github.com will be used.", - }, - cli.StringFlag{ - Name: OPTION_GITHUB_API_URL, - Usage: "The api url of the GitHub instance. If left blank, api.github.com will be used.", + Name: OPTION_GITHUB_API_VERSION, + Value: "v3", + Usage: "The api version of the GitHub instance. If left blank, v3 will be used.\n\tThis will only be used if the repo url is not a github.com url.", }, } @@ -205,8 +200,7 @@ func parseOptions(c *cli.Context) FetchOptions { ReleaseAssetChecksum: c.String(OPTION_RELEASE_ASSET_CHECKSUM), ReleaseAssetChecksumAlgo: c.String(OPTION_RELEASE_ASSET_CHECKSUM_ALGO), LocalDownloadPath: localDownloadPath, - GithubBaseUrl: c.String(OPTION_GITHUB_BASE_URL), - GithubApiUrl: c.String(OPTION_GITHUB_API_URL), + GithubApiVersion: c.String(OPTION_GITHUB_API_VERSION), } } From 5d57f91c25f46684fe212c95ee600812b760288e Mon Sep 17 00:00:00 2001 From: Jonathan Niesen Date: Fri, 10 Aug 2018 10:43:46 -0400 Subject: [PATCH 08/13] update tests to work with GitHubInstance --- checksum_test.go | 6 +++- github_test.go | 71 +++++++++++++++++++++++++++++++++++------------- 2 files changed, 57 insertions(+), 20 deletions(-) diff --git a/checksum_test.go b/checksum_test.go index aa792ea..9154421 100644 --- a/checksum_test.go +++ b/checksum_test.go @@ -16,8 +16,12 @@ const SAMPLE_RELEASE_ASSET_CHECKSUM_SHA512="28d9e487c1001e3c28d915c9edd3ed37632f func TestVerifyReleaseAsset(t *testing.T) { tmpDir := mkTempDir(t) + testInst := GitHubInstance{ + BaseUrl: "github.com", + ApiUrl: "api.github.com", + } - githubRepo, err := ParseUrlIntoGitHubRepo(SAMPLE_RELEASE_ASSET_GITHUB_REPO_URL, "") + githubRepo, err := ParseUrlIntoGitHubRepo(SAMPLE_RELEASE_ASSET_GITHUB_REPO_URL, "", testInst) if err != nil { t.Fatalf("Failed to parse sample release asset GitHub URL into Fetch GitHubRepo struct: %s", err) } diff --git a/github_test.go b/github_test.go index a5eaf9b..57972ca 100644 --- a/github_test.go +++ b/github_test.go @@ -9,22 +9,27 @@ import ( func TestGetListOfReleasesFromGitHubRepo(t *testing.T) { t.Parallel() + testInst := GitHubInstance{ + BaseUrl: "github.com", + ApiUrl: "api.github.com", + } cases := []struct { repoUrl string firstReleaseTag string lastReleaseTag string gitHubOAuthToken string + testInst GitHubInstance }{ // Test on a public repo whose sole purpose is to be a test fixture for this tool - {"https://github.com/gruntwork-io/fetch-test-public", "v0.0.1", "v0.0.3", ""}, + {"https://github.com/gruntwork-io/fetch-test-public", "v0.0.1", "v0.0.3", "", testInst}, // Private repo equivalent - {"https://github.com/gruntwork-io/fetch-test-private", "v0.0.2", "v0.0.2", os.Getenv("GITHUB_OAUTH_TOKEN")}, + {"https://github.com/gruntwork-io/fetch-test-private", "v0.0.2", "v0.0.2", os.Getenv("GITHUB_OAUTH_TOKEN"), testInst}, } for _, tc := range cases { - releases, err := FetchTags(tc.repoUrl, tc.gitHubOAuthToken) + releases, err := FetchTags(tc.repoUrl, tc.gitHubOAuthToken, testInst) if err != nil { t.Fatalf("error fetching releases: %s", err) } @@ -97,25 +102,42 @@ func TestParseUrlIntoGithubInstance(t *testing.T) { func TestParseUrlIntoGitHubRepo(t *testing.T) { t.Parallel() + ghTestInst := GitHubInstance{ + BaseUrl: "github.com", + ApiUrl: "api.github.com", + } + gheTestInst := GitHubInstance{ + BaseUrl: "ghe.mycompany.com", + ApiUrl: "ghe.mycompany.com/api/v3", + } + myCoTestInst := GitHubInstance{ + BaseUrl: "mycogithub.com", + ApiUrl: "mycogithub.com/api/v3", + } cases := []struct { - repoUrl string - owner string - name string - token string + repoUrl string + owner string + name string + token string + testInst GitHubInstance }{ - {"https://github.com/brikis98/ping-play", "brikis98", "ping-play", ""}, - {"http://github.com/brikis98/ping-play", "brikis98", "ping-play", ""}, - {"https://github.com/gruntwork-io/script-modules", "gruntwork-io", "script-modules", ""}, - {"http://github.com/gruntwork-io/script-modules", "gruntwork-io", "script-modules", ""}, - {"http://www.github.com/gruntwork-io/script-modules", "gruntwork-io", "script-modules", ""}, - {"http://www.github.com/gruntwork-io/script-modules/", "gruntwork-io", "script-modules", ""}, - {"http://www.github.com/gruntwork-io/script-modules?foo=bar", "gruntwork-io", "script-modules", "token"}, - {"http://www.github.com/gruntwork-io/script-modules?foo=bar&foo=baz", "gruntwork-io", "script-modules", "token"}, + {"https://github.com/brikis98/ping-play", "brikis98", "ping-play", "", ghTestInst}, + {"http://github.com/brikis98/ping-play", "brikis98", "ping-play", "", ghTestInst}, + {"https://github.com/gruntwork-io/script-modules", "gruntwork-io", "script-modules", "", ghTestInst}, + {"http://github.com/gruntwork-io/script-modules", "gruntwork-io", "script-modules", "", ghTestInst}, + {"http://www.github.com/gruntwork-io/script-modules", "gruntwork-io", "script-modules", "", ghTestInst}, + {"http://www.github.com/gruntwork-io/script-modules/", "gruntwork-io", "script-modules", "", ghTestInst}, + {"http://www.github.com/gruntwork-io/script-modules?foo=bar", "gruntwork-io", "script-modules", "token", ghTestInst}, + {"http://www.github.com/gruntwork-io/script-modules?foo=bar&foo=baz", "gruntwork-io", "script-modules", "token", ghTestInst}, + {"http://www.ghe.mycompany.com/gruntwork-io/script-modules?foo=bar&foo=baz", "gruntwork-io", "script-modules", "token", gheTestInst}, + {"https://www.ghe.mycompany.com/gruntwork-io/script-modules?foo=bar&foo=baz", "gruntwork-io", "script-modules", "token", gheTestInst}, + {"http://ghe.mycompany.com/gruntwork-io/script-modules?foo=bar&foo=baz", "gruntwork-io", "script-modules", "token", gheTestInst}, + {"http://mycogithub.com/gruntwork-io/script-modules?foo=bar&foo=baz", "gruntwork-io", "script-modules", "token", myCoTestInst}, } for _, tc := range cases { - repo, err := ParseUrlIntoGitHubRepo(tc.repoUrl, tc.token) + repo, err := ParseUrlIntoGitHubRepo(tc.repoUrl, tc.token, tc.testInst) if err != nil { t.Fatalf("error extracting url %s into a GitHubRepo struct: %s", tc.repoUrl, err) } @@ -140,6 +162,7 @@ func TestParseUrlIntoGitHubRepo(t *testing.T) { func TestParseUrlThrowsErrorOnMalformedUrl(t *testing.T) { t.Parallel() + testInst := GitHubInstance{} cases := []struct { repoUrl string @@ -150,7 +173,7 @@ func TestParseUrlThrowsErrorOnMalformedUrl(t *testing.T) { } for _, tc := range cases { - _, err := ParseUrlIntoGitHubRepo(tc.repoUrl, "") + _, err := ParseUrlIntoGitHubRepo(tc.repoUrl, "", testInst) if err == nil { t.Fatalf("Expected error on malformed url %s, but no error was received.", tc.repoUrl) } @@ -182,6 +205,11 @@ func TestGetGitHubReleaseInfo(t *testing.T) { Assets: []GitHubReleaseAsset{}, } + testInst := GitHubInstance{ + BaseUrl: "github.com", + ApiUrl: "api.github.com", + } + cases := []struct { repoUrl string repoToken string @@ -193,7 +221,7 @@ func TestGetGitHubReleaseInfo(t *testing.T) { } for _, tc := range cases { - repo, err := ParseUrlIntoGitHubRepo(tc.repoUrl, tc.repoToken) + repo, err := ParseUrlIntoGitHubRepo(tc.repoUrl, tc.repoToken, testInst) if err != nil { t.Fatalf("Failed to parse %s into GitHub URL due to error: %s", tc.repoUrl, err.Error()) } @@ -214,6 +242,11 @@ func TestDownloadReleaseAsset(t *testing.T) { token := os.Getenv("GITHUB_OAUTH_TOKEN") + testInst := GitHubInstance{ + BaseUrl: "github.com", + ApiUrl: "api.github.com", + } + cases := []struct { repoUrl string repoToken string @@ -225,7 +258,7 @@ func TestDownloadReleaseAsset(t *testing.T) { } for _, tc := range cases { - repo, err := ParseUrlIntoGitHubRepo(tc.repoUrl, tc.repoToken) + repo, err := ParseUrlIntoGitHubRepo(tc.repoUrl, tc.repoToken, testInst) if err != nil { t.Fatalf("Failed to parse %s into GitHub URL due to error: %s", tc.repoUrl, err.Error()) } From d16a4315b215d7ef25e8ce97a1a3edcb9f0079dd Mon Sep 17 00:00:00 2001 From: Jonathan Niesen Date: Fri, 10 Aug 2018 10:59:52 -0400 Subject: [PATCH 09/13] update readme with github enterprise docs --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e0d306..7a14b4b 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ authentication. Fetch makes it possible to handle all of these cases with a one- - Download a binary asset from a specific release. - Verify the SHA256 or SHA512 checksum of a binary asset. - Download from public repos, or from private repos by specifying a [GitHub Personal Access Token](https://help.github.com/articles/creating-an-access-token-for-command-line-use/). +- Download from GitHub Enterprise. - When specifying a git tag, you can can specify either exactly the tag you want, or a [Tag Constraint Expression](#tag-constraint-expressions) to do things like "get the latest non-breaking version" of this repo. Note that fetch assumes git tags are specified according to [Semantic Versioning](http://semver.org/) principles. #### Quick examples @@ -75,6 +76,8 @@ The supported options are: downloading from private GitHub repos. **NOTE:** fetch will also look for this token using the `GITHUB_OAUTH_TOKEN` environment variable, which we recommend using instead of the command line option to ensure the token doesn't get saved in bash history. +- `--github-api-version` (**Optional**): The used when fetching an artifact from a GitHub Enterprise instance. + The default version is `v3`. This is ignored when fetching from GitHub.com. The supported arguments are: @@ -157,7 +160,7 @@ fetch --repo="https://github.com/foo/bar" --tag="0.1.5" --release-asset="foo.exe Download the release asset `foo.exe` from a GitHub release hosted on a GitHub Enterprise instance running at `ghe.mycompany.com` where the tag is exactly `0.1.5`, and save it to `/tmp`: ``` -fetch --repo="https://ghe.mycompany.com/foo/bar" --tag="0.1.5" --release-asset="foo.exe" --github-base-url="ghe.mycompany.com" --github-api-url="ghe.mycompany.com/api/v3" /tmp +fetch --repo="https://ghe.mycompany.com/foo/bar" --tag="0.1.5" --release-asset="foo.exe" /tmp ``` ## License From 2552ef0cf51fd149f30b92e8c745beb1fa44f74d Mon Sep 17 00:00:00 2001 From: Jonathan Niesen Date: Fri, 10 Aug 2018 19:56:58 -0400 Subject: [PATCH 10/13] rewording github-api-version docs --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7a14b4b..e242c2a 100644 --- a/README.md +++ b/README.md @@ -76,8 +76,8 @@ The supported options are: downloading from private GitHub repos. **NOTE:** fetch will also look for this token using the `GITHUB_OAUTH_TOKEN` environment variable, which we recommend using instead of the command line option to ensure the token doesn't get saved in bash history. -- `--github-api-version` (**Optional**): The used when fetching an artifact from a GitHub Enterprise instance. - The default version is `v3`. This is ignored when fetching from GitHub.com. +- `--github-api-version` (**Optional**): Used when fetching an artifact from a GitHub Enterprise instance. + Defaults to `v3`. This is ignored when fetching from GitHub.com. The supported arguments are: From 51acef1e8a638078a41fb9e18695c703c3532883 Mon Sep 17 00:00:00 2001 From: Jonathan Niesen Date: Fri, 10 Aug 2018 20:00:59 -0400 Subject: [PATCH 11/13] fix whitespace issues --- checksum_test.go | 8 ++-- github.go | 42 +++++++++---------- github_test.go | 102 +++++++++++++++++++++++------------------------ main.go | 10 ++--- 4 files changed, 81 insertions(+), 81 deletions(-) diff --git a/checksum_test.go b/checksum_test.go index 9154421..36e1011 100644 --- a/checksum_test.go +++ b/checksum_test.go @@ -16,10 +16,10 @@ const SAMPLE_RELEASE_ASSET_CHECKSUM_SHA512="28d9e487c1001e3c28d915c9edd3ed37632f func TestVerifyReleaseAsset(t *testing.T) { tmpDir := mkTempDir(t) - testInst := GitHubInstance{ - BaseUrl: "github.com", - ApiUrl: "api.github.com", - } + testInst := GitHubInstance{ + BaseUrl: "github.com", + ApiUrl: "api.github.com", + } githubRepo, err := ParseUrlIntoGitHubRepo(SAMPLE_RELEASE_ASSET_GITHUB_REPO_URL, "", testInst) if err != nil { diff --git a/github.go b/github.go index 8da179a..60cf49f 100644 --- a/github.go +++ b/github.go @@ -20,8 +20,8 @@ type GitHubRepo struct { } type GitHubInstance struct { - BaseUrl string - ApiUrl string + BaseUrl string + ApiUrl string } // Represents a specific git commit. @@ -70,31 +70,31 @@ type GitHubReleaseAsset struct { } func ParseUrlIntoGithubInstance(url string, apiv string) (GitHubInstance, *FetchError) { - var instance GitHubInstance + var instance GitHubInstance - regex, regexErr := regexp.Compile("https?://(?:www\\.)?(.+?\\.com).*") - if regexErr != nil { + regex, regexErr := regexp.Compile("https?://(?:www\\.)?(.+?\\.com).*") + if regexErr != nil { return instance, newError(GITHUB_REPO_URL_MALFORMED_OR_NOT_PARSEABLE, fmt.Sprintf("GitHub Repo URL %s is malformed.", url)) - } + } - matches := regex.FindStringSubmatch(url) - if len(matches) != 2 { + matches := regex.FindStringSubmatch(url) + if len(matches) != 2 { return instance, newError(GITHUB_REPO_URL_MALFORMED_OR_NOT_PARSEABLE, fmt.Sprintf("GitHub Repo URL %s could not be parsed correctly", url)) - } + } - baseUrl := matches[1] - apiUrl := "api.github.com" - if baseUrl != "github.com" && baseUrl != "www.github.com" { - fmt.Printf("Assuming GitHub Enterprise since the provided url (%s) does not appear to be for GitHub.com\n", url) - apiUrl = baseUrl + "/api/" + apiv - } + baseUrl := matches[1] + apiUrl := "api.github.com" + if baseUrl != "github.com" && baseUrl != "www.github.com" { + fmt.Printf("Assuming GitHub Enterprise since the provided url (%s) does not appear to be for GitHub.com\n", url) + apiUrl = baseUrl + "/api/" + apiv + } - instance = GitHubInstance{ - BaseUrl: baseUrl, - ApiUrl: apiUrl, - } + instance = GitHubInstance{ + BaseUrl: baseUrl, + ApiUrl: apiUrl, + } - return instance, nil + return instance, nil } // Fetch all tags from the given GitHub repo @@ -198,7 +198,7 @@ func createGitHubRepoUrlForPath(repo GitHubRepo, path string) string { func callGitHubApi(repo GitHubRepo, path string, customHeaders map[string]string) (*http.Response, *FetchError) { httpClient := &http.Client{} - request, err := http.NewRequest("GET", fmt.Sprintf("https://" + repo.ApiUrl + "/%s", path), nil) + request, err := http.NewRequest("GET", fmt.Sprintf("https://"+repo.ApiUrl+"/%s", path), nil) if err != nil { return nil, wrapError(err) } diff --git a/github_test.go b/github_test.go index 57972ca..26a1663 100644 --- a/github_test.go +++ b/github_test.go @@ -1,25 +1,25 @@ package main import ( - "testing" + "io/ioutil" "os" "reflect" - "io/ioutil" + "testing" ) func TestGetListOfReleasesFromGitHubRepo(t *testing.T) { t.Parallel() - testInst := GitHubInstance{ - BaseUrl: "github.com", - ApiUrl: "api.github.com", - } + testInst := GitHubInstance{ + BaseUrl: "github.com", + ApiUrl: "api.github.com", + } cases := []struct { repoUrl string firstReleaseTag string lastReleaseTag string gitHubOAuthToken string - testInst GitHubInstance + testInst GitHubInstance }{ // Test on a public repo whose sole purpose is to be a test fixture for this tool {"https://github.com/gruntwork-io/fetch-test-public", "v0.0.1", "v0.0.3", "", testInst}, @@ -53,26 +53,26 @@ func TestGetListOfReleasesFromGitHubRepo(t *testing.T) { } func TestParseUrlIntoGithubInstance(t *testing.T) { - t.Parallel() - - ghTestInst := GitHubInstance{ - BaseUrl: "github.com", - ApiUrl: "api.github.com", - } - gheTestInst := GitHubInstance{ - BaseUrl: "ghe.mycompany.com", - ApiUrl: "ghe.mycompany.com/api/v3", - } - myCoTestInst := GitHubInstance{ - BaseUrl: "mycogithub.com", - ApiUrl: "mycogithub.com/api/v3", - } - - cases := []struct { - repoUrl string - apiv string - expectedInst GitHubInstance - }{ + t.Parallel() + + ghTestInst := GitHubInstance{ + BaseUrl: "github.com", + ApiUrl: "api.github.com", + } + gheTestInst := GitHubInstance{ + BaseUrl: "ghe.mycompany.com", + ApiUrl: "ghe.mycompany.com/api/v3", + } + myCoTestInst := GitHubInstance{ + BaseUrl: "mycogithub.com", + ApiUrl: "mycogithub.com/api/v3", + } + + cases := []struct { + repoUrl string + apiv string + expectedInst GitHubInstance + }{ {"http://www.github.com/gruntwork-io/script-modules/", "", ghTestInst}, {"https://www.github.com/gruntwork-io/script-modules/", "", ghTestInst}, {"http://github.com/gruntwork-io/script-modules/", "", ghTestInst}, @@ -82,7 +82,7 @@ func TestParseUrlIntoGithubInstance(t *testing.T) { {"http://www.mycogithub.com/gruntwork-io/script-modules", "v3", myCoTestInst}, {"https://www.mycogithub.com/gruntwork-io/script-modules", "v3", myCoTestInst}, {"http://mycogithub.com/gruntwork-io/script-modules", "v3", myCoTestInst}, - } + } for _, tc := range cases { inst, err := ParseUrlIntoGithubInstance(tc.repoUrl, tc.apiv) @@ -97,30 +97,30 @@ func TestParseUrlIntoGithubInstance(t *testing.T) { if inst.ApiUrl != tc.expectedInst.ApiUrl { t.Fatalf("while extracting %s, expected name %s, received %s", tc.repoUrl, tc.expectedInst.ApiUrl, inst.ApiUrl) } - } + } } func TestParseUrlIntoGitHubRepo(t *testing.T) { t.Parallel() - ghTestInst := GitHubInstance{ - BaseUrl: "github.com", - ApiUrl: "api.github.com", - } - gheTestInst := GitHubInstance{ - BaseUrl: "ghe.mycompany.com", - ApiUrl: "ghe.mycompany.com/api/v3", - } - myCoTestInst := GitHubInstance{ - BaseUrl: "mycogithub.com", - ApiUrl: "mycogithub.com/api/v3", - } + ghTestInst := GitHubInstance{ + BaseUrl: "github.com", + ApiUrl: "api.github.com", + } + gheTestInst := GitHubInstance{ + BaseUrl: "ghe.mycompany.com", + ApiUrl: "ghe.mycompany.com/api/v3", + } + myCoTestInst := GitHubInstance{ + BaseUrl: "mycogithub.com", + ApiUrl: "mycogithub.com/api/v3", + } cases := []struct { repoUrl string owner string name string token string - testInst GitHubInstance + testInst GitHubInstance }{ {"https://github.com/brikis98/ping-play", "brikis98", "ping-play", "", ghTestInst}, {"http://github.com/brikis98/ping-play", "brikis98", "ping-play", "", ghTestInst}, @@ -162,7 +162,7 @@ func TestParseUrlIntoGitHubRepo(t *testing.T) { func TestParseUrlThrowsErrorOnMalformedUrl(t *testing.T) { t.Parallel() - testInst := GitHubInstance{} + testInst := GitHubInstance{} cases := []struct { repoUrl string @@ -205,10 +205,10 @@ func TestGetGitHubReleaseInfo(t *testing.T) { Assets: []GitHubReleaseAsset{}, } - testInst := GitHubInstance{ - BaseUrl: "github.com", - ApiUrl: "api.github.com", - } + testInst := GitHubInstance{ + BaseUrl: "github.com", + ApiUrl: "api.github.com", + } cases := []struct { repoUrl string @@ -242,10 +242,10 @@ func TestDownloadReleaseAsset(t *testing.T) { token := os.Getenv("GITHUB_OAUTH_TOKEN") - testInst := GitHubInstance{ - BaseUrl: "github.com", - ApiUrl: "api.github.com", - } + testInst := GitHubInstance{ + BaseUrl: "github.com", + ApiUrl: "api.github.com", + } cases := []struct { repoUrl string diff --git a/main.go b/main.go index f82d251..450310d 100644 --- a/main.go +++ b/main.go @@ -86,7 +86,7 @@ func main() { }, cli.StringFlag{ Name: OPTION_GITHUB_API_VERSION, - Value: "v3", + Value: "v3", Usage: "The api version of the GitHub instance. If left blank, v3 will be used.\n\tThis will only be used if the repo url is not a github.com url.", }, } @@ -113,10 +113,10 @@ func runFetch(c *cli.Context) error { return err } - instance, fetchErr := ParseUrlIntoGithubInstance(options.RepoUrl, options.GithubApiVersion) - if fetchErr != nil { - return fetchErr - } + instance, fetchErr := ParseUrlIntoGithubInstance(options.RepoUrl, options.GithubApiVersion) + if fetchErr != nil { + return fetchErr + } // Get the tags for the given repo tags, fetchErr := FetchTags(options.RepoUrl, options.GithubToken, instance) From 18c0bca337f8f03f8f8f147f82ff205fc59c974e Mon Sep 17 00:00:00 2001 From: Jonathan Niesen Date: Fri, 10 Aug 2018 20:22:35 -0400 Subject: [PATCH 12/13] use url.Parse to cover additional use cases; update tests --- github.go | 26 +++++++++++--------------- github_test.go | 34 ++++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/github.go b/github.go index 60cf49f..5e1bfc3 100644 --- a/github.go +++ b/github.go @@ -1,13 +1,14 @@ package main import ( - "net/http" - "fmt" "bytes" "encoding/json" - "regexp" - "os" + "fmt" "io" + "net/http" + "net/url" + "os" + "regexp" ) type GitHubRepo struct { @@ -69,23 +70,18 @@ type GitHubReleaseAsset struct { Name string } -func ParseUrlIntoGithubInstance(url string, apiv string) (GitHubInstance, *FetchError) { +func ParseUrlIntoGithubInstance(repoUrl string, apiv string) (GitHubInstance, *FetchError) { var instance GitHubInstance - regex, regexErr := regexp.Compile("https?://(?:www\\.)?(.+?\\.com).*") - if regexErr != nil { - return instance, newError(GITHUB_REPO_URL_MALFORMED_OR_NOT_PARSEABLE, fmt.Sprintf("GitHub Repo URL %s is malformed.", url)) - } - - matches := regex.FindStringSubmatch(url) - if len(matches) != 2 { - return instance, newError(GITHUB_REPO_URL_MALFORMED_OR_NOT_PARSEABLE, fmt.Sprintf("GitHub Repo URL %s could not be parsed correctly", url)) + u, err := url.Parse(repoUrl) + if err != nil { + return instance, newError(GITHUB_REPO_URL_MALFORMED_OR_NOT_PARSEABLE, fmt.Sprintf("GitHub Repo URL %s is malformed.", repoUrl)) } - baseUrl := matches[1] + baseUrl := u.Host apiUrl := "api.github.com" if baseUrl != "github.com" && baseUrl != "www.github.com" { - fmt.Printf("Assuming GitHub Enterprise since the provided url (%s) does not appear to be for GitHub.com\n", url) + fmt.Printf("Assuming GitHub Enterprise since the provided url (%s) does not appear to be for GitHub.com\n", repoUrl) apiUrl = baseUrl + "/api/" + apiv } diff --git a/github_test.go b/github_test.go index 26a1663..3b1ef93 100644 --- a/github_test.go +++ b/github_test.go @@ -59,29 +59,51 @@ func TestParseUrlIntoGithubInstance(t *testing.T) { BaseUrl: "github.com", ApiUrl: "api.github.com", } + wwwGhTestInst := GitHubInstance{ + BaseUrl: "www.github.com", + ApiUrl: "api.github.com", + } gheTestInst := GitHubInstance{ BaseUrl: "ghe.mycompany.com", ApiUrl: "ghe.mycompany.com/api/v3", } + wwwGheTestInst := GitHubInstance{ + BaseUrl: "www.ghe.mycompany.com", + ApiUrl: "www.ghe.mycompany.com/api/v3", + } myCoTestInst := GitHubInstance{ BaseUrl: "mycogithub.com", ApiUrl: "mycogithub.com/api/v3", } + wwwMyCoTestInst := GitHubInstance{ + BaseUrl: "www.mycogithub.com", + ApiUrl: "www.mycogithub.com/api/v3", + } + localTestInst := GitHubInstance{ + BaseUrl: "mycogithub.local", + ApiUrl: "mycogithub.local/api/v3", + } + netTestInst := GitHubInstance{ + BaseUrl: "mycogithub.net", + ApiUrl: "mycogithub.net/api/v3", + } cases := []struct { repoUrl string apiv string expectedInst GitHubInstance }{ - {"http://www.github.com/gruntwork-io/script-modules/", "", ghTestInst}, - {"https://www.github.com/gruntwork-io/script-modules/", "", ghTestInst}, + {"http://www.github.com/gruntwork-io/script-modules/", "", wwwGhTestInst}, + {"https://www.github.com/gruntwork-io/script-modules/", "", wwwGhTestInst}, {"http://github.com/gruntwork-io/script-modules/", "", ghTestInst}, - {"http://www.ghe.mycompany.com/gruntwork-io/script-modules", "v3", gheTestInst}, - {"https://www.ghe.mycompany.com/gruntwork-io/script-modules", "v3", gheTestInst}, + {"http://www.ghe.mycompany.com/gruntwork-io/script-modules", "v3", wwwGheTestInst}, + {"https://www.ghe.mycompany.com/gruntwork-io/script-modules", "v3", wwwGheTestInst}, {"http://ghe.mycompany.com/gruntwork-io/script-modules", "v3", gheTestInst}, - {"http://www.mycogithub.com/gruntwork-io/script-modules", "v3", myCoTestInst}, - {"https://www.mycogithub.com/gruntwork-io/script-modules", "v3", myCoTestInst}, + {"http://www.mycogithub.com/gruntwork-io/script-modules", "v3", wwwMyCoTestInst}, + {"https://www.mycogithub.com/gruntwork-io/script-modules", "v3", wwwMyCoTestInst}, {"http://mycogithub.com/gruntwork-io/script-modules", "v3", myCoTestInst}, + {"http://mycogithub.local/gruntwork-io/script-modules", "v3", localTestInst}, + {"http://mycogithub.net/gruntwork-io/script-modules", "v3", netTestInst}, } for _, tc := range cases { From bb810bf3481c1140673b2cb69eae25d0c074c03c Mon Sep 17 00:00:00 2001 From: Jonathan Niesen Date: Fri, 10 Aug 2018 20:23:27 -0400 Subject: [PATCH 13/13] update failing test messages to match what is being tested --- github_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github_test.go b/github_test.go index 3b1ef93..127d9c6 100644 --- a/github_test.go +++ b/github_test.go @@ -113,11 +113,11 @@ func TestParseUrlIntoGithubInstance(t *testing.T) { } if inst.BaseUrl != tc.expectedInst.BaseUrl { - t.Fatalf("while extracting %s, expected owner %s, received %s", tc.repoUrl, tc.expectedInst.BaseUrl, inst.BaseUrl) + t.Fatalf("while parsing %s, expected base url %s, received %s", tc.repoUrl, tc.expectedInst.BaseUrl, inst.BaseUrl) } if inst.ApiUrl != tc.expectedInst.ApiUrl { - t.Fatalf("while extracting %s, expected name %s, received %s", tc.repoUrl, tc.expectedInst.ApiUrl, inst.ApiUrl) + t.Fatalf("while parsing %s, expected api url %s, received %s", tc.repoUrl, tc.expectedInst.ApiUrl, inst.ApiUrl) } } }