Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up models #3228

Merged
merged 7 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions agent/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ func (r *Runner) createLogger(logger zerolog.Logger, uploads *sync.WaitGroup, wo

var secrets []string
for _, secret := range workflow.Config.Secrets {
if secret.Mask {
secrets = append(secrets, secret.Value)
}
secrets = append(secrets, secret.Value)
}

loglogger.Debug().Msg("log stream opened")
Expand Down
15 changes: 0 additions & 15 deletions cmd/server/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3784,9 +3784,6 @@ const docTemplate = `{
"refspec": {
"type": "string"
},
"remote": {
"type": "string"
},
"repo_id": {
"type": "integer"
},
Expand Down Expand Up @@ -3913,9 +3910,6 @@ const docTemplate = `{
"type": "string"
}
},
"clone_url": {
"type": "string"
},
"commit": {
"type": "string"
},
Expand All @@ -3925,9 +3919,6 @@ const docTemplate = `{
"deploy_to": {
"type": "string"
},
"enqueued_at": {
"type": "integer"
},
"errors": {
"type": "array",
"items": {
Expand Down Expand Up @@ -4037,18 +4028,12 @@ const docTemplate = `{
"address": {
"type": "string"
},
"email": {
"type": "string"
},
"id": {
"type": "integer"
},
"password": {
"type": "string"
},
"token": {
"type": "string"
},
"username": {
"type": "string"
}
Expand Down
2 changes: 1 addition & 1 deletion pipeline/backend/docker/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func TestToConfigFull(t *testing.T) {
OnFailure: true,
OnSuccess: true,
Failure: "fail",
AuthConfig: backend.Auth{Username: "user", Password: "123456", Email: "[email protected]"},
AuthConfig: backend.Auth{Username: "user", Password: "123456"},
NetworkMode: "bridge",
Ports: []backend.Port{{Number: 21}, {Number: 22}},
})
Expand Down
1 change: 0 additions & 1 deletion pipeline/backend/types/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ package types
type Auth struct {
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
Email string `json:"email,omitempty"`
}
1 change: 0 additions & 1 deletion pipeline/backend/types/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ package types
type Secret struct {
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
Mask bool `json:"mask,omitempty"`
}
1 change: 0 additions & 1 deletion pipeline/frontend/yaml/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ func (c *Compiler) Compile(conf *yaml_types.Workflow) (*backend_types.Config, er
config.Secrets = append(config.Secrets, &backend_types.Secret{
Name: sec.Name,
Value: sec.Value,
Mask: true,
})
}

Expand Down
1 change: 0 additions & 1 deletion pipeline/frontend/yaml/compiler/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ func (c *Compiler) createProcess(container *yaml_types.Container, stepType backe
if utils.MatchHostname(container.Image, registry.Hostname) {
authConfig.Username = registry.Username
authConfig.Password = registry.Password
authConfig.Email = registry.Email
break
}
}
Expand Down
8 changes: 0 additions & 8 deletions server/api/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ func PostRegistry(c *gin.Context) {
Address: in.Address,
Username: in.Username,
Password: in.Password,
Token: in.Token,
Email: in.Email,
}
if err := registry.Validate(); err != nil {
c.String(http.StatusBadRequest, "Error inserting registry. %s", err)
Expand Down Expand Up @@ -119,12 +117,6 @@ func PatchRegistry(c *gin.Context) {
if in.Password != "" {
registry.Password = in.Password
}
if in.Token != "" {
registry.Token = in.Token
}
if in.Email != "" {
registry.Email = in.Email
}

if err := registry.Validate(); err != nil {
c.String(http.StatusUnprocessableEntity, "Error updating registry. %s", err)
Expand Down
1 change: 0 additions & 1 deletion server/forge/bitbucket/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ func convertPullHook(from *internal.PullRequestHook) *model.Pipeline {
from.PullRequest.Source.Branch.Name,
from.PullRequest.Dest.Branch.Name,
),
CloneURL: fmt.Sprintf("https://bitbucket.org/%s", from.PullRequest.Source.Repo.FullName),
ForgeURL: from.PullRequest.Links.HTML.Href,
Branch: from.PullRequest.Dest.Branch.Name,
Message: from.PullRequest.Desc,
Expand Down
1 change: 0 additions & 1 deletion server/forge/bitbucket/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ func Test_helper(t *testing.T) {
g.Assert(pipeline.ForgeURL).Equal(hook.PullRequest.Links.HTML.Href)
g.Assert(pipeline.Ref).Equal("refs/heads/main")
g.Assert(pipeline.Refspec).Equal("change:main")
g.Assert(pipeline.CloneURL).Equal("https://bitbucket.org/baz/bar")
g.Assert(pipeline.Message).Equal(hook.PullRequest.Desc)
g.Assert(pipeline.Timestamp).Equal(hook.PullRequest.Updated.Unix())
})
Expand Down
2 changes: 0 additions & 2 deletions server/forge/github/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ func Test_helper(t *testing.T) {
g.Assert(pipeline.Branch).Equal(*from.PullRequest.Base.Ref)
g.Assert(pipeline.Ref).Equal("refs/pull/42/merge")
g.Assert(pipeline.Refspec).Equal("changes:main")
g.Assert(pipeline.CloneURL).Equal("https://github.com/octocat/hello-world-fork")
g.Assert(pipeline.Commit).Equal(*from.PullRequest.Head.SHA)
g.Assert(pipeline.Message).Equal(*from.PullRequest.Title)
g.Assert(pipeline.Title).Equal(*from.PullRequest.Title)
Expand Down Expand Up @@ -264,7 +263,6 @@ func Test_helper(t *testing.T) {
g.Assert(pipeline.Author).Equal(*from.Sender.Login)
g.Assert(pipeline.Avatar).Equal(*from.Sender.AvatarURL)
g.Assert(pipeline.Email).Equal(*from.HeadCommit.Author.Email)
g.Assert(pipeline.CloneURL).Equal(*from.Repo.CloneURL)
})

g.It("should convert a tag from webhook", func() {
Expand Down
2 changes: 0 additions & 2 deletions server/forge/github/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ func parsePushHook(hook *github.PushEvent) (*model.Repo, *model.Pipeline) {
Email: hook.GetHeadCommit().GetAuthor().GetEmail(),
Avatar: hook.GetSender().GetAvatarURL(),
Author: hook.GetSender().GetLogin(),
CloneURL: hook.GetRepo().GetCloneURL(),
Sender: hook.GetSender().GetLogin(),
ChangedFiles: getChangedFilesFromCommits(hook.Commits),
}
Expand Down Expand Up @@ -164,7 +163,6 @@ func parsePullHook(hook *github.PullRequestEvent, merge bool) (*github.PullReque
Avatar: hook.GetPullRequest().GetUser().GetAvatarURL(),
Title: hook.GetPullRequest().GetTitle(),
Sender: hook.GetSender().GetLogin(),
CloneURL: hook.GetPullRequest().GetHead().GetRepo().GetCloneURL(),
Refspec: fmt.Sprintf(refSpec,
hook.GetPullRequest().GetHead().GetRef(),
hook.GetPullRequest().GetBase().GetRef(),
Expand Down
1 change: 0 additions & 1 deletion server/forge/gitlab/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ func convertMergeRequestHook(hook *gitlab.MergeEvent, req *http.Request) (int, *

pipeline.Message = lastCommit.Message
pipeline.Commit = lastCommit.ID
pipeline.CloneURL = obj.Source.HTTPURL

pipeline.Ref = fmt.Sprintf(mergeRefs, obj.IID)
pipeline.Branch = obj.SourceBranch
Expand Down
16 changes: 8 additions & 8 deletions server/model/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ type Agent struct {
ID int64 `json:"id" xorm:"pk autoincr 'id'"`
Created int64 `json:"created" xorm:"created"`
Updated int64 `json:"updated" xorm:"updated"`
Name string `json:"name"`
Name string `json:"name" xorm:"name"`
OwnerID int64 `json:"owner_id" xorm:"'owner_id'"`
Token string `json:"token"`
LastContact int64 `json:"last_contact"`
Platform string `json:"platform" xorm:"VARCHAR(100)"`
Backend string `json:"backend" xorm:"VARCHAR(100)"`
Capacity int32 `json:"capacity"`
Version string `json:"version"`
NoSchedule bool `json:"no_schedule"`
Token string `json:"token" xorm:"token"`
LastContact int64 `json:"last_contact" xorm:"last_contact"`
Platform string `json:"platform" xorm:"VARCHAR(100) 'platform'"`
Backend string `json:"backend" xorm:"VARCHAR(100) 'backend'"`
Capacity int32 `json:"capacity" xorm:"capacity"`
Version string `json:"version" xorm:"version"`
NoSchedule bool `json:"no_schedule" xorm:"no_schedule"`
} // @name Agent

// TableName return database table name for xorm
Expand Down
2 changes: 0 additions & 2 deletions server/model/environ.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ type EnvironStore interface {

// Environ represents an environment variable.
type Environ struct {
ID int64 `json:"id"`
Name string `json:"name"`
Value string `json:"value,omitempty"`
}
Expand All @@ -56,7 +55,6 @@ func (e *Environ) Validate() error {
// Copy makes a copy of the environment variable without the value.
func (e *Environ) Copy() *Environ {
return &Environ{
ID: e.ID,
Name: e.Name,
}
}
1 change: 0 additions & 1 deletion server/model/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type Feed struct {
Branch string `json:"branch,omitempty" xorm:"feed_pipeline_branch"`
Ref string `json:"ref,omitempty" xorm:"feed_pipeline_ref"`
Refspec string `json:"refspec,omitempty" xorm:"feed_pipeline_refspec"`
Remote string `json:"remote,omitempty" xorm:"feed_pipeline_clone_url"`
Title string `json:"title,omitempty" xorm:"feed_pipeline_title"`
Message string `json:"message,omitempty" xorm:"feed_pipeline_message"`
Author string `json:"author,omitempty" xorm:"feed_pipeline_author"`
Expand Down
3 changes: 0 additions & 3 deletions server/model/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ type Pipeline struct {
RepoID int64 `json:"-" xorm:"UNIQUE(s) INDEX 'pipeline_repo_id'"`
Number int64 `json:"number" xorm:"UNIQUE(s) 'pipeline_number'"`
Author string `json:"author" xorm:"INDEX 'pipeline_author'"`
ConfigID int64 `json:"-" xorm:"pipeline_config_id"`
Parent int64 `json:"parent" xorm:"pipeline_parent"`
Event WebhookEvent `json:"event" xorm:"pipeline_event"`
Status StatusValue `json:"status" xorm:"INDEX 'pipeline_status'"`
Errors []*errors.PipelineError `json:"errors" xorm:"json 'pipeline_errors'"`
Enqueued int64 `json:"enqueued_at" xorm:"pipeline_enqueued"`
qwerty287 marked this conversation as resolved.
Show resolved Hide resolved
Created int64 `json:"created_at" xorm:"pipeline_created"`
Updated int64 `json:"updated_at" xorm:"updated NOT NULL DEFAULT 0 'updated'"`
Started int64 `json:"started_at" xorm:"pipeline_started"`
Expand All @@ -39,7 +37,6 @@ type Pipeline struct {
Branch string `json:"branch" xorm:"pipeline_branch"`
Ref string `json:"ref" xorm:"pipeline_ref"`
Refspec string `json:"refspec" xorm:"pipeline_refspec"`
CloneURL string `json:"clone_url" xorm:"pipeline_clone_url"`
anbraten marked this conversation as resolved.
Show resolved Hide resolved
Title string `json:"title" xorm:"pipeline_title"`
Message string `json:"message" xorm:"TEXT 'pipeline_message'"`
Timestamp int64 `json:"timestamp" xorm:"pipeline_timestamp"`
Expand Down
4 changes: 0 additions & 4 deletions server/model/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ type Registry struct {
Address string `json:"address" xorm:"UNIQUE(s) INDEX 'registry_addr'"`
Username string `json:"username" xorm:"varchar(2000) 'registry_username'"`
Password string `json:"password" xorm:"TEXT 'registry_password'"`
Token string `json:"token" xorm:"TEXT 'registry_token'"`
Email string `json:"email" xorm:"varchar(500) 'registry_email'"`
} // @name Registry

// Validate validates the registry information.
Expand All @@ -83,7 +81,5 @@ func (r *Registry) Copy() *Registry {
RepoID: r.RepoID,
Address: r.Address,
Username: r.Username,
Email: r.Email,
Token: r.Token,
}
}
2 changes: 0 additions & 2 deletions server/pipeline/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"context"
"errors"
"fmt"
"time"

"github.com/rs/zerolog/log"

Expand Down Expand Up @@ -130,7 +129,6 @@ func createNewOutOfOld(old *model.Pipeline) *model.Pipeline {
newPipeline.Status = model.StatusPending
newPipeline.Started = 0
newPipeline.Finished = 0
newPipeline.Enqueued = time.Now().UTC().Unix()
newPipeline.Errors = nil
return &newPipeline
}
1 change: 0 additions & 1 deletion server/pipeline/stepbuilder/stepBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ func (b *StepBuilder) toInternalRepresentation(parsed *yaml_types.Workflow, envi
Hostname: reg.Address,
Username: reg.Username,
Password: reg.Password,
Email: reg.Email,
})
}

Expand Down
1 change: 0 additions & 1 deletion server/store/datastore/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pipelines.pipeline_commit as feed_pipeline_commit,
pipelines.pipeline_branch as feed_pipeline_branch,
pipelines.pipeline_ref as feed_pipeline_ref,
pipelines.pipeline_refspec as feed_pipeline_refspec,
pipelines.pipeline_clone_url as feed_pipeline_clone_url,
pipelines.pipeline_title as feed_pipeline_title,
pipelines.pipeline_message as feed_pipeline_message,
pipelines.pipeline_author as feed_pipeline_author,
Expand Down
57 changes: 57 additions & 0 deletions server/store/datastore/migration/029_clean_registry_pipeline.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2024 Woodpecker Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package migration

import (
"src.techknowlogick.com/xormigrate"
"xorm.io/xorm"
)

type oldRegistry029 struct {
ID int64 `json:"id" xorm:"pk autoincr 'registry_id'"`
Token string `json:"token" xorm:"TEXT 'registry_token'"`
Email string `json:"email" xorm:"varchar(500) 'registry_email'"`
}

func (oldRegistry029) TableName() string {
return "registry"
}

type oldPipeline029 struct {
ID int64 `json:"id" xorm:"pk autoincr 'pipeline_id'"`
ConfigID int64 `json:"-" xorm:"pipeline_config_id"`
Enqueued int64 `json:"enqueued_at" xorm:"pipeline_enqueued"`
CloneURL string `json:"clone_url" xorm:"pipeline_clone_url"`
}

// TableName return database table name for xorm
func (oldPipeline029) TableName() string {
return "pipelines"
}

var cleanRegistryPipeline = xormigrate.Migration{
ID: "clean-registry-pipeline",
MigrateSession: func(sess *xorm.Session) (err error) {
if err := sess.Sync(new(oldRegistry029), new(oldPipeline029)); err != nil {
return err
}

if err := dropTableColumns(sess, "pipelines", "pipeline_clone_url", "pipeline_config_id", "pipeline_enqueued"); err != nil {
return err
}

return dropTableColumns(sess, "registry", "registry_email", "registry_token")
},
}
1 change: 1 addition & 0 deletions server/store/datastore/migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var migrationTasks = []*xormigrate.Migration{
&removePluginOnlyOptionFromSecretsTable,
&convertToNewPipelineErrorFormat,
&renameLinkToURL,
&cleanRegistryPipeline,
}

var allBeans = []any{
Expand Down
1 change: 0 additions & 1 deletion server/store/datastore/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ func (s storage) CreatePipeline(pipeline *model.Pipeline, stepList ...*model.Ste
pipeline.Number = number + 1

pipeline.Created = time.Now().UTC().Unix()
pipeline.Enqueued = pipeline.Created
// only Insert set auto created ID back to object
if _, err := sess.Insert(pipeline); err != nil {
return err
Expand Down
4 changes: 0 additions & 4 deletions server/store/datastore/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ func TestRegistryFind(t *testing.T) {
Address: "index.docker.io",
Username: "foo",
Password: "bar",
Email: "[email protected]",
Token: "12345",
})
assert.NoError(t, err)

Expand All @@ -43,8 +41,6 @@ func TestRegistryFind(t *testing.T) {
assert.Equal(t, "index.docker.io", registry.Address)
assert.Equal(t, "foo", registry.Username)
assert.Equal(t, "bar", registry.Password)
assert.Equal(t, "[email protected]", registry.Email)
assert.Equal(t, "12345", registry.Token)
}

func TestRegistryList(t *testing.T) {
Expand Down
3 changes: 0 additions & 3 deletions web/src/lib/api/types/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ export type Pipeline = {
// When the pipeline was updated last time in database.
updated_at: number;

// When the pipeline was enqueued.
enqueued_at: number;

// When the pipeline began execution.
started_at: number;

Expand Down
Loading