You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
989 B
Go
49 lines
989 B
Go
package uploader
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"git.awesome-for.me/liuzhiguo/drone-go/drone"
|
|
"git.awesome-for.me/liuzhiguo/runner-go/client"
|
|
"git.awesome-for.me/liuzhiguo/runner-go/internal"
|
|
"git.awesome-for.me/liuzhiguo/runner-go/pipeline"
|
|
)
|
|
|
|
var _ pipeline.Uploader = (*Upload)(nil)
|
|
|
|
type Upload struct {
|
|
client client.Client
|
|
}
|
|
|
|
func New(client client.Client) *Upload {
|
|
return &Upload{
|
|
client: client,
|
|
}
|
|
}
|
|
|
|
func (s *Upload) UploadCard(ctx context.Context, bytes []byte, state *pipeline.State, stepName string) error {
|
|
src := state.Find(stepName)
|
|
card := drone.CardInput{}
|
|
err := json.Unmarshal(bytes, &card)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = s.client.UploadCard(ctx, src.ID, &card)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// update step schema
|
|
state.Lock()
|
|
src.Schema = card.Schema
|
|
cpy := internal.CloneStep(src)
|
|
state.Unlock()
|
|
err = s.client.UpdateStep(ctx, cpy)
|
|
if err == nil {
|
|
state.Lock()
|
|
internal.MergeStep(cpy, src)
|
|
state.Unlock()
|
|
}
|
|
return nil
|
|
}
|