Skip to content

Commit

Permalink
Merge pull request #7 from go-vela/cleanup
Browse files Browse the repository at this point in the history
Cleanup and refactor library logic
  • Loading branch information
Neal authored Nov 9, 2019
2 parents 4bb44d9 + dab3ece commit 876d1d1
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 114 deletions.
14 changes: 7 additions & 7 deletions vela/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ type AuthenticationService struct {
}

// SetTokenAuth sets the authentication type as OAuth Token.
func (s *AuthenticationService) SetTokenAuth(token string) {
s.secret = String(token)
s.authType = AuthenticationToken
func (svc *AuthenticationService) SetTokenAuth(token string) {
svc.secret = String(token)
svc.authType = AuthenticationToken
}

// HasAuth checks if the authentication type is set.
func (s *AuthenticationService) HasAuth() bool {
return s.authType > 0
func (svc *AuthenticationService) HasAuth() bool {
return svc.authType > 0
}

// HasTokenAuth checks if the authentication type is OAuth Token.
func (s *AuthenticationService) HasTokenAuth() bool {
return s.authType == AuthenticationToken
func (svc *AuthenticationService) HasTokenAuth() bool {
return svc.authType == AuthenticationToken
}
41 changes: 20 additions & 21 deletions vela/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package vela
import (
"fmt"

"github.com/go-vela/types/database"
"github.com/go-vela/types/library"
)

Expand All @@ -16,92 +15,92 @@ import (
type BuildService service

// Get returns the provided build.
func (s *BuildService) Get(org, repo string, target int) (*library.Build, *Response, error) {
func (svc *BuildService) Get(org, repo string, build int) (*library.Build, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d", org, repo, target)
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d", org, repo, build)

// library Build type we want to return
v := new(library.Build)

// send request using client
resp, err := s.client.Call("GET", u, nil, v)
resp, err := svc.client.Call("GET", u, nil, v)
return v, resp, err
}

// GetAll returns a list of all builds.
func (s *BuildService) GetAll(org, repo string) (*[]library.Build, *Response, error) {
func (svc *BuildService) GetAll(org, repo string) (*[]library.Build, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds", org, repo)

// slice library Build type we want to return
v := new([]library.Build)

// send request using client
resp, err := s.client.Call("GET", u, nil, v)
resp, err := svc.client.Call("GET", u, nil, v)
return v, resp, err
}

// GetLogs returns the provided build logs.
func (s *BuildService) GetLogs(org, repo string, target int) (*[]database.Log, *Response, error) {
func (svc *BuildService) GetLogs(org, repo string, build int) (*[]library.Log, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/logs", org, repo, target)
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/logs", org, repo, build)

// slice database Log type we want to return
v := new([]database.Log)
v := new([]library.Log)

// send request using client
resp, err := s.client.Call("GET", u, nil, v)
resp, err := svc.client.Call("GET", u, nil, v)
return v, resp, err
}

// Add constructs a build with the provided details.
func (s *BuildService) Add(org, repo string, target *library.Build) (*library.Build, *Response, error) {
func (svc *BuildService) Add(org, repo string, b *library.Build) (*library.Build, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds", org, repo)

// library Build type we want to return
v := new(library.Build)

// send request using client
resp, err := s.client.Call("POST", u, target, v)
resp, err := svc.client.Call("POST", u, b, v)
return v, resp, err
}

// Update modifies a build with the provided details.
func (s *BuildService) Update(org, repo string, target *library.Build) (*library.Build, *Response, error) {
func (svc *BuildService) Update(org, repo string, b *library.Build) (*library.Build, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d", org, repo, *target.Number)
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d", org, repo, b.GetNumber())

// library Build type we want to return
v := new(library.Build)

// send request using client
resp, err := s.client.Call("PUT", u, target, v)
resp, err := svc.client.Call("PUT", u, b, v)
return v, resp, err
}

// Remove deletes the provided build.
func (s *BuildService) Remove(org, repo string, target int) (*string, *Response, error) {
func (svc *BuildService) Remove(org, repo string, build int) (*string, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d", org, repo, target)
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d", org, repo, build)

// string type we want to return
v := new(string)

// send request using client
resp, err := s.client.Call("DELETE", u, nil, v)
resp, err := svc.client.Call("DELETE", u, nil, v)
return v, resp, err
}

// Restart takes the build provided and restarts it
func (s *BuildService) Restart(org, repo string, target int) (*library.Build, *Response, error) {
func (svc *BuildService) Restart(org, repo string, build int) (*library.Build, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d", org, repo, target)
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d", org, repo, build)

// library Build type we want to return
v := new(library.Build)

// send request using client
resp, err := s.client.Call("POST", u, nil, v)
resp, err := svc.client.Call("POST", u, nil, v)
return v, resp, err
}
5 changes: 2 additions & 3 deletions vela/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"time"

"github.com/go-vela/mock/server"
"github.com/go-vela/types/database"
"github.com/go-vela/types/library"

"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -104,7 +103,7 @@ func TestBuild_GetLogs_200(t *testing.T) {
c, _ := NewClient(s.URL, nil)

data := []byte(server.BuildLogsResp)
var want []database.Log
var want []library.Log
_ = json.Unmarshal(data, &want)

// run test
Expand All @@ -129,7 +128,7 @@ func TestBuild_GetLogs_404(t *testing.T) {
s := httptest.NewServer(server.FakeHandler())
c, _ := NewClient(s.URL, nil)

want := []database.Log{}
want := []library.Log{}

// run test
got, resp, err := c.Build.GetLogs("github", "octocat", 0)
Expand Down
48 changes: 24 additions & 24 deletions vela/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,105 +15,105 @@ import (
type LogService service

// GetService returns the provided service log.
func (s *LogService) GetService(org, repo string, buildNum, serviceNum int) (*library.Log, *Response, error) {
func (svc *LogService) GetService(org, repo string, build, service int) (*library.Log, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/services/%d/logs", org, repo, buildNum, serviceNum)
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/services/%d/logs", org, repo, build, service)

// library Log type we want to return
v := new(library.Log)

// send request using client
resp, err := s.client.Call("GET", u, nil, v)
resp, err := svc.client.Call("GET", u, nil, v)
return v, resp, err
}

// AddService constructs a service log with the provided details.
func (s *LogService) AddService(org, repo string, buildNum, serviceNum int, target *library.Log) (*library.Log, *Response, error) {
func (svc *LogService) AddService(org, repo string, build, service int, l *library.Log) (*library.Log, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/services/%d/logs", org, repo, buildNum, serviceNum)
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/services/%d/logs", org, repo, build, service)

// library Log type we want to return
v := new(library.Log)

// send request using client
resp, err := s.client.Call("POST", u, target, v)
resp, err := svc.client.Call("POST", u, l, v)
return v, resp, err
}

// UpdateService modifies a service log with the provided details.
func (s *LogService) UpdateService(org, repo string, buildNum, serviceNum int, target *library.Log) (*library.Log, *Response, error) {
func (svc *LogService) UpdateService(org, repo string, build, service int, l *library.Log) (*library.Log, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/services/%d/logs", org, repo, buildNum, serviceNum)
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/services/%d/logs", org, repo, build, service)

// library Log type we want to return
v := new(library.Log)

// send request using client
resp, err := s.client.Call("PUT", u, target, v)
resp, err := svc.client.Call("PUT", u, l, v)
return v, resp, err
}

// RemoveService deletes the provided service log.
func (s *LogService) RemoveService(org, repo string, buildNum, serviceNum int) (*string, *Response, error) {
func (svc *LogService) RemoveService(org, repo string, build, service int) (*string, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/services/%d/logs", org, repo, buildNum, serviceNum)
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/services/%d/logs", org, repo, build, service)

// string type we want to return
v := new(string)

// send request using client
resp, err := s.client.Call("DELETE", u, nil, v)
resp, err := svc.client.Call("DELETE", u, nil, v)
return v, resp, err
}

// GetStep returns the provided step log.
func (s *LogService) GetStep(org, repo string, buildNum, stepNum int) (*library.Log, *Response, error) {
func (svc *LogService) GetStep(org, repo string, build, step int) (*library.Log, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/steps/%d/logs", org, repo, buildNum, stepNum)
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/steps/%d/logs", org, repo, build, step)

// library Log type we want to return
v := new(library.Log)

// send request using client
resp, err := s.client.Call("GET", u, nil, v)
resp, err := svc.client.Call("GET", u, nil, v)
return v, resp, err
}

// AddStep constructs a step log with the provided details.
func (s *LogService) AddStep(org, repo string, buildNum, stepNum int, target *library.Log) (*library.Log, *Response, error) {
func (svc *LogService) AddStep(org, repo string, build, step int, l *library.Log) (*library.Log, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/steps/%d/logs", org, repo, buildNum, stepNum)
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/steps/%d/logs", org, repo, build, step)

// library Log type we want to return
v := new(library.Log)

// send request using client
resp, err := s.client.Call("POST", u, target, v)
resp, err := svc.client.Call("POST", u, l, v)
return v, resp, err
}

// UpdateStep modifies a step log with the provided details.
func (s *LogService) UpdateStep(org, repo string, buildNum, stepNum int, target *library.Log) (*library.Log, *Response, error) {
func (svc *LogService) UpdateStep(org, repo string, build, step int, l *library.Log) (*library.Log, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/steps/%d/logs", org, repo, buildNum, stepNum)
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/steps/%d/logs", org, repo, build, step)

// library Log type we want to return
v := new(library.Log)

// send request using client
resp, err := s.client.Call("PUT", u, target, v)
resp, err := svc.client.Call("PUT", u, l, v)
return v, resp, err
}

// RemoveStep deletes the provided step log.
func (s *LogService) RemoveStep(org, repo string, buildNum, stepNum int) (*string, *Response, error) {
func (svc *LogService) RemoveStep(org, repo string, build, step int) (*string, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/steps/%d/logs", org, repo, buildNum, stepNum)
u := fmt.Sprintf("/api/v1/repos/%s/%s/builds/%d/steps/%d/logs", org, repo, build, step)

// string type we want to return
v := new(string)

// send request using client
resp, err := s.client.Call("DELETE", u, nil, v)
resp, err := svc.client.Call("DELETE", u, nil, v)
return v, resp, err
}
4 changes: 2 additions & 2 deletions vela/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
type AuthorizationService service

// Login constructs a build with the provided details.
func (s *AuthorizationService) Login(target *library.Login) (*library.Login, *Response, error) {
func (svc *AuthorizationService) Login(l *library.Login) (*library.Login, *Response, error) {
// set the API endpoint path we send the request to
u := fmt.Sprintf("/login")

// library Login type we want to return
v := new(library.Login)

// send request using client
resp, err := s.client.Call("POST", u, target, v)
resp, err := svc.client.Call("POST", u, l, v)
return v, resp, err
}
Loading

0 comments on commit 876d1d1

Please sign in to comment.