Skip to content

Commit

Permalink
Merge branch 'main' into fix/gitlab-hook-verify
Browse files Browse the repository at this point in the history
  • Loading branch information
garethjevans authored Jan 25, 2023
2 parents 30976f2 + aff8b3c commit 5f3d324
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
21 changes: 20 additions & 1 deletion scm/driver/github/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,26 @@ func (s *repositoryService) CreateHook(ctx context.Context, repo string, input *
}

func (s *repositoryService) UpdateHook(ctx context.Context, repo string, input *scm.HookInput) (*scm.Hook, *scm.Response, error) {
return nil, nil, scm.ErrNotSupported
path := fmt.Sprintf("repos/%s/hooks/%s", repo, input.Name)
in := new(hook)
in.Active = true
in.Name = "web"
in.Config.Secret = input.Secret
in.Config.ContentType = "json"
in.Config.URL = input.Target
if input.SkipVerify {
in.Config.InsecureSSL = "1"
} else {
in.Config.InsecureSSL = "0"
}
input.NativeEvents = append(
input.NativeEvents,
convertHookEvents(input.Events)...,
)
in.Events = input.NativeEvents
out := new(hook)
res, err := s.client.do(ctx, "PATCH", path, in, out)
return convertHook(out), res, err
}

// CreateStatus creates a new commit status.
Expand Down
40 changes: 40 additions & 0 deletions scm/driver/github/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,46 @@ func TestRepositoryHookCreate(t *testing.T) {
t.Run("Rate", testRate(res))
}

func TestRepositoryHookUpdate(t *testing.T) {
defer gock.Off()

gock.New("https://api.github.com").
Patch("/repos/octocat/hello-world/hooks/drone").
Reply(200).
Type("application/json").
SetHeaders(mockHeaders).
File("testdata/hook.json")

in := &scm.HookInput{
Name: "drone",
Target: "https://example.com",
Secret: "topsecret",
SkipVerify: true,
}

client := NewDefault()
got, res, err := client.Repositories.UpdateHook(context.Background(), "octocat/hello-world", in)
if err != nil {
t.Error(err)
return
}

want := new(scm.Hook)
raw, _ := os.ReadFile("testdata/hook.json.golden")
err = json.Unmarshal(raw, want)
if err != nil {
t.Error(err)
}

if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("Unexpected Results")
t.Log(diff)
}

t.Run("Request", testRequest(res))
t.Run("Rate", testRate(res))
}

func TestRepositoryCreate(t *testing.T) {
defer gock.Off()

Expand Down

0 comments on commit 5f3d324

Please sign in to comment.