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