| 
 | 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 | +// build.complete  | 
 | 40 | + | 
 | 41 | +type BuildCompleteEvent struct {  | 
 | 42 | +	ID                 string      `json:"id"`  | 
 | 43 | +	EventType          Event       `json:"eventType"`  | 
 | 44 | +	PublisherID        string      `json:"publisherId"`  | 
 | 45 | +	Scope              string      `json:"scope"`  | 
 | 46 | +	Message            Message     `json:"message"`  | 
 | 47 | +	DetailedMessage    Message     `json:"detailedMessage"`  | 
 | 48 | +	Resource           Build       `json:"resource"`  | 
 | 49 | +	ResourceVersion    string      `json:"resourceVersion"`  | 
 | 50 | +	ResourceContainers interface{} `json:"resourceContainers"`  | 
 | 51 | +	CreatedDate        Date        `json:"createdDate"`  | 
 | 52 | +}  | 
 | 53 | + | 
 | 54 | +// -----------------------  | 
 | 55 | + | 
 | 56 | +type Message struct {  | 
 | 57 | +	Text     string `json:"text"`  | 
 | 58 | +	HTML     string `json:"html"`  | 
 | 59 | +	Markdown string `json:"markdown"`  | 
 | 60 | +}  | 
 | 61 | + | 
 | 62 | +type Commit struct {  | 
 | 63 | +	CommitID string `json:"commitId"`  | 
 | 64 | +	URL      string `json:"url"`  | 
 | 65 | +}  | 
 | 66 | + | 
 | 67 | +type PullRequest struct {  | 
 | 68 | +	Repository            Repository `json:"repository"`  | 
 | 69 | +	PullRequestID         int        `json:"pullRequestId"`  | 
 | 70 | +	Status                string     `json:"status"`  | 
 | 71 | +	CreatedBy             User       `json:"createdBy"`  | 
 | 72 | +	CreationDate          Date       `json:"creationDate"`  | 
 | 73 | +	ClosedDate            Date       `json:"closedDate"`  | 
 | 74 | +	Title                 string     `json:"title"`  | 
 | 75 | +	Description           string     `json:"description"`  | 
 | 76 | +	SourceRefName         string     `json:"sourceRefName"`  | 
 | 77 | +	TargetRefName         string     `json:"targetRefName"`  | 
 | 78 | +	MergeStatus           string     `json:"mergeStatus"`  | 
 | 79 | +	MergeID               string     `json:"mergeId"`  | 
 | 80 | +	LastMergeSourceCommit Commit     `json:"lastMergeSourceCommit"`  | 
 | 81 | +	LastMergeTargetCommit Commit     `json:"lastMergeTargetCommit"`  | 
 | 82 | +	LastMergeCommit       Commit     `json:"lastMergeCommit"`  | 
 | 83 | +	Reviewers             []Reviewer `json:"reviewers"`  | 
 | 84 | +	Commits               []Commit   `json:"commits"`  | 
 | 85 | +	URL                   string     `json:"url"`  | 
 | 86 | +}  | 
 | 87 | + | 
 | 88 | +type Repository struct {  | 
 | 89 | +	ID            string  `json:"id"`  | 
 | 90 | +	Name          string  `json:"name"`  | 
 | 91 | +	URL           string  `json:"url"`  | 
 | 92 | +	Project       Project `json:"project"`  | 
 | 93 | +	DefaultBranch string  `json:"defaultBranch"`  | 
 | 94 | +	RemoteURL     string  `json:"remoteUrl"`  | 
 | 95 | +}  | 
 | 96 | + | 
 | 97 | +type Project struct {  | 
 | 98 | +	ID    string `json:"id"`  | 
 | 99 | +	Name  string `json:"name"`  | 
 | 100 | +	URL   string `json:"url"`  | 
 | 101 | +	State string `json:"state"`  | 
 | 102 | +}  | 
 | 103 | + | 
 | 104 | +type User struct {  | 
 | 105 | +	ID          string `json:"id"`  | 
 | 106 | +	DisplayName string `json:"displayName"`  | 
 | 107 | +	UniqueName  string `json:"uniqueName"`  | 
 | 108 | +	URL         string `json:"url"`  | 
 | 109 | +	ImageURL    string `json:"imageUrl"`  | 
 | 110 | +}  | 
 | 111 | + | 
 | 112 | +type Reviewer struct {  | 
 | 113 | +	ReviewerURL string `json:"reviewerUrl"`  | 
 | 114 | +	Vote        int    `json:"vote"`  | 
 | 115 | +	ID          string `json:"id"`  | 
 | 116 | +	DisplayName string `json:"displayName"`  | 
 | 117 | +	UniqueName  string `json:"uniqueName"`  | 
 | 118 | +	URL         string `json:"url"`  | 
 | 119 | +	ImageURL    string `json:"imageUrl"`  | 
 | 120 | +	IsContainer bool   `json:"isContainer"`  | 
 | 121 | +}  | 
 | 122 | + | 
 | 123 | +type Build struct {  | 
 | 124 | +	URI                string          `json:"uri"`  | 
 | 125 | +	ID                 int             `json:"id"`  | 
 | 126 | +	BuildNumber        string          `json:"buildNumber"`  | 
 | 127 | +	URL                string          `json:"url"`  | 
 | 128 | +	StartTime          Date            `json:"startTime"`  | 
 | 129 | +	FinishTime         Date            `json:"finishTime"`  | 
 | 130 | +	Reason             string          `json:"reason"`  | 
 | 131 | +	Status             string          `json:"status"`  | 
 | 132 | +	DropLocation       string          `json:"dropLocation"`  | 
 | 133 | +	Drop               Drop            `json:"drop"`  | 
 | 134 | +	Log                Log             `json:"log"`  | 
 | 135 | +	SourceGetVersion   string          `json:"sourceGetVersion"`  | 
 | 136 | +	LastChangedBy      User            `json:"lastChangedBy"`  | 
 | 137 | +	RetainIndefinitely bool            `json:"retainIndefinitely"`  | 
 | 138 | +	HasDiagnostics     bool            `json:"hasDiagnostics"`  | 
 | 139 | +	Definition         BuildDefinition `json:"definition"`  | 
 | 140 | +	Queue              Queue           `json:"queue"`  | 
 | 141 | +	Requests           []Request       `json:"requests"`  | 
 | 142 | +}  | 
 | 143 | + | 
 | 144 | +type Drop struct {  | 
 | 145 | +	Location    string `json:"location"`  | 
 | 146 | +	Type        string `json:"type"`  | 
 | 147 | +	URL         string `json:"url"`  | 
 | 148 | +	DownloadURL string `json:"downloadUrl"`  | 
 | 149 | +}  | 
 | 150 | + | 
 | 151 | +type Log struct {  | 
 | 152 | +	Type        string `json:"type"`  | 
 | 153 | +	URL         string `json:"url"`  | 
 | 154 | +	DownloadURL string `json:"downloadUrl"`  | 
 | 155 | +}  | 
 | 156 | + | 
 | 157 | +type BuildDefinition struct {  | 
 | 158 | +	BatchSize      int    `json:"batchSize"`  | 
 | 159 | +	TriggerType    string `json:"triggerType"`  | 
 | 160 | +	DefinitionType string `json:"definitionType"`  | 
 | 161 | +	ID             int    `json:"id"`  | 
 | 162 | +	Name           string `json:"name"`  | 
 | 163 | +	URL            string `json:"url"`  | 
 | 164 | +}  | 
 | 165 | + | 
 | 166 | +type Queue struct {  | 
 | 167 | +	QueueType string `json:"queueType"`  | 
 | 168 | +	ID        int    `json:"id"`  | 
 | 169 | +	Name      string `json:"name"`  | 
 | 170 | +	URL       string `json:"url"`  | 
 | 171 | +}  | 
 | 172 | + | 
 | 173 | +type Request struct {  | 
 | 174 | +	ID           int    `json:"id"`  | 
 | 175 | +	URL          string `json:"url"`  | 
 | 176 | +	RequestedFor User   `json:"requestedFor"`  | 
 | 177 | +}  | 
 | 178 | + | 
 | 179 | +type Date time.Time  | 
 | 180 | + | 
 | 181 | +func (b *Date) UnmarshalJSON(p []byte) error {  | 
 | 182 | +	t, err := time.Parse(time.RFC3339Nano, strings.Replace(string(p), "\"", "", -1))  | 
 | 183 | +	if err != nil {  | 
 | 184 | +		return err  | 
 | 185 | +	}  | 
 | 186 | +	*b = Date(t)  | 
 | 187 | +	return nil  | 
 | 188 | +}  | 
 | 189 | + | 
 | 190 | +func (b Date) MarshalJSON() ([]byte, error) {  | 
 | 191 | +	stamp := fmt.Sprintf("\"%s\"", time.Time(b).Format(time.RFC3339Nano))  | 
 | 192 | +	return []byte(stamp), nil  | 
 | 193 | +}  | 
0 commit comments