Write is a util function which writes execution and pipeline state to the check store.
( ctx context.Context, checkStore store.CheckStore, execution *types.Execution, pipeline *types.Pipeline, )
| 28 | // Write is a util function which writes execution and pipeline state to the |
| 29 | // check store. |
| 30 | func Write( |
| 31 | ctx context.Context, |
| 32 | checkStore store.CheckStore, |
| 33 | execution *types.Execution, |
| 34 | pipeline *types.Pipeline, |
| 35 | ) error { |
| 36 | payload := types.CheckPayloadInternal{ |
| 37 | Number: execution.Number, |
| 38 | RepoID: execution.RepoID, |
| 39 | PipelineID: execution.PipelineID, |
| 40 | } |
| 41 | data, err := json.Marshal(payload) |
| 42 | if err != nil { |
| 43 | return fmt.Errorf("could not marshal check payload: %w", err) |
| 44 | } |
| 45 | now := time.Now().UnixMilli() |
| 46 | summary := pipeline.Description |
| 47 | if summary == "" { |
| 48 | summary = pipeline.Identifier |
| 49 | } |
| 50 | check := &types.Check{ |
| 51 | RepoID: execution.RepoID, |
| 52 | Identifier: pipeline.Identifier, |
| 53 | Summary: summary, |
| 54 | Created: now, |
| 55 | Updated: now, |
| 56 | CreatedBy: execution.CreatedBy, |
| 57 | Status: execution.Status.ConvertToCheckStatus(), |
| 58 | CommitSHA: execution.After, |
| 59 | Metadata: []byte("{}"), |
| 60 | Payload: types.CheckPayload{ |
| 61 | Version: "1", |
| 62 | Kind: enum.CheckPayloadKindPipeline, |
| 63 | Data: data, |
| 64 | }, |
| 65 | } |
| 66 | err = checkStore.Upsert(ctx, check) |
| 67 | if err != nil { |
| 68 | return fmt.Errorf("could not upsert to check store: %w", err) |
| 69 | } |
| 70 | return nil |
| 71 | } |
no test coverage detected
searching dependent graphs…