~bigbes/sr-ht-spec

ref: 61515a575dc7e931829c05eed0cd3c3a441df753 sr-ht-spec/graph/webhook_event.go -rw-r--r-- 1.4 KiB
61515a57 — Eugene Blikh chore(beads): file spec-ejq.2, CI publish blocked on missing apk-ci-s3 secret 24 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package graph

import (
	"time"

	"sourcecraft.dev/bigbes/sr-ht-spec/graph/model"
	"sourcecraft.dev/bigbes/sr-ht-spec/service"
)

// NewProposalEvent builds the webhook payload for a proposal lifecycle event.
// The cmd webhook sink calls it; it lives here because converting a
// service.Proposal to the GraphQL model.Proposal is this package's job.
//
// It composes the two existing conversions this package already owns: a
// service.Proposal is field-for-field a graph.Proposal (the same shape
// serviceProposals.ListProposals produces), and proposalModel maps a
// graph.Proposal to the *model.Proposal every GraphQL surface returns. Reusing
// them keeps the webhook payload identical to what a `proposals` query would
// serve for the same proposal.
func NewProposalEvent(event model.WebhookEvent, uuid string, date time.Time, p service.Proposal) (*model.ProposalEvent, error) {
	pm, err := proposalModel(Proposal{
		ID:           p.ID,
		Space:        p.Space,
		Title:        p.Title,
		Rationale:    p.Rationale,
		BaseRev:      p.BaseRev,
		Branch:       p.Branch,
		State:        p.State,
		Approval:     p.Approval,
		MergedRev:    p.MergedRev,
		Agent:        p.Agent,
		AgentSession: p.AgentSession,
		Created:      p.Created,
		Resolved:     p.Resolved,
	})
	if err != nil {
		return nil, err
	}
	return &model.ProposalEvent{
		UUID:     uuid,
		Event:    event,
		Date:     date,
		Proposal: pm,
	}, nil
}