Skip to content

Commit

Permalink
chore: cleanup and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 committed Oct 29, 2024
1 parent 771d1a6 commit 51960e2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
6 changes: 3 additions & 3 deletions api/step/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func PlanSteps(ctx context.Context, database database.Interface, scm scm.Service
// iterate through all steps for each pipeline stage
for _, step := range stage.Steps {
// create the step object
s, err := planStep(ctx, database, scm, b, r, step, stage.Name)
s, err := planStep(ctx, database, scm, b, step, stage.Name)
if err != nil {
return steps, err
}
Expand All @@ -39,7 +39,7 @@ func PlanSteps(ctx context.Context, database database.Interface, scm scm.Service

// iterate through all pipeline steps
for _, step := range p.Steps {
s, err := planStep(ctx, database, scm, b, r, step, "")
s, err := planStep(ctx, database, scm, b, step, "")
if err != nil {
return steps, err
}
Expand All @@ -50,7 +50,7 @@ func PlanSteps(ctx context.Context, database database.Interface, scm scm.Service
return steps, nil
}

func planStep(ctx context.Context, database database.Interface, scm scm.Service, b *types.Build, r *types.Repo, c *pipeline.Container, stage string) (*types.Step, error) {
func planStep(ctx context.Context, database database.Interface, scm scm.Service, b *types.Build, c *pipeline.Container, stage string) (*types.Step, error) {
// create the step object
s := new(types.Step)
s.SetBuildID(b.GetID())
Expand Down
3 changes: 3 additions & 0 deletions constants/app_install.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-License-Identifier: Apache-2.0

// App Install vars.
package constants

// see: https://docs.github.com/en/rest/authentication/permissions-required-for-github-apps?apiVersion=2022-11-28
Expand Down
26 changes: 17 additions & 9 deletions scm/github/app_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ func (t *AppsTransport) RoundTrip(req *http.Request) (*http.Response, error) {
req.Header.Set("Authorization", "Bearer "+ss)
req.Header.Add("Accept", acceptHeader)

resp, err := t.tr.RoundTrip(req)
return resp, err
return t.tr.RoundTrip(req)
}

// Transport provides a http.RoundTripper by wrapping an existing
Expand Down Expand Up @@ -182,13 +181,14 @@ func (t *Transport) refreshToken(ctx context.Context) error {
// convert InstallationTokenOptions into a ReadWriter to pass as an argument to http.NewRequest
body, err := GetReadWriter(t.InstallationTokenOptions)
if err != nil {
return fmt.Errorf("could not convert installation token parameters into json: %s", err)
return fmt.Errorf("could not convert installation token parameters into json: %w", err)
}

requestURL := fmt.Sprintf("%s/app/installations/%v/access_tokens", strings.TrimRight(t.BaseURL, "/"), t.installationID)

req, err := http.NewRequest("POST", requestURL, body)
if err != nil {
return fmt.Errorf("could not create request: %s", err)
return fmt.Errorf("could not create request: %w", err)
}

// set Content and Accept headers
Expand Down Expand Up @@ -223,29 +223,37 @@ func (t *Transport) refreshToken(ctx context.Context) error {
// GetReadWriter converts a body interface into an io.ReadWriter object.
func GetReadWriter(i interface{}) (io.ReadWriter, error) {
var buf io.ReadWriter

if i != nil {
buf = new(bytes.Buffer)

enc := json.NewEncoder(buf)

err := enc.Encode(i)
if err != nil {
return nil, err
}
}

return buf, nil
}

// cloneRequest returns a clone of the provided *http.Request.
// The clone is a shallow copy of the struct and its Header map.
func cloneRequest(r *http.Request) *http.Request {
// shallow copy of the struct
r2 := new(http.Request)
*r2 = *r
_r := new(http.Request)

*_r = *r

// deep copy of the Header
r2.Header = make(http.Header, len(r.Header))
_r.Header = make(http.Header, len(r.Header))

for k, s := range r.Header {
r2.Header[k] = append([]string(nil), s...)
_r.Header[k] = append([]string(nil), s...)
}
return r2

return _r
}

// Signer is a JWT token signer. This is a wrapper around [jwt.SigningMethod] with predetermined
Expand Down

0 comments on commit 51960e2

Please sign in to comment.