2015-09-30 03:21:17 +02:00
|
|
|
package engine
|
2015-05-05 10:04:20 +02:00
|
|
|
|
|
|
|
import (
|
2015-09-30 03:21:17 +02:00
|
|
|
"database/sql"
|
2015-05-06 04:46:26 +02:00
|
|
|
"encoding/json"
|
2015-05-11 09:45:31 +02:00
|
|
|
"fmt"
|
2015-05-05 10:04:20 +02:00
|
|
|
"io"
|
|
|
|
|
2015-09-30 03:21:17 +02:00
|
|
|
"github.com/drone/drone/model"
|
|
|
|
"github.com/drone/drone/remote"
|
2015-05-05 10:04:20 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type updater struct {
|
2015-09-30 03:21:17 +02:00
|
|
|
bus *eventbus
|
|
|
|
db *sql.DB
|
2015-05-10 05:46:32 +02:00
|
|
|
remote remote.Remote
|
2015-05-05 10:04:20 +02:00
|
|
|
}
|
|
|
|
|
2015-09-30 03:21:17 +02:00
|
|
|
func (u *updater) SetBuild(r *Task) error {
|
|
|
|
err := model.UpdateBuild(u.db, r.Build)
|
2015-05-05 10:04:20 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-05-06 04:46:26 +02:00
|
|
|
|
2015-09-30 03:21:17 +02:00
|
|
|
err = u.remote.Status(r.User, r.Repo, r.Build, fmt.Sprintf("%s/%s/%d", r.System.Link, r.Repo.FullName, r.Build.Number))
|
2015-05-13 08:58:30 +02:00
|
|
|
if err != nil {
|
|
|
|
// log err
|
|
|
|
}
|
2015-05-10 05:46:32 +02:00
|
|
|
|
2015-09-30 03:21:17 +02:00
|
|
|
msg, err := json.Marshal(&payload{r.Build, r.Jobs})
|
2015-05-06 04:46:26 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-09-30 03:21:17 +02:00
|
|
|
u.bus.send(&Event{
|
|
|
|
Name: r.Repo.FullName,
|
2015-05-06 04:46:26 +02:00
|
|
|
Msg: msg,
|
2015-05-05 10:04:20 +02:00
|
|
|
})
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-09-30 03:21:17 +02:00
|
|
|
func (u *updater) SetJob(r *Task) error {
|
|
|
|
err := model.UpdateJob(u.db, r.Job)
|
2015-05-05 10:04:20 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-05-06 04:46:26 +02:00
|
|
|
|
2015-09-30 03:21:17 +02:00
|
|
|
msg, err := json.Marshal(&payload{r.Build, r.Jobs})
|
2015-05-06 04:46:26 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-09-30 03:21:17 +02:00
|
|
|
u.bus.send(&Event{
|
|
|
|
Name: r.Repo.FullName,
|
2015-05-06 04:46:26 +02:00
|
|
|
Msg: msg,
|
2015-05-05 10:04:20 +02:00
|
|
|
})
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-09-30 03:21:17 +02:00
|
|
|
func (u *updater) SetLogs(r *Task, rc io.ReadCloser) error {
|
|
|
|
return model.SetLog(u.db, r.Job, rc)
|
|
|
|
}
|
|
|
|
|
|
|
|
type payload struct {
|
|
|
|
*model.Build
|
|
|
|
Jobs []*model.Job `json:"jobs"`
|
2015-05-05 10:04:20 +02:00
|
|
|
}
|