~bigbes/sr-ht-spec

ref: cd1b8b014d4f88d3a972259e5bb7aee42d14013b sr-ht-spec/graph/model/models_gen.go -rw-r--r-- 4.6 KiB
cd1b8b01 — Eugene Blikh deps: auxilia whose scribe.Err reads the whole error chain 9 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.

package model

import (
	"fmt"
	"io"
	"strconv"
	"time"

	"sourcecraft.dev/bigbes/sr-ht-core/model"
)

// The payload delivered to a webhook: the event being dispatched, over which the
// subscription's `query` is evaluated.
type WebhookPayload interface {
	IsWebhookPayload()
}

// A webhook subscription: a URL and a GraphQL query evaluated in the webhook
// context when one of `events` fires.
type WebhookSubscription interface {
	IsWebhookSubscription()
}

type ProposalEvent struct {
	UUID     string       `json:"uuid"`
	Event    WebhookEvent `json:"event"`
	Date     time.Time    `json:"date"`
	Proposal *Proposal    `json:"proposal"`
}

func (ProposalEvent) IsWebhookPayload() {}

type UserWebhookInput struct {
	URL    string         `json:"url"`
	Events []WebhookEvent `json:"events"`
	Query  string         `json:"query"`
}

// A cursor for enumerating a list of webhook deliveries.
//
// If there are additional results available, the cursor object may be passed
// back into the same endpoint to retrieve another page. If the cursor is null,
// there are no remaining results to return.
type WebhookDeliveryCursor struct {
	Results []*WebhookDelivery `json:"results"`
	Cursor  *model.Cursor      `json:"cursor,omitempty"`
}

// A cursor for enumerating a list of webhook subscriptions.
//
// If there are additional results available, the cursor object may be passed
// back into the same endpoint to retrieve another page. If the cursor is null,
// there are no remaining results to return.
type WebhookSubscriptionCursor struct {
	Results []WebhookSubscription `json:"results"`
	Cursor  *model.Cursor         `json:"cursor,omitempty"`
}

// How a merge was authorized. Auto-merged is not human-approved, and readers must
// be able to tell: a bot asking for the approved text of a spec should be able to
// require human approval and get a different answer than for a firehose note.
type Approval string

const (
	ApprovalHuman  Approval = "HUMAN"
	ApprovalPolicy Approval = "POLICY"
)

var AllApproval = []Approval{
	ApprovalHuman,
	ApprovalPolicy,
}

func (e Approval) IsValid() bool {
	switch e {
	case ApprovalHuman, ApprovalPolicy:
		return true
	}
	return false
}

func (e Approval) String() string {
	return string(e)
}

func (e *Approval) UnmarshalGQL(v interface{}) error {
	str, ok := v.(string)
	if !ok {
		return fmt.Errorf("enums must be strings")
	}

	*e = Approval(str)
	if !e.IsValid() {
		return fmt.Errorf("%s is not a valid Approval", str)
	}
	return nil
}

func (e Approval) MarshalGQL(w io.Writer) {
	fmt.Fprint(w, strconv.Quote(e.String()))
}

// The lifecycle of a proposal. Collapsed from the usual five states because there
// is exactly one reviewer: "approve" is "merge now", and a proposal you dislike is
// rejected rather than sent back for changes.
type ProposalState string

const (
	ProposalStateOpen     ProposalState = "OPEN"
	ProposalStateMerged   ProposalState = "MERGED"
	ProposalStateRejected ProposalState = "REJECTED"
)

var AllProposalState = []ProposalState{
	ProposalStateOpen,
	ProposalStateMerged,
	ProposalStateRejected,
}

func (e ProposalState) IsValid() bool {
	switch e {
	case ProposalStateOpen, ProposalStateMerged, ProposalStateRejected:
		return true
	}
	return false
}

func (e ProposalState) String() string {
	return string(e)
}

func (e *ProposalState) UnmarshalGQL(v interface{}) error {
	str, ok := v.(string)
	if !ok {
		return fmt.Errorf("enums must be strings")
	}

	*e = ProposalState(str)
	if !e.IsValid() {
		return fmt.Errorf("%s is not a valid ProposalState", str)
	}
	return nil
}

func (e ProposalState) MarshalGQL(w io.Writer) {
	fmt.Fprint(w, strconv.Quote(e.String()))
}

// A proposal lifecycle event a webhook may subscribe to.
type WebhookEvent string

const (
	WebhookEventProposalOpened   WebhookEvent = "PROPOSAL_OPENED"
	WebhookEventProposalMerged   WebhookEvent = "PROPOSAL_MERGED"
	WebhookEventProposalRejected WebhookEvent = "PROPOSAL_REJECTED"
)

var AllWebhookEvent = []WebhookEvent{
	WebhookEventProposalOpened,
	WebhookEventProposalMerged,
	WebhookEventProposalRejected,
}

func (e WebhookEvent) IsValid() bool {
	switch e {
	case WebhookEventProposalOpened, WebhookEventProposalMerged, WebhookEventProposalRejected:
		return true
	}
	return false
}

func (e WebhookEvent) String() string {
	return string(e)
}

func (e *WebhookEvent) UnmarshalGQL(v interface{}) error {
	str, ok := v.(string)
	if !ok {
		return fmt.Errorf("enums must be strings")
	}

	*e = WebhookEvent(str)
	if !e.IsValid() {
		return fmt.Errorf("%s is not a valid WebhookEvent", str)
	}
	return nil
}

func (e WebhookEvent) MarshalGQL(w io.Writer) {
	fmt.Fprint(w, strconv.Quote(e.String()))
}