forked from drone/go-scm
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
so that Create() and Fork() return the clone URL and add some more tests
- Loading branch information
Showing
6 changed files
with
134 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package fake | ||
|
||
import ( | ||
"context" | ||
"github.com/jenkins-x/go-scm/scm" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
// AssertRepoExists asserts that the repository exists | ||
func AssertRepoExists(t *testing.T, ctx context.Context, client *scm.Client, repo string) *scm.Repository { | ||
require.NotEmpty(t, repo, "no repository name") | ||
require.NotNil(t, client, "no scm client") | ||
require.NotNil(t, client.Repositories, "scm client does not support Repositories") | ||
|
||
repository, _, err := client.Repositories.Find(ctx, repo) | ||
|
||
if err != nil && scm.IsScmNotFound(err) { | ||
err = nil | ||
} | ||
require.NoError(t, err, "failed to find repo %s", repo) | ||
require.NotNil(t, repository, "no repository returned for %s", repo) | ||
return repository | ||
} | ||
|
||
// AssertNoRepoExists asserts that the repository does not exist | ||
func AssertNoRepoExists(t *testing.T, ctx context.Context, client *scm.Client, repo string) { | ||
require.NotEmpty(t, repo, "no repository name") | ||
require.NotNil(t, client, "no scm client") | ||
require.NotNil(t, client.Repositories, "scm client does not support Repositories") | ||
|
||
_, _, err := client.Repositories.Find(ctx, repo) | ||
require.Error(t, err, "expected not found error when looking up repo %s", repo) | ||
require.True(t, scm.IsScmNotFound(err), "should have returned an is not found error for repo %s", repo) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/jenkins-x/go-scm/scm" | ||
"os" | ||
|
||
"github.com/jenkins-x/go-scm/scm/factory" | ||
"github.com/jenkins-x/go-scm/scm/factory/examples/helpers" | ||
) | ||
|
||
func main() { | ||
args := os.Args | ||
if len(args) == 1 { | ||
fmt.Printf("usage: repoName") | ||
return | ||
} | ||
|
||
client, err := factory.NewClientFromEnvironment() | ||
if err != nil { | ||
helpers.Fail(err) | ||
return | ||
} | ||
ctx := context.Background() | ||
|
||
name := args[1] | ||
fmt.Printf("finding repository %s\n", name) | ||
|
||
repo, _, err := client.Repositories.Find(ctx, name) | ||
if scm.IsScmNotFound(err) { | ||
fmt.Printf("not found\n") | ||
return | ||
} | ||
if err != nil { | ||
fmt.Printf("failed: %s\n", err.Error()) | ||
return | ||
} | ||
fmt.Printf("found %#v\n", repo) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters