From 66a8977a8c3789403b01d395f8af770da7125456 Mon Sep 17 00:00:00 2001 From: aliculPix4D Date: Thu, 26 Oct 2023 16:32:51 +0200 Subject: [PATCH] cogito: don't hardcode Github domain name --- cmd/cogito/main_test.go | 4 ++-- cogito/putter.go | 6 +++--- cogito/putter_private_test.go | 22 +++++++++++----------- testhelp/testhelper.go | 12 ++++++------ 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/cmd/cogito/main_test.go b/cmd/cogito/main_test.go index 5a259560..56ebe77c 100644 --- a/cmd/cogito/main_test.go +++ b/cmd/cogito/main_test.go @@ -80,7 +80,7 @@ func TestRunPutSuccess(t *testing.T) { var out bytes.Buffer var logOut bytes.Buffer inputDir := testhelp.MakeGitRepoFromTestdata(t, "../../cogito/testdata/one-repo/a-repo", - testhelp.HttpsRemote("the-owner", "the-repo"), "dummySHA", wantGitRef) + testhelp.HttpsRemote("github.com", "the-owner", "the-repo"), "dummySHA", wantGitRef) t.Setenv("COGITO_GITHUB_API", gitHubSpy.URL) err := mainErr(in, &out, &logOut, []string{"out", inputDir}) @@ -115,7 +115,7 @@ func TestRunPutSuccessIntegration(t *testing.T) { var out bytes.Buffer var logOut bytes.Buffer inputDir := testhelp.MakeGitRepoFromTestdata(t, "../../cogito/testdata/one-repo/a-repo", - testhelp.HttpsRemote(gitHubCfg.Owner, gitHubCfg.Repo), gitHubCfg.SHA, + testhelp.HttpsRemote("github.com", gitHubCfg.Owner, gitHubCfg.Repo), gitHubCfg.SHA, "ref: refs/heads/a-branch-FIXME") t.Setenv("BUILD_JOB_NAME", "TestRunPutSuccessIntegration") t.Setenv("ATC_EXTERNAL_URL", "https://cogito.invalid") diff --git a/cogito/putter.go b/cogito/putter.go index ad9ef048..47aacae2 100644 --- a/cogito/putter.go +++ b/cogito/putter.go @@ -270,13 +270,13 @@ func checkGitRepoDir(dir, owner, repo string) error { return fmt.Errorf(`the received git repository is incompatible with the Cogito configuration. Git repository configuration (received as 'inputs:' in this PUT step): - url: %s + url: %s owner: %s - repo: %s + repo: %s Cogito SOURCE configuration: owner: %s - repo: %s`, + repo: %s`, gitUrl, gu.Owner, gu.Repo, owner, repo) } diff --git a/cogito/putter_private_test.go b/cogito/putter_private_test.go index 36991f6b..0abc3738 100644 --- a/cogito/putter_private_test.go +++ b/cogito/putter_private_test.go @@ -82,17 +82,17 @@ func TestCheckGitRepoDirSuccess(t *testing.T) { { name: "repo with good SSH remote", dir: "testdata/one-repo/a-repo", - repoURL: testhelp.SshRemote(wantOwner, wantRepo), + repoURL: testhelp.SshRemote("github.com", wantOwner, wantRepo), }, { name: "repo with good HTTPS remote", dir: "testdata/one-repo/a-repo", - repoURL: testhelp.HttpsRemote(wantOwner, wantRepo), + repoURL: testhelp.HttpsRemote("github.com", wantOwner, wantRepo), }, { name: "repo with good HTTP remote", dir: "testdata/one-repo/a-repo", - repoURL: testhelp.HttpRemote(wantOwner, wantRepo), + repoURL: testhelp.HttpRemote("github.com", wantOwner, wantRepo), }, { name: "PR resource but with basic auth in URL (see PR #46)", @@ -143,32 +143,32 @@ func TestCheckGitRepoDirFailure(t *testing.T) { { name: "repo with unrelated HTTPS remote", dir: "testdata/one-repo/a-repo", - repoURL: testhelp.HttpsRemote("owner-a", "repo-a"), + repoURL: testhelp.HttpsRemote("github.com", "owner-a", "repo-a"), wantErrWild: `the received git repository is incompatible with the Cogito configuration. Git repository configuration (received as 'inputs:' in this PUT step): - url: https://github.com/owner-a/repo-a.git + url: https://github.com/owner-a/repo-a.git owner: owner-a - repo: repo-a + repo: repo-a Cogito SOURCE configuration: owner: smiling - repo: butterfly`, + repo: butterfly`, }, { name: "repo with unrelated SSH remote or wrong source config", dir: "testdata/one-repo/a-repo", - repoURL: testhelp.SshRemote("owner-a", "repo-a"), + repoURL: testhelp.SshRemote("github.com", "owner-a", "repo-a"), wantErrWild: `the received git repository is incompatible with the Cogito configuration. Git repository configuration (received as 'inputs:' in this PUT step): - url: git@github.com:owner-a/repo-a.git + url: git@github.com:owner-a/repo-a.git owner: owner-a - repo: repo-a + repo: repo-a Cogito SOURCE configuration: owner: smiling - repo: butterfly`, + repo: butterfly`, }, { name: "invalid git pseudo URL in .git/config", diff --git a/testhelp/testhelper.go b/testhelp/testhelper.go index 4849558a..a5cc70f8 100644 --- a/testhelp/testhelper.go +++ b/testhelp/testhelper.go @@ -247,18 +247,18 @@ func MakeGitRepoFromTestdata( } // SshRemote returns a GitHub SSH URL -func SshRemote(owner, repo string) string { - return fmt.Sprintf("git@github.com:%s/%s.git", owner, repo) +func SshRemote(domain, owner, repo string) string { + return fmt.Sprintf("git@%s:%s/%s.git", domain, owner, repo) } // HttpsRemote returns a GitHub HTTPS URL -func HttpsRemote(owner, repo string) string { - return fmt.Sprintf("https://github.com/%s/%s.git", owner, repo) +func HttpsRemote(domain, owner, repo string) string { + return fmt.Sprintf("https://%s/%s/%s.git", domain, owner, repo) } // HttpRemote returns a GitHub HTTP URL -func HttpRemote(owner, repo string) string { - return fmt.Sprintf("http://github.com/%s/%s.git", owner, repo) +func HttpRemote(domain, owner, repo string) string { + return fmt.Sprintf("http://%s/%s/%s.git", domain, owner, repo) } // ToJSON returns the JSON encoding of thing.