github.com/go-playground/webhooks/v6@v6.3.0/azuredevops/payload.go (about) 1 package azuredevops 2 3 import ( 4 "fmt" 5 "strings" 6 "time" 7 ) 8 9 // https://docs.microsoft.com/en-us/azure/devops/service-hooks/events 10 11 // azure devops does not send an event header, this BasicEvent is provided to get the EventType 12 13 type BasicEvent struct { 14 ID string `json:"id"` 15 EventType Event `json:"eventType"` 16 PublisherID string `json:"publisherId"` 17 Scope string `json:"scope"` 18 CreatedDate Date `json:"createdDate"` 19 } 20 21 // git.pullrequest.* 22 // git.pullrequest.created 23 // git.pullrequest.merged 24 // git.pullrequest.updated 25 26 type GitPullRequestEvent struct { 27 ID string `json:"id"` 28 EventType Event `json:"eventType"` 29 PublisherID string `json:"publisherId"` 30 Scope string `json:"scope"` 31 Message Message `json:"message"` 32 DetailedMessage Message `json:"detailedMessage"` 33 Resource PullRequest `json:"resource"` 34 ResourceVersion string `json:"resourceVersion"` 35 ResourceContainers interface{} `json:"resourceContainers"` 36 CreatedDate Date `json:"createdDate"` 37 } 38 39 // git.push 40 41 type GitPushEvent struct { 42 CreatedDate string `json:"createdDate"` 43 DetailedMessage Message `json:"detailedMessage"` 44 EventType string `json:"eventType"` 45 ID string `json:"id"` 46 Message Message `json:"message"` 47 PublisherID string `json:"publisherId"` 48 Resource Resource `json:"resource"` 49 ResourceContainers ResourceContainers `json:"resourceContainers"` 50 ResourceVersion string `json:"resourceVersion"` 51 Scope string `json:"scope"` 52 } 53 54 // build.complete 55 56 type BuildCompleteEvent struct { 57 ID string `json:"id"` 58 EventType Event `json:"eventType"` 59 PublisherID string `json:"publisherId"` 60 Scope string `json:"scope"` 61 Message Message `json:"message"` 62 DetailedMessage Message `json:"detailedMessage"` 63 Resource Build `json:"resource"` 64 ResourceVersion string `json:"resourceVersion"` 65 ResourceContainers interface{} `json:"resourceContainers"` 66 CreatedDate Date `json:"createdDate"` 67 } 68 69 // ----------------------- 70 71 type Message struct { 72 Text string `json:"text"` 73 HTML string `json:"html"` 74 Markdown string `json:"markdown"` 75 } 76 77 type Commit struct { 78 CommitID string `json:"commitId"` 79 URL string `json:"url"` 80 } 81 82 type PullRequest struct { 83 Repository Repository `json:"repository"` 84 PullRequestID int `json:"pullRequestId"` 85 Status string `json:"status"` 86 CreatedBy User `json:"createdBy"` 87 CreationDate Date `json:"creationDate"` 88 ClosedDate Date `json:"closedDate"` 89 Title string `json:"title"` 90 Description string `json:"description"` 91 SourceRefName string `json:"sourceRefName"` 92 TargetRefName string `json:"targetRefName"` 93 MergeStatus string `json:"mergeStatus"` 94 MergeID string `json:"mergeId"` 95 LastMergeSourceCommit Commit `json:"lastMergeSourceCommit"` 96 LastMergeTargetCommit Commit `json:"lastMergeTargetCommit"` 97 LastMergeCommit Commit `json:"lastMergeCommit"` 98 Reviewers []Reviewer `json:"reviewers"` 99 Commits []Commit `json:"commits"` 100 URL string `json:"url"` 101 } 102 103 type Repository struct { 104 ID string `json:"id"` 105 Name string `json:"name"` 106 URL string `json:"url"` 107 Project Project `json:"project"` 108 DefaultBranch string `json:"defaultBranch"` 109 RemoteURL string `json:"remoteUrl"` 110 } 111 112 type Project struct { 113 ID string `json:"id"` 114 Name string `json:"name"` 115 URL string `json:"url"` 116 State string `json:"state"` 117 } 118 119 type User struct { 120 ID string `json:"id"` 121 DisplayName string `json:"displayName"` 122 UniqueName string `json:"uniqueName"` 123 URL string `json:"url"` 124 ImageURL string `json:"imageUrl"` 125 } 126 127 type Reviewer struct { 128 ReviewerURL string `json:"reviewerUrl"` 129 Vote int `json:"vote"` 130 ID string `json:"id"` 131 DisplayName string `json:"displayName"` 132 UniqueName string `json:"uniqueName"` 133 URL string `json:"url"` 134 ImageURL string `json:"imageUrl"` 135 IsContainer bool `json:"isContainer"` 136 } 137 138 type Build struct { 139 URI string `json:"uri"` 140 ID int `json:"id"` 141 BuildNumber string `json:"buildNumber"` 142 URL string `json:"url"` 143 StartTime Date `json:"startTime"` 144 FinishTime Date `json:"finishTime"` 145 Reason string `json:"reason"` 146 Status string `json:"status"` 147 DropLocation string `json:"dropLocation"` 148 Drop Drop `json:"drop"` 149 Log Log `json:"log"` 150 SourceGetVersion string `json:"sourceGetVersion"` 151 LastChangedBy User `json:"lastChangedBy"` 152 RetainIndefinitely bool `json:"retainIndefinitely"` 153 HasDiagnostics bool `json:"hasDiagnostics"` 154 Definition BuildDefinition `json:"definition"` 155 Queue Queue `json:"queue"` 156 Requests []Request `json:"requests"` 157 } 158 159 type Drop struct { 160 Location string `json:"location"` 161 Type string `json:"type"` 162 URL string `json:"url"` 163 DownloadURL string `json:"downloadUrl"` 164 } 165 166 type Log struct { 167 Type string `json:"type"` 168 URL string `json:"url"` 169 DownloadURL string `json:"downloadUrl"` 170 } 171 172 type BuildDefinition struct { 173 BatchSize int `json:"batchSize"` 174 TriggerType string `json:"triggerType"` 175 DefinitionType string `json:"definitionType"` 176 ID int `json:"id"` 177 Name string `json:"name"` 178 URL string `json:"url"` 179 } 180 181 type Queue struct { 182 QueueType string `json:"queueType"` 183 ID int `json:"id"` 184 Name string `json:"name"` 185 URL string `json:"url"` 186 } 187 188 type Request struct { 189 ID int `json:"id"` 190 URL string `json:"url"` 191 RequestedFor User `json:"requestedFor"` 192 } 193 194 type Resource struct { 195 Commits []Commit `json:"commits"` 196 Date string `json:"date"` 197 PushedBy PushedBy `json:"pushedBy"` 198 PushID int `json:"pushId"` 199 RefUpdates []RefUpdate `json:"refUpdates"` 200 Repository Repository `json:"repository"` 201 URL string `json:"url"` 202 } 203 204 type RefUpdate struct { 205 Name string `json:"name"` 206 NewObjectID string `json:"newObjectId"` 207 OldObjectID string `json:"oldObjectId"` 208 } 209 210 type PushedBy struct { 211 DisplayName string `json:"displayName"` 212 ID string `json:"id"` 213 UniqueName string `json:"uniqueName"` 214 } 215 216 type ResourceContainers struct { 217 Account Account `json:"account"` 218 Collection Account `json:"collection"` 219 Project Account `json:"project"` 220 } 221 222 type Account struct { 223 ID string `json:"id"` 224 } 225 226 type Date time.Time 227 228 func (b *Date) UnmarshalJSON(p []byte) error { 229 t, err := time.Parse(time.RFC3339Nano, strings.Replace(string(p), "\"", "", -1)) 230 if err != nil { 231 return err 232 } 233 *b = Date(t) 234 return nil 235 } 236 237 func (b Date) MarshalJSON() ([]byte, error) { 238 stamp := fmt.Sprintf("\"%s\"", time.Time(b).Format(time.RFC3339Nano)) 239 return []byte(stamp), nil 240 }