mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-13 12:06:29 +00:00
ba159976a0
1. server/login.go:49 (// TODO(bradrydzewski) return an error message instead). Added error message if authorization fails. 2. server/repos.go:178 (TODO(bradrydzewski) verify repo not exists). Added a checking for the repo and return an error in case it does not exist. 3. server/queue.go:170: // TODO (bradrydzewski) change this interface to accept an io.Reader. All references to the API change been in question SetLogs() have been modified. 4. remote/github/github.go:106 // Fixed a crash in case *repo_.Language is nil , when de-referencing it. This could happen when a repo only has a readme, so github hasn't set the language yet. 5. ./server/queue.go:170: // TODO (bradrydzewski) change this interface to accept an io.Reader. All references to the API change been in question SetLogs() have been modified. 6. .remote/github/github.go:106 // Fixed a crash in case *repo_.Language is nil , when de-referencing it. This could happen when a repo only has a readme, so github hasn't set the language yet.
87 lines
1.9 KiB
Go
87 lines
1.9 KiB
Go
package builtin
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
//"io/ioutil"
|
|
|
|
"github.com/drone/drone/common"
|
|
"github.com/drone/drone/datastore"
|
|
"github.com/drone/drone/eventbus"
|
|
)
|
|
|
|
type Updater interface {
|
|
SetBuild(*common.Repo, *common.Build) error
|
|
SetTask(*common.Repo, *common.Build, *common.Task) error
|
|
SetLogs(*common.Repo, *common.Build, *common.Task, io.ReadCloser) error
|
|
}
|
|
|
|
// NewUpdater returns an implementation of the Updater interface
|
|
// that directly modifies the database and sends messages to the bus.
|
|
func NewUpdater(bus eventbus.Bus, store datastore.Datastore) Updater {
|
|
return &updater{bus, store}
|
|
}
|
|
|
|
type updater struct {
|
|
bus eventbus.Bus
|
|
store datastore.Datastore
|
|
}
|
|
|
|
func (u *updater) SetBuild(r *common.Repo, b *common.Build) error {
|
|
err := u.store.SetBuildState(r.FullName, b)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// if the build is complete we may need to update
|
|
if b.State != common.StatePending && b.State != common.StateRunning {
|
|
repo, err := u.store.Repo(r.FullName)
|
|
if err == nil {
|
|
if repo.Last == nil || b.Number >= repo.Last.Number {
|
|
repo.Last = b
|
|
u.store.SetRepo(repo)
|
|
}
|
|
}
|
|
}
|
|
|
|
msg, err := json.Marshal(b)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
u.bus.Send(&eventbus.Event{
|
|
Name: r.FullName,
|
|
Kind: eventbus.EventRepo,
|
|
Msg: msg,
|
|
})
|
|
return nil
|
|
}
|
|
|
|
func (u *updater) SetTask(r *common.Repo, b *common.Build, t *common.Task) error {
|
|
err := u.store.SetBuildTask(r.FullName, b.Number, t)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
msg, err := json.Marshal(b)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
u.bus.Send(&eventbus.Event{
|
|
Name: r.FullName,
|
|
Kind: eventbus.EventRepo,
|
|
Msg: msg,
|
|
})
|
|
return nil
|
|
}
|
|
|
|
func (u *updater) SetLogs(r *common.Repo, b *common.Build, t *common.Task, rc io.ReadCloser) error {
|
|
//defer rc.Close()
|
|
//out, err := ioutil.ReadAll(rc)
|
|
//if err != nil {
|
|
// return err
|
|
//}
|
|
//return u.store.SetLogs(r.FullName, b.Number, t.Number, out)
|
|
return u.store.SetLogs(r.FullName, b.Number, t.Number, rc)
|
|
}
|