support bitbucket hook find, list

feature/refresh
Brad Rydzewski 6 years ago
parent 2903d8a22d
commit b8dd5a71c3

@ -1,27 +1,42 @@
GET /repos/octocat/hello-world/hooks/1
GET /2.0/repositories/atlassian/stash-example-plugin/hooks/{d53603cc-3f67-45ea-b310-aaa5ef6ec061}
Status: 200
Content-Type: application/json; charset=UTF-8
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 59
X-RateLimit-Reset: 1512076018
X-GitHub-Media-Type: github.v3; format=json
X-GitHub-Request-Id: DD0E:6011:12F21A8:1926790:5A2064E2
{
"id": 1,
"url": "https://api.github.com/repos/octocat/Hello-World/hooks/1",
"test_url": "https://api.github.com/repos/octocat/Hello-World/hooks/1/test",
"ping_url": "https://api.github.com/repos/octocat/Hello-World/hooks/1/pings",
"name": "web",
"events": [
"push",
"pull_request"
],
"read_only": false,
"description": "beta.drone.io",
"links": {
"self": {
"href": "https:\/\/api.bitbucket.org\/2.0\/repositories\/atlassian\/stash-example-plugin\/hooks\/%7Bd53603cc-3f67-45ea-b310-aaa5ef6ec061%7D"
}
},
"url": "http://example.com/webhook",
"created_at": "2015-10-05T01:11:48.096116Z",
"skip_cert_verification": false,
"source": null,
"active": true,
"config": {
"url": "http://example.com/webhook",
"content_type": "json"
"subject": {
"links": {
"self": {
"href": "https:\/\/api.bitbucket.org\/2.0\/repositories\/atlassian\/stash-example-plugin"
},
"html": {
"href": "https:\/\/bitbucket.org\/atlassian\/stash-example-plugin"
},
"avatar": {
"href": "https:\/\/bytebucket.org\/ravatar\/%7Bc179f544-ba1f-4ea9-bd8f-2b2c1efa4046%7D?ts=go"
}
},
"type": "repository",
"name": "stash-example-plugin",
"full_name": "atlassian\/stash-example-plugin",
"uuid": "{c179f544-ba1f-4ea9-bd8f-2b2c1efa4046}"
},
"updated_at": "2011-09-06T20:39:23Z",
"created_at": "2011-09-06T17:26:27Z"
"type": "webhook_subscription",
"events": [
"pullrequest:created",
"pullrequest:updated",
"repo:push"
],
"uuid": "{d53603cc-3f67-45ea-b310-aaa5ef6ec061}"
}

@ -1,33 +1,49 @@
GET /repos/octocat/hello-world/hooks?page=1&per_page=30
GET /2.0/repositories/atlassian/stash-example-plugin/hooks?page=1&pagelen=30
Status: 200
Content-Type: application/json; charset=UTF-8
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 59
X-RateLimit-Reset: 1512076018
X-GitHub-Media-Type: github.v3; format=json
X-GitHub-Request-Id: DD0E:6011:12F21A8:1926790:5A2064E2
Link: <https://api.github.com/resource?page=2>; rel="next",
<https://api.github.com/resource?page=1>; rel="prev",
<https://api.github.com/resource?page=1>; rel="first",
<https://api.github.com/resource?page=5>; rel="last"
[
{
"id": 1,
"url": "https://api.github.com/repos/octocat/Hello-World/hooks/1",
"test_url": "https://api.github.com/repos/octocat/Hello-World/hooks/1/test",
"ping_url": "https://api.github.com/repos/octocat/Hello-World/hooks/1/pings",
"name": "web",
"events": [
"push",
"pull_request"
],
"active": true,
"config": {
{
"pagelen": 10,
"values": [
{
"read_only": false,
"description": "example.com",
"links": {
"self": {
"href": "https:\/\/api.bitbucket.org\/2.0\/repositories\/atlassian\/stash-example-plugin\/hooks\/%7Bd53603cc-3f67-45ea-b310-aaa5ef6ec061%7D"
}
},
"url": "http://example.com/webhook",
"content_type": "json"
},
"updated_at": "2011-09-06T20:39:23Z",
"created_at": "2011-09-06T17:26:27Z"
}
]
"created_at": "2015-10-05T01:11:48.096116Z",
"skip_cert_verification": false,
"source": null,
"active": true,
"subject": {
"links": {
"self": {
"href": "https:\/\/api.bitbucket.org\/2.0\/repositories\/atlassian\/stash-example-plugin"
},
"html": {
"href": "https:\/\/bitbucket.org\/atlassian\/stash-example-plugin"
},
"avatar": {
"href": "https:\/\/bytebucket.org\/ravatar\/%7Bc179f544-ba1f-4ea9-bd8f-2b2c1efa4046%7D?ts=go"
}
},
"type": "repository",
"name": "stash-example-plugin",
"full_name": "atlassian\/stash-example-plugin",
"uuid": "{c179f544-ba1f-4ea9-bd8f-2b2c1efa4046}"
},
"type": "webhook_subscription",
"events": [
"pullrequest:created",
"pullrequest:updated",
"repo:push"
],
"uuid": "{d53603cc-3f67-45ea-b310-aaa5ef6ec061}"
}
],
"page": 1,
"size": 1
}

@ -122,36 +122,25 @@ var routes = []struct {
},
},
// GET /repos/octocat/hello-world/hooks/1
// GET /2.0/repositories/atlassian/stash-example-plugin/hooks/{d53603cc-3f67-45ea-b310-aaa5ef6ec061}
{
Method: "GET",
Path: "/repos/octocat/hello-world/hooks/1",
Path: "/2.0/repositories/atlassian/stash-example-plugin/hooks/{d53603cc-3f67-45ea-b310-aaa5ef6ec061}",
Status: 200,
Body: "{\n \"id\": 1,\n \"url\": \"https://api.github.com/repos/octocat/Hello-World/hooks/1\",\n \"test_url\": \"https://api.github.com/repos/octocat/Hello-World/hooks/1/test\",\n \"ping_url\": \"https://api.github.com/repos/octocat/Hello-World/hooks/1/pings\",\n \"name\": \"web\",\n \"events\": [\n \"push\",\n \"pull_request\"\n ],\n \"active\": true,\n \"config\": {\n \"url\": \"http://example.com/webhook\",\n \"content_type\": \"json\"\n },\n \"updated_at\": \"2011-09-06T20:39:23Z\",\n \"created_at\": \"2011-09-06T17:26:27Z\"\n}",
Body: "{\n \"read_only\": false,\n \"description\": \"beta.drone.io\",\n \"links\": {\n \"self\": {\n \"href\": \"https:\\/\\/api.bitbucket.org\\/2.0\\/repositories\\/atlassian\\/stash-example-plugin\\/hooks\\/%7Bd53603cc-3f67-45ea-b310-aaa5ef6ec061%7D\"\n }\n },\n \"url\": \"http://example.com/webhook\",\n \"created_at\": \"2015-10-05T01:11:48.096116Z\",\n \"skip_cert_verification\": false,\n \"source\": null,\n \"active\": true,\n \"subject\": {\n \"links\": {\n \"self\": {\n \"href\": \"https:\\/\\/api.bitbucket.org\\/2.0\\/repositories\\/atlassian\\/stash-example-plugin\"\n },\n \"html\": {\n \"href\": \"https:\\/\\/bitbucket.org\\/atlassian\\/stash-example-plugin\"\n },\n \"avatar\": {\n \"href\": \"https:\\/\\/bytebucket.org\\/ravatar\\/%7Bc179f544-ba1f-4ea9-bd8f-2b2c1efa4046%7D?ts=go\"\n }\n },\n \"type\": \"repository\",\n \"name\": \"stash-example-plugin\",\n \"full_name\": \"atlassian\\/stash-example-plugin\",\n \"uuid\": \"{c179f544-ba1f-4ea9-bd8f-2b2c1efa4046}\"\n },\n \"type\": \"webhook_subscription\",\n \"events\": [\n \"pullrequest:created\",\n \"pullrequest:updated\",\n \"repo:push\"\n ],\n \"uuid\": \"{d53603cc-3f67-45ea-b310-aaa5ef6ec061}\"\n}",
Header: map[string]string{
"Content-Type": "application/json; charset=UTF-8",
"X-Github-Media-Type": "github.v3; format=json",
"X-Github-Request-Id": "DD0E:6011:12F21A8:1926790:5A2064E2",
"X-Ratelimit-Limit": "60",
"X-Ratelimit-Remaining": "59",
"X-Ratelimit-Reset": "1512076018",
"Content-Type": "application/json; charset=UTF-8",
},
},
// GET /repos/octocat/hello-world/hooks?page=1&per_page=30
// GET /2.0/repositories/atlassian/stash-example-plugin/hooks?page=1&pagelen=30
{
Method: "GET",
Path: "/repos/octocat/hello-world/hooks?page=1&per_page=30",
Path: "/2.0/repositories/atlassian/stash-example-plugin/hooks?page=1&pagelen=30",
Status: 200,
Body: "[\n {\n \"id\": 1,\n \"url\": \"https://api.github.com/repos/octocat/Hello-World/hooks/1\",\n \"test_url\": \"https://api.github.com/repos/octocat/Hello-World/hooks/1/test\",\n \"ping_url\": \"https://api.github.com/repos/octocat/Hello-World/hooks/1/pings\",\n \"name\": \"web\",\n \"events\": [\n \"push\",\n \"pull_request\"\n ],\n \"active\": true,\n \"config\": {\n \"url\": \"http://example.com/webhook\",\n \"content_type\": \"json\"\n },\n \"updated_at\": \"2011-09-06T20:39:23Z\",\n \"created_at\": \"2011-09-06T17:26:27Z\"\n }\n]",
Body: "{\n \"pagelen\": 10,\n \"values\": [\n {\n \"read_only\": false,\n \"description\": \"example.com\",\n \"links\": {\n \"self\": {\n \"href\": \"https:\\/\\/api.bitbucket.org\\/2.0\\/repositories\\/atlassian\\/stash-example-plugin\\/hooks\\/%7Bd53603cc-3f67-45ea-b310-aaa5ef6ec061%7D\"\n }\n },\n \"url\": \"http://example.com/webhook\",\n \"created_at\": \"2015-10-05T01:11:48.096116Z\",\n \"skip_cert_verification\": false,\n \"source\": null,\n \"active\": true,\n \"subject\": {\n \"links\": {\n \"self\": {\n \"href\": \"https:\\/\\/api.bitbucket.org\\/2.0\\/repositories\\/atlassian\\/stash-example-plugin\"\n },\n \"html\": {\n \"href\": \"https:\\/\\/bitbucket.org\\/atlassian\\/stash-example-plugin\"\n },\n \"avatar\": {\n \"href\": \"https:\\/\\/bytebucket.org\\/ravatar\\/%7Bc179f544-ba1f-4ea9-bd8f-2b2c1efa4046%7D?ts=go\"\n }\n },\n \"type\": \"repository\",\n \"name\": \"stash-example-plugin\",\n \"full_name\": \"atlassian\\/stash-example-plugin\",\n \"uuid\": \"{c179f544-ba1f-4ea9-bd8f-2b2c1efa4046}\"\n },\n \"type\": \"webhook_subscription\",\n \"events\": [\n \"pullrequest:created\",\n \"pullrequest:updated\",\n \"repo:push\"\n ],\n \"uuid\": \"{d53603cc-3f67-45ea-b310-aaa5ef6ec061}\"\n }\n ],\n \"page\": 1,\n \"size\": 1\n}",
Header: map[string]string{
"Content-Type": "application/json; charset=UTF-8",
"Link": "<https://api.github.com/resource?page=2>; rel=\"next\", <https://api.github.com/resource?page=1>; rel=\"prev\", <https://api.github.com/resource?page=1>; rel=\"first\", <https://api.github.com/resource?page=5>; rel=\"last\"",
"X-Github-Media-Type": "github.v3; format=json",
"X-Github-Request-Id": "DD0E:6011:12F21A8:1926790:5A2064E2",
"X-Ratelimit-Limit": "60",
"X-Ratelimit-Remaining": "59",
"X-Ratelimit-Reset": "1512076018",
"Content-Type": "application/json; charset=UTF-8",
},
},

@ -31,16 +31,18 @@ type perms struct {
} `json:"values"`
}
type hooks struct {
pagination
Values []*hook `json:"values"`
}
type hook struct {
ID int `json:"id"`
Name string `json:"name"`
Events []string `json:"events"`
Active bool `json:"active"`
Config struct {
URL string `json:"url"`
Secret string `json:"secret"`
ContentType string `json:"content_type"`
} `json:"config"`
Description string `json:"description"`
URL string `json:"url"`
SkipCertVerification bool `json:"skip_cert_verification"`
Active bool `json:"active"`
Events []string `json:"events"`
UUID string `json:"uuid"`
}
type repositoryService struct {
@ -56,12 +58,11 @@ func (s *repositoryService) Find(ctx context.Context, repo string) (*scm.Reposit
}
// FindHook returns a repository hook.
func (s *repositoryService) FindHook(ctx context.Context, repo string, id int) (*scm.Hook, *scm.Response, error) {
// path := fmt.Sprintf("repos/%s/hooks/%d", repo, id)
// out := new(hook)
// res, err := s.client.do(ctx, "GET", path, nil, out)
// return convertHook(out), res, err
return nil, nil, scm.ErrNotSupported
func (s *repositoryService) FindHook(ctx context.Context, repo string, id string) (*scm.Hook, *scm.Response, error) {
path := fmt.Sprintf("2.0/repositories/%s/hooks/%s", repo, id)
out := new(hook)
res, err := s.client.do(ctx, "GET", path, nil, out)
return convertHook(out), res, err
}
// FindPerms returns the repository permissions.
@ -83,11 +84,11 @@ func (s *repositoryService) List(ctx context.Context, opts scm.ListOptions) ([]*
// ListHooks returns a list or repository hooks.
func (s *repositoryService) ListHooks(ctx context.Context, repo string, opts scm.ListOptions) ([]*scm.Hook, *scm.Response, error) {
// path := fmt.Sprintf("repos/%s/hooks?%s", repo, encodeListOptions(opts))
// out := []*hook{}
// res, err := s.client.do(ctx, "GET", path, nil, &out)
// return convertHookList(out), res, err
return nil, nil, scm.ErrNotSupported
path := fmt.Sprintf("2.0/repositories/%s/hooks?%s", repo, encodeListOptions(opts))
out := new(hooks)
res, err := s.client.do(ctx, "GET", path, nil, out)
copyPagination(out.pagination, res)
return convertHookList(out), res, err
}
// ListStatus returns a list of commit statuses.
@ -134,7 +135,7 @@ func (s *repositoryService) CreateStatus(ctx context.Context, repo, ref string,
}
// DeleteHook deletes a repository webhook.
func (s *repositoryService) DeleteHook(ctx context.Context, repo string, id int) (*scm.Response, error) {
func (s *repositoryService) DeleteHook(ctx context.Context, repo string, id string) (*scm.Response, error) {
// path := fmt.Sprintf("repos/%s/hooks/%d", repo, id)
// return s.client.do(ctx, "DELETE", path, nil, nil)
return nil, scm.ErrNotSupported
@ -187,9 +188,9 @@ func convertPerms(from *perms) *scm.Perm {
return to
}
func convertHookList(from []*hook) []*scm.Hook {
func convertHookList(from *hooks) []*scm.Hook {
to := []*scm.Hook{}
for _, v := range from {
for _, v := range from.Values {
to = append(to, convertHook(v))
}
return to
@ -197,33 +198,40 @@ func convertHookList(from []*hook) []*scm.Hook {
func convertHook(from *hook) *scm.Hook {
return &scm.Hook{
ID: from.ID,
Active: from.Active,
Target: from.Config.URL,
Events: from.Events,
ID: from.UUID,
Name: from.Description,
Active: from.Active,
Target: from.URL,
Events: from.Events,
SkipVerify: from.SkipCertVerification,
}
}
func convertHookEvents(from scm.HookEvents) []string {
var events []string
if from.Push {
events = append(events, "push")
events = append(events, "repo:push")
}
if from.PullRequest {
events = append(events, "pull_request")
events = append(events, "pullrequest:updated")
events = append(events, "pullrequest:unapproved")
events = append(events, "pullrequest:approved")
events = append(events, "pullrequest:rejected")
events = append(events, "pullrequest:fulfilled")
events = append(events, "pullrequest:created")
}
if from.PullRequestComment {
events = append(events, "pull_request_review_comment")
events = append(events, "pullrequest:comment_created")
events = append(events, "pullrequest:comment_updated")
events = append(events, "pullrequest:comment_deleted")
}
if from.Issue {
events = append(events, "issues")
events = append(events, "issue:created")
events = append(events, "issue:updated")
}
if from.IssueComment || from.PullRequestComment {
events = append(events, "issue_comment")
}
if from.Branch || from.Tag {
events = append(events, "create")
events = append(events, "delete")
if from.IssueComment {
events = append(events, "issue:comment_created")
}
return events
}

@ -106,13 +106,11 @@ func TestRepositoryHookFind(t *testing.T) {
defer server.Close()
client, _ := New(server.URL)
result, res, err := client.Repositories.FindHook(context.Background(), "octocat/hello-world", 1)
result, _, err := client.Repositories.FindHook(context.Background(), "atlassian/stash-example-plugin", "{d53603cc-3f67-45ea-b310-aaa5ef6ec061}")
if err != nil {
t.Error(err)
return
}
t.Run("Request", testRequest(res))
t.Run("Rate", testRate(res))
t.Run("Hook", testHook(result))
}
@ -121,7 +119,7 @@ func TestRepositoryHookList(t *testing.T) {
defer server.Close()
client, _ := New(server.URL)
result, res, err := client.Repositories.ListHooks(context.Background(), "octocat/hello-world", scm.ListOptions{Page: 1, Size: 30})
result, _, err := client.Repositories.ListHooks(context.Background(), "atlassian/stash-example-plugin", scm.ListOptions{Page: 1, Size: 30})
if err != nil {
t.Error(err)
return
@ -130,9 +128,6 @@ func TestRepositoryHookList(t *testing.T) {
t.Errorf("Want %d hooks, got %d", want, got)
return
}
t.Run("Request", testRequest(res))
t.Run("Rate", testRate(res))
t.Run("Page", testPage(res))
t.Run("Hook", testHook(result[0]))
}
@ -141,7 +136,7 @@ func TestRepositoryHookDelete(t *testing.T) {
defer server.Close()
client, _ := New(server.URL)
_, err := client.Repositories.DeleteHook(context.Background(), "octocat/hello-world", 1)
_, err := client.Repositories.DeleteHook(context.Background(), "octocat/hello-world", "1")
if err != nil {
t.Error(err)
}
@ -198,7 +193,7 @@ func testPermissions(perms *scm.Perm) func(t *testing.T) {
func testHook(hook *scm.Hook) func(t *testing.T) {
return func(t *testing.T) {
if got, want := hook.ID, 1; got != want {
if got, want := hook.ID, "{d53603cc-3f67-45ea-b310-aaa5ef6ec061}"; got != want {
t.Errorf("Want hook ID %v, got %v", want, got)
}
if got, want := hook.Active, true; got != want {

@ -62,8 +62,8 @@ func (s *repositoryService) Find(ctx context.Context, repo string) (*scm.Reposit
}
// FindHook returns a repository hook.
func (s *repositoryService) FindHook(ctx context.Context, repo string, id int) (*scm.Hook, *scm.Response, error) {
path := fmt.Sprintf("repos/%s/hooks/%d", repo, id)
func (s *repositoryService) FindHook(ctx context.Context, repo string, id string) (*scm.Hook, *scm.Response, error) {
path := fmt.Sprintf("repos/%s/hooks/%s", repo, id)
out := new(hook)
res, err := s.client.do(ctx, "GET", path, nil, out)
return convertHook(out), res, err
@ -134,8 +134,8 @@ func (s *repositoryService) CreateStatus(ctx context.Context, repo, ref string,
}
// DeleteHook deletes a repository webhook.
func (s *repositoryService) DeleteHook(ctx context.Context, repo string, id int) (*scm.Response, error) {
path := fmt.Sprintf("repos/%s/hooks/%d", repo, id)
func (s *repositoryService) DeleteHook(ctx context.Context, repo string, id string) (*scm.Response, error) {
path := fmt.Sprintf("repos/%s/hooks/%s", repo, id)
return s.client.do(ctx, "DELETE", path, nil, nil)
}
@ -181,7 +181,7 @@ func convertHookList(from []*hook) []*scm.Hook {
func convertHook(from *hook) *scm.Hook {
return &scm.Hook{
ID: from.ID,
ID: strconv.Itoa(from.ID),
Active: from.Active,
Target: from.Config.URL,
Events: from.Events,

@ -126,7 +126,7 @@ func TestRepositoryHookFind(t *testing.T) {
defer server.Close()
client, _ := New(server.URL)
result, res, err := client.Repositories.FindHook(context.Background(), "octocat/hello-world", 1)
result, res, err := client.Repositories.FindHook(context.Background(), "octocat/hello-world", "1")
if err != nil {
t.Error(err)
return
@ -161,7 +161,7 @@ func TestRepositoryHookDelete(t *testing.T) {
defer server.Close()
client, _ := New(server.URL)
_, err := client.Repositories.DeleteHook(context.Background(), "octocat/hello-world", 1)
_, err := client.Repositories.DeleteHook(context.Background(), "octocat/hello-world", "1")
if err != nil {
t.Error(err)
}
@ -218,7 +218,7 @@ func testPermissions(perms *scm.Perm) func(t *testing.T) {
func testHook(hook *scm.Hook) func(t *testing.T) {
return func(t *testing.T) {
if got, want := hook.ID, 1; got != want {
if got, want := hook.ID, "1"; got != want {
t.Errorf("Want hook ID %v, got %v", want, got)
}
if got, want := hook.Active, true; got != want {

@ -71,8 +71,8 @@ func (s *repositoryService) Find(ctx context.Context, repo string) (*scm.Reposit
return convertRepository(out), res, err
}
func (s *repositoryService) FindHook(ctx context.Context, repo string, id int) (*scm.Hook, *scm.Response, error) {
path := fmt.Sprintf("api/v4/projects/%s/hooks/%d", encode(repo), id)
func (s *repositoryService) FindHook(ctx context.Context, repo string, id string) (*scm.Hook, *scm.Response, error) {
path := fmt.Sprintf("api/v4/projects/%s/hooks/%s", encode(repo), id)
out := new(hook)
res, err := s.client.do(ctx, "GET", path, nil, out)
return convertHook(out), res, err
@ -152,8 +152,8 @@ func (s *repositoryService) CreateStatus(ctx context.Context, repo, ref string,
return convertStatus(out), res, err
}
func (s *repositoryService) DeleteHook(ctx context.Context, repo string, id int) (*scm.Response, error) {
path := fmt.Sprintf("api/v4/projects/%s/hooks/%d", encode(repo), id)
func (s *repositoryService) DeleteHook(ctx context.Context, repo string, id string) (*scm.Response, error) {
path := fmt.Sprintf("api/v4/projects/%s/hooks/%s", encode(repo), id)
return s.client.do(ctx, "DELETE", path, nil, nil)
}
@ -202,7 +202,7 @@ func convertHookList(from []*hook) []*scm.Hook {
func convertHook(from *hook) *scm.Hook {
return &scm.Hook{
ID: from.ID,
ID: strconv.Itoa(from.ID),
Active: true,
Target: from.URL,
Events: convertEvents(from),

@ -126,7 +126,7 @@ func TestRepositoryHookFind(t *testing.T) {
defer server.Close()
client, _ := New(server.URL)
result, res, err := client.Repositories.FindHook(context.Background(), "diaspora/diaspora", 1)
result, res, err := client.Repositories.FindHook(context.Background(), "diaspora/diaspora", "1")
if err != nil {
t.Error(err)
return
@ -161,7 +161,7 @@ func TestRepositoryHookDelete(t *testing.T) {
defer server.Close()
client, _ := New(server.URL)
_, err := client.Repositories.DeleteHook(context.Background(), "diaspora/diaspora", 1)
_, err := client.Repositories.DeleteHook(context.Background(), "diaspora/diaspora", "1")
if err != nil {
t.Error(err)
}
@ -225,7 +225,7 @@ func testPermissions(perms *scm.Perm) func(t *testing.T) {
func testHook(hook *scm.Hook) func(t *testing.T) {
return func(t *testing.T) {
if got, want := hook.ID, 1; got != want {
if got, want := hook.ID, "1"; got != want {
t.Errorf("Want hook ID %v, got %v", want, got)
}
if got, want := hook.Active, true; got != want {

@ -24,8 +24,8 @@ func (s *repositoryService) Find(ctx context.Context, repo string) (*scm.Reposit
return convertRepository(out), res, err
}
func (s *repositoryService) FindHook(ctx context.Context, repo string, id int) (*scm.Hook, *scm.Response, error) {
path := fmt.Sprintf("api/v1/repos/%s/hooks/%d", repo, id)
func (s *repositoryService) FindHook(ctx context.Context, repo string, id string) (*scm.Hook, *scm.Response, error) {
path := fmt.Sprintf("api/v1/repos/%s/hooks/%s", repo, id)
out := new(hook)
res, err := s.client.do(ctx, "GET", path, nil, out)
return convertHook(out), res, err
@ -77,8 +77,8 @@ func (s *repositoryService) CreateStatus(context.Context, string, string, *scm.S
return nil, nil, scm.ErrNotSupported
}
func (s *repositoryService) DeleteHook(ctx context.Context, repo string, id int) (*scm.Response, error) {
path := fmt.Sprintf("api/v1/repos/%s/hooks/%d", repo, id)
func (s *repositoryService) DeleteHook(ctx context.Context, repo string, id string) (*scm.Response, error) {
path := fmt.Sprintf("api/v1/repos/%s/hooks/%s", repo, id)
return s.client.do(ctx, "DELETE", path, nil, nil)
}
@ -171,7 +171,7 @@ func convertHookList(src []*hook) []*scm.Hook {
func convertHook(from *hook) *scm.Hook {
return &scm.Hook{
ID: from.ID,
ID: strconv.Itoa(from.ID),
Active: from.Active,
Target: from.Config.URL,
Events: from.Events,

@ -89,7 +89,7 @@ func testHooks(client *scm.Client) func(t *testing.T) {
func testHookFind(client *scm.Client) func(t *testing.T) {
return func(t *testing.T) {
result, _, err := client.Repositories.FindHook(context.Background(), "gogits/gogs", 20)
result, _, err := client.Repositories.FindHook(context.Background(), "gogits/gogs", "20")
if err != nil {
t.Error(err)
} else {
@ -124,7 +124,7 @@ func testHookCreate(client *scm.Client) func(t *testing.T) {
func testHookDelete(client *scm.Client) func(t *testing.T) {
return func(t *testing.T) {
_, err := client.Repositories.DeleteHook(context.Background(), "gogits/gogs", 20)
_, err := client.Repositories.DeleteHook(context.Background(), "gogits/gogs", "20")
if err != nil {
t.Error(err)
}
@ -200,7 +200,7 @@ func testPermissions(perms *scm.Perm) func(t *testing.T) {
func testHook(hook *scm.Hook) func(t *testing.T) {
return func(t *testing.T) {
if got, want := hook.ID, 20; got != want {
if got, want := hook.ID, "20"; got != want {
t.Errorf("Want hook ID %v, got %v", want, got)
}
if got, want := hook.Active, true; got != want {

@ -34,7 +34,7 @@ type (
// Hook represents a repository hook.
Hook struct {
ID int
ID string
Name string
Target string
Events []string
@ -96,7 +96,7 @@ type (
Find(context.Context, string) (*Repository, *Response, error)
// FindHook returns a repository hook.
FindHook(context.Context, string, int) (*Hook, *Response, error)
FindHook(context.Context, string, string) (*Hook, *Response, error)
// FindPerms returns repository permissions.
FindPerms(context.Context, string) (*Perm, *Response, error)
@ -117,7 +117,7 @@ type (
CreateStatus(context.Context, string, string, *StatusInput) (*Status, *Response, error)
// DeleteHook deletes a repository webhook.
DeleteHook(context.Context, string, int) (*Response, error)
DeleteHook(context.Context, string, string) (*Response, error)
}
)

Loading…
Cancel
Save