mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-04 14:48:42 +00:00
parent
203ef518df
commit
612eee8269
3 changed files with 22 additions and 3 deletions
|
@ -25,6 +25,12 @@ const (
|
||||||
EventManual WebhookEvent = "manual"
|
EventManual WebhookEvent = "manual"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type WebhookEventList []WebhookEvent
|
||||||
|
|
||||||
|
func (wel WebhookEventList) Len() int { return len(wel) }
|
||||||
|
func (wel WebhookEventList) Swap(i, j int) { wel[i], wel[j] = wel[j], wel[i] }
|
||||||
|
func (wel WebhookEventList) Less(i, j int) bool { return wel[i] < wel[j] }
|
||||||
|
|
||||||
func ValidateWebhookEvent(s WebhookEvent) bool {
|
func ValidateWebhookEvent(s WebhookEvent) bool {
|
||||||
switch s {
|
switch s {
|
||||||
case EventPush, EventPull, EventTag, EventDeploy, EventCron, EventManual:
|
case EventPush, EventPull, EventTag, EventDeploy, EventCron, EventManual:
|
||||||
|
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -83,6 +84,11 @@ func (Secret) TableName() string {
|
||||||
return "secrets"
|
return "secrets"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BeforeInsert will sort events before inserted into database
|
||||||
|
func (s *Secret) BeforeInsert() {
|
||||||
|
s.Events = sortEvents(s.Events)
|
||||||
|
}
|
||||||
|
|
||||||
// Global secret.
|
// Global secret.
|
||||||
func (s Secret) Global() bool {
|
func (s Secret) Global() bool {
|
||||||
return s.RepoID == 0 && s.Owner == ""
|
return s.RepoID == 0 && s.Owner == ""
|
||||||
|
@ -151,6 +157,11 @@ func (s *Secret) Copy() *Secret {
|
||||||
RepoID: s.RepoID,
|
RepoID: s.RepoID,
|
||||||
Name: s.Name,
|
Name: s.Name,
|
||||||
Images: s.Images,
|
Images: s.Images,
|
||||||
Events: s.Events,
|
Events: sortEvents(s.Events),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sortEvents(wel WebhookEventList) WebhookEventList {
|
||||||
|
sort.Sort(wel)
|
||||||
|
return wel
|
||||||
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ import (
|
||||||
"xorm.io/builder"
|
"xorm.io/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const orderSecretsBy = "secret_name"
|
||||||
|
|
||||||
func (s storage) SecretFind(repo *model.Repo, name string) (*model.Secret, error) {
|
func (s storage) SecretFind(repo *model.Repo, name string) (*model.Secret, error) {
|
||||||
secret := &model.Secret{
|
secret := &model.Secret{
|
||||||
RepoID: repo.ID,
|
RepoID: repo.ID,
|
||||||
|
@ -35,7 +37,7 @@ func (s storage) SecretList(repo *model.Repo, includeGlobalAndOrgSecrets bool) (
|
||||||
cond = cond.Or(builder.Eq{"secret_owner": repo.Owner}).
|
cond = cond.Or(builder.Eq{"secret_owner": repo.Owner}).
|
||||||
Or(builder.And(builder.Eq{"secret_owner": ""}, builder.Eq{"secret_repo_id": 0}))
|
Or(builder.And(builder.Eq{"secret_owner": ""}, builder.Eq{"secret_repo_id": 0}))
|
||||||
}
|
}
|
||||||
return secrets, s.engine.Where(cond).Find(&secrets)
|
return secrets, s.engine.Where(cond).OrderBy(orderSecretsBy).Find(&secrets)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s storage) SecretCreate(secret *model.Secret) error {
|
func (s storage) SecretCreate(secret *model.Secret) error {
|
||||||
|
@ -76,5 +78,5 @@ func (s storage) GlobalSecretFind(name string) (*model.Secret, error) {
|
||||||
|
|
||||||
func (s storage) GlobalSecretList() ([]*model.Secret, error) {
|
func (s storage) GlobalSecretList() ([]*model.Secret, error) {
|
||||||
secrets := make([]*model.Secret, 0, perPage)
|
secrets := make([]*model.Secret, 0, perPage)
|
||||||
return secrets, s.engine.Where(builder.And(builder.Eq{"secret_owner": ""}, builder.Eq{"secret_repo_id": 0})).Find(&secrets)
|
return secrets, s.engine.Where(builder.And(builder.Eq{"secret_owner": ""}, builder.Eq{"secret_repo_id": 0})).OrderBy(orderSecretsBy).Find(&secrets)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue