mirror of https://github.com/harness/drone.git
fix missed error and linting errors
parent
2369983dfe
commit
59e3bff412
|
@ -157,13 +157,13 @@ func SetupLogger(config *types.Config) {
|
|||
}
|
||||
|
||||
func SetupProfiler(config *types.Config) {
|
||||
profilerType, parsed := profiler.ParseProfiler(config.Profiler.Type)
|
||||
profilerType, parsed := profiler.ParseType(config.Profiler.Type)
|
||||
if !parsed {
|
||||
log.Info().Msgf("No valid profiler so skipping profiling ['%s']", config.Profiler.Type)
|
||||
return
|
||||
}
|
||||
|
||||
gitnessProfiler, _ := profiler.GetProfiler(profilerType)
|
||||
gitnessProfiler, _ := profiler.New(profilerType)
|
||||
gitnessProfiler.StartProfiling(config.Profiler.ServiceName, version.Version.String())
|
||||
}
|
||||
|
||||
|
|
|
@ -15,13 +15,15 @@ import (
|
|||
// ReviewerDelete deletes reviewer from the reviewerlist for the given PR.
|
||||
func (c *Controller) ReviewerDelete(ctx context.Context, session *auth.Session,
|
||||
repoRef string, prNum, reviewerID int64) error {
|
||||
|
||||
repo, err := c.getRepoCheckAccess(ctx, session, repoRef, enum.PermissionRepoEdit)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to acquire access to repo: %w", err)
|
||||
}
|
||||
|
||||
pr, err := c.pullreqStore.FindByNumber(ctx, repo.ID, prNum)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to find pull request: %w", err)
|
||||
}
|
||||
|
||||
err = c.reviewerStore.Delete(ctx, pr.ID, reviewerID)
|
||||
if err != nil {
|
||||
|
|
|
@ -412,17 +412,14 @@ func pullReqOperations(reflector *openapi3.Reflector) {
|
|||
reviewerDelete := openapi3.Operation{}
|
||||
reviewerDelete.WithTags("pullreq")
|
||||
reviewerDelete.WithMapOfAnything(map[string]interface{}{"operationId": "reviewerDeletePullReq"})
|
||||
err := reflector.SetRequest(&reviewerDelete, new(reviewerDeletePullReqRequest), http.MethodDelete)
|
||||
err = reflector.SetJSONResponse(&reviewerDelete, nil, http.StatusNoContent)
|
||||
err = reflector.SetJSONResponse(&reviewerDelete, new(usererror.Error), http.StatusBadRequest)
|
||||
err = reflector.SetJSONResponse(&reviewerDelete, new(usererror.Error), http.StatusInternalServerError)
|
||||
err = reflector.SetJSONResponse(&reviewerDelete, new(usererror.Error), http.StatusUnauthorized)
|
||||
err = reflector.SetJSONResponse(&reviewerDelete, new(usererror.Error), http.StatusForbidden)
|
||||
err = reflector.Spec.AddOperation(http.MethodDelete,
|
||||
_ = reflector.SetRequest(&reviewerDelete, new(reviewerDeletePullReqRequest), http.MethodDelete)
|
||||
_ = reflector.SetJSONResponse(&reviewerDelete, nil, http.StatusNoContent)
|
||||
_ = reflector.SetJSONResponse(&reviewerDelete, new(usererror.Error), http.StatusBadRequest)
|
||||
_ = reflector.SetJSONResponse(&reviewerDelete, new(usererror.Error), http.StatusInternalServerError)
|
||||
_ = reflector.SetJSONResponse(&reviewerDelete, new(usererror.Error), http.StatusUnauthorized)
|
||||
_ = reflector.SetJSONResponse(&reviewerDelete, new(usererror.Error), http.StatusForbidden)
|
||||
_ = reflector.Spec.AddOperation(http.MethodDelete,
|
||||
"/repos/{repo_ref}/pullreq/{pullreq_number}/reviewers/{pullreq_reviewer_id}", reviewerDelete)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
reviewSubmit := openapi3.Operation{}
|
||||
reviewSubmit.WithTags("pullreq")
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
// Copyright 2022 Harness Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Polyform Free Trial License
|
||||
// that can be found in the LICENSE.md file for this repository.
|
||||
|
||||
package profiler
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
// Copyright 2022 Harness Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Polyform Free Trial License
|
||||
// that can be found in the LICENSE.md file for this repository.
|
||||
|
||||
package profiler
|
||||
|
||||
import "github.com/rs/zerolog/log"
|
||||
|
@ -6,6 +10,5 @@ type NoopProfiler struct {
|
|||
}
|
||||
|
||||
func (noopProfiler *NoopProfiler) StartProfiling(serviceName, serviceVersion string) {
|
||||
//do nothing
|
||||
log.Info().Msg("Not starting profiler")
|
||||
}
|
||||
|
|
|
@ -1,27 +1,36 @@
|
|||
// Copyright 2022 Harness Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Polyform Free Trial License
|
||||
// that can be found in the LICENSE.md file for this repository.
|
||||
|
||||
package profiler
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Profiler interface {
|
||||
StartProfiling(serviceName, serviceVersion string)
|
||||
}
|
||||
|
||||
type ProfilerType string
|
||||
type Type string
|
||||
|
||||
const (
|
||||
ProfilerTypeGCP ProfilerType = "GCP"
|
||||
TypeGCP Type = "gcp"
|
||||
)
|
||||
|
||||
func ParseProfiler(profiler string) (ProfilerType, bool) {
|
||||
if profiler == string(ProfilerTypeGCP) {
|
||||
return ProfilerTypeGCP, true
|
||||
func ParseType(profilerType string) (Type, bool) {
|
||||
switch strings.TrimSpace(strings.ToLower(profilerType)) {
|
||||
case string(TypeGCP):
|
||||
return TypeGCP, true
|
||||
default:
|
||||
return "", false
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
func GetProfiler(profiler ProfilerType) (Profiler, error) {
|
||||
func New(profiler Type) (Profiler, error) {
|
||||
switch profiler {
|
||||
case ProfilerTypeGCP:
|
||||
case TypeGCP:
|
||||
return &GCPProfiler{}, nil
|
||||
default:
|
||||
return &NoopProfiler{}, fmt.Errorf("profiler '%s' not supported", profiler)
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
// Copyright 2022 Harness Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Polyform Free Trial License
|
||||
// that can be found in the LICENSE.md file for this repository.
|
||||
|
||||
package profiler
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestParseType(t *testing.T) {
|
||||
var tests = []struct {
|
||||
raw string
|
||||
expectedType Type
|
||||
expectedOk bool
|
||||
}{
|
||||
// basic invalid tests
|
||||
{"", Type(""), false},
|
||||
{"a", Type(""), false},
|
||||
{"g cp", Type(""), false},
|
||||
|
||||
// ensure case insensitivity
|
||||
{"gcp", TypeGCP, true},
|
||||
{"GCP", TypeGCP, true},
|
||||
|
||||
// ensure trim space works
|
||||
{" gcp ", TypeGCP, true},
|
||||
{" GCP ", TypeGCP, true},
|
||||
|
||||
// testing all valid values
|
||||
{"gcp", TypeGCP, true},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
parsedType, ok := ParseType(test.raw)
|
||||
|
||||
assert.Equal(t, test.expectedOk, ok, "test case %d with input '%s'", i, test.raw)
|
||||
assert.Equal(t, test.expectedType, parsedType, "test case %d with input '%s'", i, test.raw)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue