This repository has no description
1package models
2
3import (
4 "slices"
5 "time"
6
7 "github.com/bluesky-social/indigo/atproto/syntax"
8)
9
10type WebhookEvent string
11
12const (
13 WebhookEventPush WebhookEvent = "push"
14 WebhookEventRepoRenamed WebhookEvent = "repository:renamed"
15 WebhookEventPullRequestCreated WebhookEvent = "pull_request:created"
16 WebhookEventPullRequestResubmitted WebhookEvent = "pull_request:resubmitted"
17 WebhookEventPullRequestMerged WebhookEvent = "pull_request:merged"
18 WebhookEventPullRequestClosed WebhookEvent = "pull_request:closed"
19 WebhookEventPullRequestReopened WebhookEvent = "pull_request:reopened"
20)
21
22type Webhook struct {
23 Id int64
24 RepoDid syntax.DID
25 Url string
26 Secret string
27 Active bool
28 Events []string // comma-separated event types
29 CreatedAt time.Time
30 UpdatedAt time.Time
31}
32
33// HasEvent checks if the webhook is subscribed to a specific event
34func (w *Webhook) HasEvent(event WebhookEvent) bool {
35 return slices.Contains(w.Events, string(event))
36}
37
38type WebhookDelivery struct {
39 Id int64
40 WebhookId int64
41 Event string
42 DeliveryId string // UUID for tracking
43 Url string
44 RequestBody string
45 ResponseCode int
46 ResponseBody string
47 Success bool
48 CreatedAt time.Time
49}
50
51// WebhookPayload represents the webhook payload structure
52type WebhookPayload struct {
53 Ref string `json:"ref"`
54 Before string `json:"before"`
55 After string `json:"after"`
56 Repository WebhookRepository `json:"repository"`
57 Pusher WebhookUser `json:"pusher"`
58}
59
60// WebhookRepository represents repository information in webhook payload
61type WebhookRepository struct {
62 Name string `json:"name"`
63 FullName string `json:"full_name"`
64 Description string `json:"description"`
65 Fork bool `json:"fork"`
66 HtmlUrl string `json:"html_url"`
67 CloneUrl string `json:"clone_url"`
68 SshUrl string `json:"ssh_url"`
69 Website string `json:"website,omitempty"`
70 StarsCount int `json:"stars_count,omitempty"`
71 OpenIssues int `json:"open_issues_count,omitempty"`
72 CreatedAt string `json:"created_at"`
73 UpdatedAt string `json:"updated_at"`
74 Owner WebhookUser `json:"owner"`
75}
76
77// WebhookUser represents user information in webhook payload
78type WebhookUser struct {
79 Did string `json:"did"`
80}
81
82// WebhookRenamePayload represents the payload for a repository:renamed event
83type WebhookRenamePayload struct {
84 OldName string `json:"old_name"`
85 NewName string `json:"new_name"`
86 Repository WebhookRepository `json:"repository"`
87 Sender WebhookUser `json:"sender"`
88}
89
90// WebhookPullRequestPayload represents the payload for pull_request:* events
91type WebhookPullRequestPayload struct {
92 Action string `json:"action"`
93 PullRequest WebhookPullRequest `json:"pull_request"`
94 Repository WebhookRepository `json:"repository"`
95 Sender WebhookUser `json:"sender"`
96}
97
98// WebhookPullRequest represents pull request information in webhook payload
99type WebhookPullRequest struct {
100 Number int `json:"number"`
101 Title string `json:"title"`
102 Body string `json:"body"`
103 State string `json:"state"`
104 TargetBranch string `json:"target_branch"`
105 Source *WebhookPullRequestSource `json:"source,omitempty"`
106 RoundNumber int `json:"round_number"`
107 Owner WebhookUser `json:"owner"`
108 HtmlUrl string `json:"html_url"`
109 PatchUrl string `json:"patch_url"`
110 CreatedAt string `json:"created_at"`
111}
112
113// WebhookPullRequestSource represents the source of a branch- or fork-based
114// pull request; absent for patch-based pull requests
115type WebhookPullRequestSource struct {
116 Branch string `json:"branch"`
117 Repo string `json:"repo,omitempty"`
118 Sha string `json:"sha,omitempty"`
119}