Skip to content

Commit

Permalink
Merge branch 'master' into drop-coding
Browse files Browse the repository at this point in the history
  • Loading branch information
6543 committed Mar 19, 2023
2 parents c922968 + 51168db commit 02f4615
Show file tree
Hide file tree
Showing 61 changed files with 713 additions and 556 deletions.
50 changes: 29 additions & 21 deletions agent/rpc/client_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ func (c *client) Next(ctx context.Context, f rpc.Filter) (*rpc.Pipeline, error)
res, err = c.client.Next(ctx, req)
if err == nil {
break
}

// TODO: remove after adding continuous data exchange by something like #536
if strings.Contains(err.Error(), "\"too_many_pings\"") {
// https://github.com/woodpecker-ci/woodpecker/issues/717#issuecomment-1049365104
log.Trace().Err(err).Msg("grpc: to many keepalive pings without sending data")
} else {
// TODO: remove after adding continuous data exchange by something like #536
if strings.Contains(err.Error(), "\"too_many_pings\"") {
// https://github.com/woodpecker-ci/woodpecker/issues/717#issuecomment-1049365104
log.Trace().Err(err).Msg("grpc: to many keepalive pings without sending data")
} else {
log.Err(err).Msgf("grpc error: done(): code: %v: %s", status.Code(err), err)
}
log.Err(err).Msgf("grpc error: done(): code: %v: %s", status.Code(err), err)
}

switch status.Code(err) {
case
codes.Aborted,
Expand Down Expand Up @@ -94,9 +95,10 @@ func (c *client) Wait(ctx context.Context, id string) (err error) {
_, err = c.client.Wait(ctx, req)
if err == nil {
break
} else {
log.Err(err).Msgf("grpc error: wait(): code: %v: %s", status.Code(err), err)
}

log.Err(err).Msgf("grpc error: wait(): code: %v: %s", status.Code(err), err)

switch status.Code(err) {
case
codes.Aborted,
Expand Down Expand Up @@ -128,9 +130,10 @@ func (c *client) Init(ctx context.Context, id string, state rpc.State) (err erro
_, err = c.client.Init(ctx, req)
if err == nil {
break
} else {
log.Err(err).Msgf("grpc error: init(): code: %v: %s", status.Code(err), err)
}

log.Err(err).Msgf("grpc error: init(): code: %v: %s", status.Code(err), err)

switch status.Code(err) {
case
codes.Aborted,
Expand Down Expand Up @@ -162,9 +165,10 @@ func (c *client) Done(ctx context.Context, id string, state rpc.State) (err erro
_, err = c.client.Done(ctx, req)
if err == nil {
break
} else {
log.Err(err).Msgf("grpc error: done(): code: %v: %s", status.Code(err), err)
}

log.Err(err).Msgf("grpc error: done(): code: %v: %s", status.Code(err), err)

switch status.Code(err) {
case
codes.Aborted,
Expand All @@ -189,9 +193,10 @@ func (c *client) Extend(ctx context.Context, id string) (err error) {
_, err = c.client.Extend(ctx, req)
if err == nil {
break
} else {
log.Err(err).Msgf("grpc error: extend(): code: %v: %s", status.Code(err), err)
}

log.Err(err).Msgf("grpc error: extend(): code: %v: %s", status.Code(err), err)

switch status.Code(err) {
case
codes.Aborted,
Expand Down Expand Up @@ -223,9 +228,10 @@ func (c *client) Update(ctx context.Context, id string, state rpc.State) (err er
_, err = c.client.Update(ctx, req)
if err == nil {
break
} else {
log.Err(err).Msgf("grpc error: update(): code: %v: %s", status.Code(err), err)
}

log.Err(err).Msgf("grpc error: update(): code: %v: %s", status.Code(err), err)

switch status.Code(err) {
case
codes.Aborted,
Expand Down Expand Up @@ -258,9 +264,10 @@ func (c *client) Upload(ctx context.Context, id string, file *rpc.File) (err err
_, err = c.client.Upload(ctx, req)
if err == nil {
break
} else {
log.Err(err).Msgf("grpc error: upload(): code: %v: %s", status.Code(err), err)
}

log.Err(err).Msgf("grpc error: upload(): code: %v: %s", status.Code(err), err)

switch status.Code(err) {
case
codes.Aborted,
Expand Down Expand Up @@ -290,9 +297,10 @@ func (c *client) Log(ctx context.Context, id string, line *rpc.Line) (err error)
_, err = c.client.Log(ctx, req)
if err == nil {
break
} else {
log.Err(err).Msgf("grpc error: log(): code: %v: %s", status.Code(err), err)
}

log.Err(err).Msgf("grpc error: log(): code: %v: %s", status.Code(err), err)

switch status.Code(err) {
case
codes.Aborted,
Expand Down
6 changes: 1 addition & 5 deletions cli/pipeline/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,5 @@ func pipelineCreate(c *cli.Context) error {
return err
}

if err := tmpl.Execute(os.Stdout, pipeline); err != nil {
return err
}

return nil
return tmpl.Execute(os.Stdout, pipeline)
}
6 changes: 3 additions & 3 deletions cmd/agent/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ func init() {
http.HandleFunc("/version", handleVersion)
}

func handleHeartbeat(w http.ResponseWriter, r *http.Request) {
func handleHeartbeat(w http.ResponseWriter, _ *http.Request) {
if counter.Healthy() {
w.WriteHeader(200)
} else {
w.WriteHeader(500)
}
}

func handleVersion(w http.ResponseWriter, r *http.Request) {
func handleVersion(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(200)
w.Header().Add("Content-Type", "text/json")
_ = json.NewEncoder(w).Encode(versionResp{
Expand All @@ -54,7 +54,7 @@ func handleVersion(w http.ResponseWriter, r *http.Request) {
})
}

func handleStats(w http.ResponseWriter, r *http.Request) {
func handleStats(w http.ResponseWriter, _ *http.Request) {
if counter.Healthy() {
w.WriteHeader(200)
} else {
Expand Down
6 changes: 3 additions & 3 deletions cmd/server/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ func setupStore(c *cli.Context) (store.Store, error) {
}

if driver == "sqlite3" {
if new, err := fallbackSqlite3File(datasource); err != nil {
if newDatasource, err := fallbackSqlite3File(datasource); err != nil {
log.Fatal().Err(err).Msg("fallback to old sqlite3 file failed")
} else {
datasource = new
datasource = newDatasource
}
}

Expand Down Expand Up @@ -177,7 +177,7 @@ func setupRegistryService(c *cli.Context, s store.Store) model.RegistryService {
return registry.New(s)
}

func setupEnvironService(c *cli.Context, s store.Store) model.EnvironService {
func setupEnvironService(c *cli.Context, _ store.Store) model.EnvironService {
return environments.Parse(c.StringSlice("environment"))
}

Expand Down
3 changes: 1 addition & 2 deletions pipeline/backend/docker/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ func TestSplitVolumeParts(t *testing.T) {
}
for _, test := range testdata {
results, err := splitVolumeParts(test.from)
if test.success == (err != nil) {
} else {
if test.success != (err == nil) {
if reflect.DeepEqual(results, test.to) != test.success {
t.Errorf("Expect %q matches %q is %v", test.from, results, test.to)
}
Expand Down
2 changes: 1 addition & 1 deletion pipeline/backend/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (e *local) Load() error {
}

// Setup the pipeline environment.
func (e *local) Setup(ctx context.Context, config *types.Config) error {
func (e *local) Setup(_ context.Context, _ *types.Config) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pipeline/backend/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (e *ssh) Load() error {
}

// Setup the pipeline environment.
func (e *ssh) Setup(ctx context.Context, config *types.Config) error {
func (e *ssh) Setup(_ context.Context, _ *types.Config) error {
return nil
}

Expand Down
72 changes: 36 additions & 36 deletions pipeline/drone_compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,49 @@ package pipeline
// layer. Main purpose is to be compatible with drone plugins.
func SetDroneEnviron(env map[string]string) {
// webhook
copy("CI_COMMIT_BRANCH", "DRONE_BRANCH", env)
copy("CI_COMMIT_PULL_REQUEST", "DRONE_PULL_REQUEST", env)
copy("CI_COMMIT_TAG", "DRONE_TAG", env)
copy("CI_COMMIT_SOURCE_BRANCH", "DRONE_SOURCE_BRANCH", env)
copy("CI_COMMIT_TARGET_BRANCH", "DRONE_TARGET_BRANCH", env)
copyEnv("CI_COMMIT_BRANCH", "DRONE_BRANCH", env)
copyEnv("CI_COMMIT_PULL_REQUEST", "DRONE_PULL_REQUEST", env)
copyEnv("CI_COMMIT_TAG", "DRONE_TAG", env)
copyEnv("CI_COMMIT_SOURCE_BRANCH", "DRONE_SOURCE_BRANCH", env)
copyEnv("CI_COMMIT_TARGET_BRANCH", "DRONE_TARGET_BRANCH", env)
// pipeline
copy("CI_PIPELINE_NUMBER", "DRONE_BUILD_NUMBER", env)
copy("CI_PIPELINE_PARENT", "DRONE_BUILD_PARENT", env)
copy("CI_PIPELINE_EVENT", "DRONE_BUILD_EVENT", env)
copy("CI_PIPELINE_STATUS", "DRONE_BUILD_STATUS", env)
copy("CI_PIPELINE_LINK", "DRONE_BUILD_LINK", env)
copy("CI_PIPELINE_CREATED", "DRONE_BUILD_CREATED", env)
copy("CI_PIPELINE_STARTED", "DRONE_BUILD_STARTED", env)
copy("CI_PIPELINE_FINISHED", "DRONE_BUILD_FINISHED", env)
copyEnv("CI_PIPELINE_NUMBER", "DRONE_BUILD_NUMBER", env)
copyEnv("CI_PIPELINE_PARENT", "DRONE_BUILD_PARENT", env)
copyEnv("CI_PIPELINE_EVENT", "DRONE_BUILD_EVENT", env)
copyEnv("CI_PIPELINE_STATUS", "DRONE_BUILD_STATUS", env)
copyEnv("CI_PIPELINE_LINK", "DRONE_BUILD_LINK", env)
copyEnv("CI_PIPELINE_CREATED", "DRONE_BUILD_CREATED", env)
copyEnv("CI_PIPELINE_STARTED", "DRONE_BUILD_STARTED", env)
copyEnv("CI_PIPELINE_FINISHED", "DRONE_BUILD_FINISHED", env)
// commit
copy("CI_COMMIT_SHA", "DRONE_COMMIT", env)
copy("CI_COMMIT_SHA", "DRONE_COMMIT_SHA", env)
copy("CI_PREV_COMMIT_SHA", "DRONE_COMMIT_BEFORE", env)
copy("CI_COMMIT_REF", "DRONE_COMMIT_REF", env)
copy("CI_COMMIT_BRANCH", "DRONE_COMMIT_BRANCH", env)
copy("CI_COMMIT_LINK", "DRONE_COMMIT_LINK", env)
copy("CI_COMMIT_MESSAGE", "DRONE_COMMIT_MESSAGE", env)
copy("CI_COMMIT_AUTHOR", "DRONE_COMMIT_AUTHOR", env)
copy("CI_COMMIT_AUTHOR", "DRONE_COMMIT_AUTHOR_NAME", env)
copy("CI_COMMIT_AUTHOR_EMAIL", "DRONE_COMMIT_AUTHOR_EMAIL", env)
copy("CI_COMMIT_AUTHOR_AVATAR", "DRONE_COMMIT_AUTHOR_AVATAR", env)
copyEnv("CI_COMMIT_SHA", "DRONE_COMMIT", env)
copyEnv("CI_COMMIT_SHA", "DRONE_COMMIT_SHA", env)
copyEnv("CI_PREV_COMMIT_SHA", "DRONE_COMMIT_BEFORE", env)
copyEnv("CI_COMMIT_REF", "DRONE_COMMIT_REF", env)
copyEnv("CI_COMMIT_BRANCH", "DRONE_COMMIT_BRANCH", env)
copyEnv("CI_COMMIT_LINK", "DRONE_COMMIT_LINK", env)
copyEnv("CI_COMMIT_MESSAGE", "DRONE_COMMIT_MESSAGE", env)
copyEnv("CI_COMMIT_AUTHOR", "DRONE_COMMIT_AUTHOR", env)
copyEnv("CI_COMMIT_AUTHOR", "DRONE_COMMIT_AUTHOR_NAME", env)
copyEnv("CI_COMMIT_AUTHOR_EMAIL", "DRONE_COMMIT_AUTHOR_EMAIL", env)
copyEnv("CI_COMMIT_AUTHOR_AVATAR", "DRONE_COMMIT_AUTHOR_AVATAR", env)
// repo
copy("CI_REPO", "DRONE_REPO", env)
copy("CI_REPO_SCM", "DRONE_REPO_SCM", env)
copy("CI_REPO_OWNER", "DRONE_REPO_OWNER", env)
copy("CI_REPO_NAME", "DRONE_REPO_NAME", env)
copy("CI_REPO_LINK", "DRONE_REPO_LINK", env)
copy("CI_REPO_DEFAULT_BRANCH", "DRONE_REPO_BRANCH", env)
copy("CI_REPO_PRIVATE", "DRONE_REPO_PRIVATE", env)
copyEnv("CI_REPO", "DRONE_REPO", env)
copyEnv("CI_REPO_SCM", "DRONE_REPO_SCM", env)
copyEnv("CI_REPO_OWNER", "DRONE_REPO_OWNER", env)
copyEnv("CI_REPO_NAME", "DRONE_REPO_NAME", env)
copyEnv("CI_REPO_LINK", "DRONE_REPO_LINK", env)
copyEnv("CI_REPO_DEFAULT_BRANCH", "DRONE_REPO_BRANCH", env)
copyEnv("CI_REPO_PRIVATE", "DRONE_REPO_PRIVATE", env)
// clone
copy("CI_REPO_CLONE_URL", "DRONE_REMOTE_URL", env)
copy("CI_REPO_CLONE_URL", "DRONE_GIT_HTTP_URL", env)
copyEnv("CI_REPO_CLONE_URL", "DRONE_REMOTE_URL", env)
copyEnv("CI_REPO_CLONE_URL", "DRONE_GIT_HTTP_URL", env)
// misc
copy("CI_SYSTEM_HOST", "DRONE_SYSTEM_HOST", env)
copy("CI_STEP_NUMBER", "DRONE_STEP_NUMBER", env)
copyEnv("CI_SYSTEM_HOST", "DRONE_SYSTEM_HOST", env)
copyEnv("CI_STEP_NUMBER", "DRONE_STEP_NUMBER", env)
}

func copy(woodpecker, drone string, env map[string]string) {
func copyEnv(woodpecker, drone string, env map[string]string) {
var present bool
var value string

Expand Down
4 changes: 2 additions & 2 deletions pipeline/frontend/yaml/compiler/cacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type s3Cacher struct {
region string
}

func (c *s3Cacher) Restore(repo, branch string, mounts []string) *yaml.Container {
func (c *s3Cacher) Restore(_, _ string, mounts []string) *yaml.Container {
return &yaml.Container{
Name: "rebuild_cache",
Image: "plugins/s3-cache:latest",
Expand All @@ -87,7 +87,7 @@ func (c *s3Cacher) Restore(repo, branch string, mounts []string) *yaml.Container
}
}

func (c *s3Cacher) Rebuild(repo, branch string, mounts []string) *yaml.Container {
func (c *s3Cacher) Rebuild(_, _ string, mounts []string) *yaml.Container {
return &yaml.Container{
Name: "rebuild_cache",
Image: "plugins/s3-cache:latest",
Expand Down
7 changes: 2 additions & 5 deletions pipeline/frontend/yaml/linter/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@ func (l *Linter) Lint(c *yaml.Config) error {
if err := l.lint(c.Pipeline.Containers, blockPipeline); err != nil {
return err
}
if err := l.lint(c.Services.Containers, blockServices); err != nil {
return err
}
return nil
return l.lint(c.Services.Containers, blockServices)
}

func (l *Linter) lint(containers []*yaml.Container, block uint8) error {
func (l *Linter) lint(containers []*yaml.Container, _ uint8) error {
for _, container := range containers {
if err := l.lintImage(container); err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions server/api/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func HandleAuth(c *gin.Context) {
u.Secret = tmpuser.Secret
u.Email = tmpuser.Email
u.Avatar = tmpuser.Avatar
u.Admin = u.Admin || config.IsAdmin(tmpuser)

// if self-registration is enabled for whitelisted organizations we need to
// check the user's organization membership.
Expand Down
8 changes: 6 additions & 2 deletions server/api/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ func PatchUser(c *gin.Context) {
c.AbortWithStatus(http.StatusNotFound)
return
}
user.Active = in.Active

// TODO: allow to change login (currently used as primary key)
// TODO: disallow to change login, email, avatar if the user is using oauth
user.Email = in.Email
user.Avatar = in.Avatar
user.Admin = in.Admin

err = _store.UpdateUser(user)
if err != nil {
Expand All @@ -77,7 +82,6 @@ func PostUser(c *gin.Context) {
return
}
user := &model.User{
Active: true,
Login: in.Login,
Email: in.Email,
Avatar: in.Avatar,
Expand Down
10 changes: 5 additions & 5 deletions server/forge/bitbucket/bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,12 @@ func (c *config) File(ctx context.Context, u *model.User, r *model.Repo, p *mode
return []byte(*config), err
}

func (c *config) Dir(ctx context.Context, u *model.User, r *model.Repo, p *model.Pipeline, f string) ([]*forge_types.FileMeta, error) {
func (c *config) Dir(_ context.Context, _ *model.User, _ *model.Repo, _ *model.Pipeline, _ string) ([]*forge_types.FileMeta, error) {
return nil, forge_types.ErrNotImplemented
}

// Status creates a pipeline status for the Bitbucket commit.
func (c *config) Status(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, step *model.Step) error {
func (c *config) Status(ctx context.Context, user *model.User, repo *model.Repo, pipeline *model.Pipeline, _ *model.Step) error {
status := internal.PipelineStatus{
State: convertStatus(pipeline.Status),
Desc: common.GetPipelineStatusDescription(pipeline.Status),
Expand Down Expand Up @@ -274,7 +274,7 @@ func (c *config) Deactivate(ctx context.Context, u *model.User, r *model.Repo, l

// Netrc returns a netrc file capable of authenticating Bitbucket requests and
// cloning Bitbucket repositories.
func (c *config) Netrc(u *model.User, r *model.Repo) (*model.Netrc, error) {
func (c *config) Netrc(u *model.User, _ *model.Repo) (*model.Netrc, error) {
return &model.Netrc{
Machine: "bitbucket.org",
Login: "x-token-auth",
Expand All @@ -297,14 +297,14 @@ func (c *config) Branches(ctx context.Context, u *model.User, r *model.Repo) ([]
}

// BranchHead returns the sha of the head (latest commit) of the specified branch
func (c *config) BranchHead(ctx context.Context, u *model.User, r *model.Repo, branch string) (string, error) {
func (c *config) BranchHead(_ context.Context, _ *model.User, _ *model.Repo, _ string) (string, error) {
// TODO(1138): missing implementation
return "", forge_types.ErrNotImplemented
}

// Hook parses the incoming Bitbucket hook and returns the Repository and
// Pipeline details. If the hook is unsupported nil values are returned.
func (c *config) Hook(ctx context.Context, req *http.Request) (*model.Repo, *model.Pipeline, error) {
func (c *config) Hook(_ context.Context, req *http.Request) (*model.Repo, *model.Pipeline, error) {
return parseHook(req)
}

Expand Down
Loading

0 comments on commit 02f4615

Please sign in to comment.