Skip to content

Commit

Permalink
Merge pull request #241 from tphoney/harness_repo_calls
Browse files Browse the repository at this point in the history
(feat) harness, add repo list
  • Loading branch information
TP Honey authored Feb 7, 2023
2 parents ca3776c + 2066d10 commit 8a67193
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 233 deletions.
8 changes: 1 addition & 7 deletions scm/driver/harness/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (s *contentService) Update(ctx context.Context, repo, path string, params *
Path: path,
Payload: string(params.Data),
Encoding: "string",
Sha: params.BlobID,
}
in := editFile{
Branch: params.Branch,
Expand Down Expand Up @@ -91,13 +92,6 @@ func (s *contentService) Delete(ctx context.Context, repo, path string, params *
return res, err
}

func buildHarnessURI(account, organization, project, repo string) (uri string) {
if account != "" {
return fmt.Sprintf("%s/%s/%s/%s/+", account, organization, project, repo)
}
return repo
}

func (s *contentService) List(ctx context.Context, repo, path, ref string, _ scm.ListOptions) ([]*scm.ContentInfo, *scm.Response, error) {
repo = buildHarnessURI(s.client.account, s.client.organization, s.client.project, repo)
endpoint := fmt.Sprintf("api/v1/repos/%s/content/%s?%s&include_commit=true", repo, path, ref)
Expand Down
69 changes: 37 additions & 32 deletions scm/driver/harness/content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@ const (
harnessOrg = "px7xd_BFRCi-pfWPYXVjvw"
harnessAccount = "default"
harnessProject = "codeciintegration"
harnessRepo = "demo"
harnessRepo = "thomas"
harnessPAT = ""
)

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

gock.New(gockOrigin).
Get("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/demo/+/content/README.md").
Reply(200).
Type("plain/text").
File("testdata/content.json")
if harnessPAT == "" {
defer gock.Off()

gock.New(gockOrigin).
Get("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/content/README.md").
Reply(200).
Type("plain/text").
File("testdata/content.json")
}
client, _ := New(gockOrigin, harnessOrg, harnessAccount, harnessProject)
client.Client = &http.Client{
Transport: &transport.Custom{
Expand All @@ -57,20 +58,21 @@ func TestContentFind(t *testing.T) {
if got, want := result.Path, "README.md"; got != want {
t.Errorf("Want file Path %q, got %q", want, got)
}
if !strings.Contains(string(result.Data), "demo") {
t.Errorf("Want file Data %q, must contain 'demo'", result.Data)
if !strings.Contains(string(result.Data), "project") {
t.Errorf("Want file Data %q, must contain 'project'", result.Data)
}
}

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

gock.New(gockOrigin).
Post("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/demo/+/commits").
Reply(200).
Type("plain/text").
BodyString("{\"commit_id\":\"20ecde1f8c277da0e91750bef9f3b88f228d86db\"}")
if harnessPAT == "" {
defer gock.Off()

gock.New(gockOrigin).
Post("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/commits").
Reply(200).
Type("plain/text").
BodyString("{\"commit_id\":\"20ecde1f8c277da0e91750bef9f3b88f228d86db\"}")
}
client, _ := New(gockOrigin, harnessOrg, harnessAccount, harnessProject)
client.Client = &http.Client{
Transport: &transport.Custom{
Expand Down Expand Up @@ -99,14 +101,15 @@ func TestContentCreate(t *testing.T) {
}

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

gock.New(gockOrigin).
Post("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/demo/+/commits").
Reply(200).
Type("plain/text").
BodyString("{\"commit_id\":\"20ecde1f8c277da0e91750bef9f3b88f228d86db\"}")
if harnessPAT == "" {
defer gock.Off()

gock.New(gockOrigin).
Post("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/commits").
Reply(200).
Type("plain/text").
BodyString("{\"commit_id\":\"20ecde1f8c277da0e91750bef9f3b88f228d86db\"}")
}
client, _ := New(gockOrigin, harnessOrg, harnessAccount, harnessProject)
client.Client = &http.Client{
Transport: &transport.Custom{
Expand All @@ -123,6 +126,7 @@ func TestContentUpdate(t *testing.T) {
Data: []byte("hello world 2"),
Message: "update README.2",
Branch: "main",
BlobID: "95d09f2b10159347eece71399a7e2e907ea3df4f",
},
)
if err != nil {
Expand All @@ -135,14 +139,15 @@ func TestContentUpdate(t *testing.T) {
}

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

gock.New(gockOrigin).
Post("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/demo/+/commits").
Reply(200).
Type("plain/text").
BodyString("{\"commit_id\":\"20ecde1f8c277da0e91750bef9f3b88f228d86db\"}")
if harnessPAT == "" {
defer gock.Off()

gock.New(gockOrigin).
Post("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/commits").
Reply(200).
Type("plain/text").
BodyString("{\"commit_id\":\"20ecde1f8c277da0e91750bef9f3b88f228d86db\"}")
}
client, _ := New(gockOrigin, harnessOrg, harnessAccount, harnessProject)
client.Client = &http.Client{
Transport: &transport.Custom{
Expand Down Expand Up @@ -173,7 +178,7 @@ func TestContentList(t *testing.T) {
defer gock.Off()

gock.New(gockOrigin).
Get("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/demo/+/content/docker").
Get("/gateway/code/api/v1/repos/px7xd_BFRCi-pfWPYXVjvw/default/codeciintegration/thomas/+/content/docker").
Reply(200).
Type("application/json").
File("testdata/content_list.json")
Expand Down
2 changes: 1 addition & 1 deletion scm/driver/harness/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func convertPullRequest(src *pr) *scm.PullRequest {
Target: src.Base.Name,
Link: src.HTMLURL,
Diff: src.DiffURL,
Fork: src.Base.Repo.FullName,
Fork: "fork",
Ref: fmt.Sprintf("refs/pull/%d/head", src.Number),
Closed: src.State == "closed",
Author: *convertUser(&src.User),
Expand Down
Loading

0 comments on commit 8a67193

Please sign in to comment.