Skip to content

Commit

Permalink
(feat) harness, add find hook
Browse files Browse the repository at this point in the history
  • Loading branch information
TP Honey committed Feb 8, 2023
1 parent ff7deab commit b8eea16
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
6 changes: 5 additions & 1 deletion scm/driver/harness/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ func (s *repositoryService) Find(ctx context.Context, repo string) (*scm.Reposit
}

func (s *repositoryService) FindHook(ctx context.Context, repo string, id string) (*scm.Hook, *scm.Response, error) {
return nil, nil, scm.ErrNotSupported
harnessURI := buildHarnessURI(s.client.account, s.client.organization, s.client.project, repo)
path := fmt.Sprintf("api/v1/repos/%s/webhooks/%s", harnessURI, id)
out := new(hook)
res, err := s.client.do(ctx, "GET", path, nil, &out)
return convertHook(out), res, err
}

func (s *repositoryService) FindPerms(ctx context.Context, repo string) (*scm.Perm, *scm.Response, error) {
Expand Down
34 changes: 34 additions & 0 deletions scm/driver/harness/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,37 @@ func TestRepositoryHookList(t *testing.T) {
t.Log(diff)
}
}

func TestRepositoryFindHook(t *testing.T) {
if harnessPAT == "" {
defer gock.Off()

gock.New(gockOrigin).
Get("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/webhooks/6").
Reply(200).
Type("application/json").
File("testdata/hook.json")
}
client, _ := New(gockOrigin, harnessOrg, harnessAccount, harnessProject)
client.Client = &http.Client{
Transport: &transport.Custom{
Before: func(r *http.Request) {
r.Header.Set("x-api-key", harnessPAT)
},
},
}
got, _, err := client.Repositories.FindHook(context.Background(), harnessRepo, "6")
if err != nil {
t.Error(err)
return
}

want := new(scm.Hook)
raw, _ := ioutil.ReadFile("testdata/hook.json.golden")
_ = json.Unmarshal(raw, &want)

if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("Unexpected Results")
t.Log(diff)
}
}
17 changes: 17 additions & 0 deletions scm/driver/harness/testdata/hook.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"id": 6,
"version": 1,
"parent_id": 11,
"parent_type": "repo",
"created_by": 14,
"created": 1675867490853,
"updated": 1675867531549,
"display_name": "webhookname",
"description": "webhookdescription",
"url": "http://1.1.1.1",
"enabled": true,
"insecure": true,
"triggers": [],
"latest_execution_result": "success",
"has_secret": true
}
8 changes: 8 additions & 0 deletions scm/driver/harness/testdata/hook.json.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"ID": "6",
"Name": "webhookname",
"Target": "http://1.1.1.1",
"Events": [],
"Active": true,
"SkipVerify": true
}

0 comments on commit b8eea16

Please sign in to comment.