| 1 |
|
package graph |
| 2 |
|
|
| 3 |
|
import ( |
| 4 |
|
"time" |
| 5 |
|
|
| 6 |
|
"sourcecraft.dev/bigbes/sr-ht-spec/graph/model" |
| 7 |
|
"sourcecraft.dev/bigbes/sr-ht-spec/service" |
| 8 |
|
) |
| 9 |
|
|
| 10 |
|
// NewProposalEvent builds the webhook payload for a proposal lifecycle event. |
| 11 |
|
// The cmd webhook sink calls it; it lives here because converting a |
| 12 |
|
// service.Proposal to the GraphQL model.Proposal is this package's job. |
| 13 |
|
// |
| 14 |
|
// It composes the two existing conversions this package already owns: a |
| 15 |
|
// service.Proposal is field-for-field a graph.Proposal (the same shape |
| 16 |
|
// serviceProposals.ListProposals produces), and proposalModel maps a |
| 17 |
|
// graph.Proposal to the *model.Proposal every GraphQL surface returns. Reusing |
| 18 |
|
// them keeps the webhook payload identical to what a `proposals` query would |
| 19 |
|
// serve for the same proposal. |
| 20 |
0 |
func NewProposalEvent(event model.WebhookEvent, uuid string, date time.Time, p service.Proposal) (*model.ProposalEvent, error) { |
| 21 |
0 |
pm, err := proposalModel(Proposal{ |
| 22 |
0 |
ID: p.ID, |
| 23 |
0 |
Space: p.Space, |
| 24 |
0 |
Title: p.Title, |
| 25 |
0 |
Rationale: p.Rationale, |
| 26 |
0 |
BaseRev: p.BaseRev, |
| 27 |
0 |
Branch: p.Branch, |
| 28 |
0 |
State: p.State, |
| 29 |
0 |
Approval: p.Approval, |
| 30 |
0 |
MergedRev: p.MergedRev, |
| 31 |
0 |
Agent: p.Agent, |
| 32 |
0 |
AgentSession: p.AgentSession, |
| 33 |
0 |
Created: p.Created, |
| 34 |
0 |
Resolved: p.Resolved, |
| 35 |
0 |
}) |
| 36 |
0 |
if err != nil { |
| 37 |
0 |
return nil, err |
| 38 |
0 |
} |
| 39 |
0 |
return &model.ProposalEvent{ |
| 40 |
0 |
UUID: uuid, |
| 41 |
0 |
Event: event, |
| 42 |
0 |
Date: date, |
| 43 |
0 |
Proposal: pm, |
| 44 |
0 |
}, nil |
| 45 |
|
} |