From d0b4ba1c505b0d40741a7e5ecc2fb69c04385068 Mon Sep 17 00:00:00 2001 From: Max Knee Date: Mon, 8 Jul 2024 12:09:11 -0400 Subject: [PATCH] adding async option Signed-off-by: Max Knee --- drone/client.go | 13 ++++++++++++- drone/client_test.go | 4 +--- drone/interface.go | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/drone/client.go b/drone/client.go index c9657fe..864dfa7 100644 --- a/drone/client.go +++ b/drone/client.go @@ -88,6 +88,14 @@ func encodeListOptions(opts ListOptions) string { return params.Encode() } +func asyncOpt(hasAsync bool) string { + params := url.Values{} + if hasAsync { + params.Set("async", "true") + } + return params.Encode() +} + // New returns a client at the specified url. func New(uri string) Client { return &client{http.DefaultClient, strings.TrimSuffix(uri, "/")} @@ -190,9 +198,12 @@ func (c *client) RepoList() ([]*Repo, error) { // RepoListSync returns a list of all repositories to which // the user has explicit access in the host system. -func (c *client) RepoListSync() ([]*Repo, error) { +func (c *client) RepoListSync(hasAsync bool) ([]*Repo, error) { var out []*Repo uri := fmt.Sprintf(pathRepos, c.addr) + if hasAsync { + uri += "?" + asyncOpt(hasAsync) + } err := c.post(uri, nil, &out) return out, err } diff --git a/drone/client_test.go b/drone/client_test.go index d931e38..3006cfd 100644 --- a/drone/client_test.go +++ b/drone/client_test.go @@ -245,7 +245,7 @@ func TestRepoListSync(t *testing.T) { defer ts.Close() client := New(ts.URL) - got, err := client.RepoListSync() + got, err := client.RepoListSync(true) if err != nil { t.Error(err) return @@ -681,9 +681,7 @@ func TestLogsPurge(t *testing.T) { } } -// // mock server and testdata. -// func mockHandler(w http.ResponseWriter, r *http.Request) { routes := []struct { verb string diff --git a/drone/interface.go b/drone/interface.go index d84ae6f..a96cd53 100644 --- a/drone/interface.go +++ b/drone/interface.go @@ -64,7 +64,7 @@ type Client interface { // RepoListSync returns a list of all repositories to which // the user has explicit access in the host system. - RepoListSync() ([]*Repo, error) + RepoListSync(hasAsync bool) ([]*Repo, error) // RepoListAll returns a list of all repositories in // the database. This is only available to system admins.