-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added Projects list function (#4)
* feat: Added Projects list function * feat: Added ListProjects
- Loading branch information
Showing
10 changed files
with
374 additions
and
114 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module( | ||
name = "go-bitbucket", | ||
version = "1.0.0", | ||
) | ||
|
||
bazel_dep(name = "rules_go", version = "0.51.0", repo_name = "io_bazel_rules_go") | ||
bazel_dep(name = "gazelle", version = "0.40.0", repo_name = "bazel_gazelle") | ||
|
||
go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk") | ||
go_sdk.download(version = "1.23.4") | ||
|
||
go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps") | ||
go_deps.from_file(go_mod = "//:go.mod") | ||
use_repo( | ||
go_deps, | ||
"com_github_google_go_querystring", | ||
"com_github_julienschmidt_httprouter", | ||
"com_github_stretchr_testify", | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,31 +0,0 @@ | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
http_archive( | ||
name = "io_bazel_rules_go", | ||
sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa", | ||
urls = [ | ||
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", | ||
"https://github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip", | ||
], | ||
) | ||
|
||
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") | ||
go_rules_dependencies() | ||
go_register_toolchains(version = "1.19.2") | ||
|
||
http_archive( | ||
name = "bazel_gazelle", | ||
sha256 = "de69a09dc70417580aabf20a28619bb3ef60d038470c7cf8442fafcf627c21cb", | ||
urls = [ | ||
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz", | ||
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz", | ||
], | ||
) | ||
|
||
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") | ||
load("//:deps.bzl", "go_dependencies") | ||
|
||
# gazelle:repository_macro deps.bzl%go_dependencies | ||
go_dependencies() | ||
|
||
gazelle_dependencies() | ||
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 |
---|---|---|
@@ -1,5 +1,30 @@ | ||
package bitbucket | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type ProjectsService service | ||
|
||
const projectsApiName = "api" | ||
|
||
type Project struct { | ||
ID uint64 `json:"id,omitempty"` | ||
Key string `json:"key,omitempty"` | ||
Name string `json:"name"` | ||
Links map[string][]Link `json:"links,omitempty"` | ||
} | ||
|
||
type ProjectList struct { | ||
ListResponse | ||
Projects []*Project `json:"values"` | ||
} | ||
|
||
func (s *ProjectsService) ListProjects(ctx context.Context, opts *ListOptions) ([]*Project, *Response, error) { | ||
var l ProjectList | ||
resp, err := s.client.GetPaged(ctx, projectsApiName, "projects", &l, opts) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
return l.Projects, resp, nil | ||
} |
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,69 @@ | ||
package bitbucket | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestListProjects(t *testing.T) { | ||
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { | ||
assert.Equal(t, "GET", req.Method) | ||
assert.Equal(t, "/api/latest/projects", req.URL.Path) | ||
rw.Write([]byte(listProjectsResponse)) | ||
})) | ||
defer server.Close() | ||
|
||
client, _ := NewClient(server.URL, nil) | ||
ctx := context.Background() | ||
repos, resp, err := client.Projects.ListProjects(ctx, &ListOptions{}) | ||
assert.NoError(t, err) | ||
assert.Len(t, repos, 2) | ||
assert.Equal(t, uint64(363), repos[0].ID) | ||
assert.True(t, resp.LastPage) | ||
assert.Equal(t, uint(0), resp.Page.NextPageStart) | ||
} | ||
|
||
const listProjectsResponse = `{ | ||
"size": 2, | ||
"limit": 25, | ||
"isLastPage": true, | ||
"start": 0, | ||
"nextPageStart": 0, | ||
"values": [ | ||
{ | ||
"key": "PRJ1", | ||
"id": 363, | ||
"name": "Project 1", | ||
"description": "My project 1", | ||
"public": false, | ||
"type": "NORMAL", | ||
"links": { | ||
"self": [ | ||
{ | ||
"href": "https://git/projects/PRJ1" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"key": "PRJ2", | ||
"id": 909, | ||
"name": "Project 2", | ||
"description": "My Project 2", | ||
"public": false, | ||
"type": "NORMAL", | ||
"links": { | ||
"self": [ | ||
{ | ||
"href": "https://git/projects/PRJ2" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
` |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/neticdk/go-bitbucket | ||
|
||
go 1.19 | ||
go 1.23 | ||
|
||
require github.com/stretchr/testify v1.8.1 | ||
|
||
|
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