diff --git a/server/forge/bitbucket/bitbucket_test.go b/server/forge/bitbucket/bitbucket_test.go index a3d3277fdc..b616e0db8a 100644 --- a/server/forge/bitbucket/bitbucket_test.go +++ b/server/forge/bitbucket/bitbucket_test.go @@ -178,6 +178,36 @@ func Test_bitbucket(t *testing.T) { }) }) + g.Describe("When requesting repo branch HEAD", func() { + g.It("Should return the details", func() { + branchHead, err := c.BranchHead(ctx, fakeUser, fakeRepo, "branch_name") + g.Assert(err).IsNil() + g.Assert(branchHead).Equal("branch_head_name") + }) + g.It("Should handle not found errors", func() { + _, err := c.BranchHead(ctx, fakeUser, fakeRepo, "branch_not_found") + g.Assert(err).IsNotNil() + }) + }) + + g.Describe("When requesting repo pull requests", func() { + listOpts := model.ListOptions{ + All: false, + Page: 1, + PerPage: 10, + } + g.It("Should return the details", func() { + repoPRs, err := c.PullRequests(ctx, fakeUser, fakeRepo, &listOpts) + g.Assert(err).IsNil() + g.Assert(repoPRs[0].Title).Equal("PRs title") + g.Assert(repoPRs[0].Index).Equal(int64(123)) + }) + g.It("Should handle not found errors", func() { + _, err := c.PullRequests(ctx, fakeUser, fakeRepoNotFound, &listOpts) + g.Assert(err).IsNotNil() + }) + }) + g.Describe("When requesting repo directory contents", func() { g.It("Should return the details", func() { files, err := c.Dir(ctx, fakeUser, fakeRepo, fakePipeline, "/dir") diff --git a/server/forge/bitbucket/fixtures/handler.go b/server/forge/bitbucket/fixtures/handler.go index 90847e821d..b200bb219d 100644 --- a/server/forge/bitbucket/fixtures/handler.go +++ b/server/forge/bitbucket/fixtures/handler.go @@ -38,7 +38,8 @@ func Handler() http.Handler { e.GET("/2.0/repositories/:owner", getUserRepos) e.GET("/2.0/user/", getUser) e.GET("/2.0/user/permissions/repositories", getPermissions) - + e.GET("/2.0/repositories/:owner/:name/commits/:commit", getBranchHead) + e.GET("/2.0/repositories/:owner/:name/pullrequests", getPullRequests) return e } @@ -119,6 +120,24 @@ func getRepoFile(c *gin.Context) { } } +func getBranchHead(c *gin.Context) { + switch c.Param("commit") { + case "branch_name": + c.String(200, branchCommitsPayload) + default: + c.String(404, "") + } +} + +func getPullRequests(c *gin.Context) { + switch c.Param("name") { + case "repo_name": + c.String(200, pullRequestsPayload) + default: + c.String(404, "") + } +} + func createRepoStatus(c *gin.Context) { switch c.Param("name") { case "repo_not_found": @@ -248,6 +267,40 @@ const repoDirPayload = ` } ` +const branchCommitsPayload = ` +{ + "values": [ + { + "hash": "branch_head_name" + }, + { + "hash": "random1" + }, + { + "hash": "random2" + } + ] +} +` + +const pullRequestsPayload = ` +{ + "values": [ + { + "id": 123, + "title": "PRs title" + }, + { + "id": 456, + "title": "Another PRs title" + } + ], + "pagelen": 10, + "size": 2, + "page": 1 +} +` + const userPayload = ` { "username": "superman",