@@ -3,13 +3,13 @@ package services
33import (
44 "encoding/json"
55 "fmt"
6- "net/http"
7-
86 "github.com/jfrog/jfrog-client-go/auth"
97 "github.com/jfrog/jfrog-client-go/http/jfroghttpclient"
108 "github.com/jfrog/jfrog-client-go/utils"
119 "github.com/jfrog/jfrog-client-go/utils/errorutils"
10+ servicesutils "github.com/jfrog/jfrog-client-go/xsc/services/utils"
1211 xscutils "github.com/jfrog/jfrog-client-go/xsc/services/utils"
12+ "net/http"
1313)
1414
1515const (
@@ -66,10 +66,17 @@ func (vs *AnalyticsEventService) sendGetRequest(msi string) (resp *http.Response
6666}
6767
6868// AddGeneralEvent add general event in Xsc and returns msi generated by Xsc.
69- func (vs * AnalyticsEventService ) AddGeneralEvent (event XscAnalyticsGeneralEvent ) (string , error ) {
70- requestContent , err := json .Marshal (event )
71- if err != nil {
72- return "" , errorutils .CheckError (err )
69+ func (vs * AnalyticsEventService ) AddGeneralEvent (event XscAnalyticsGeneralEvent , xrayVersion string ) (string , error ) {
70+ var requestContent []byte
71+ if err := utils .ValidateMinimumVersion (utils .Xray , xrayVersion , servicesutils .MinXrayVersionNewGitInfoContext ); err != nil {
72+ // use deprecated event struct
73+ if requestContent , err = json .Marshal (convertToDeprecatedEventStruct (event )); err != nil {
74+ return "" , errorutils .CheckError (err )
75+ }
76+ } else {
77+ if requestContent , err = json .Marshal (event ); err != nil {
78+ return "" , errorutils .CheckError (err )
79+ }
7380 }
7481 resp , body , err := vs .sendPostRequest (requestContent )
7582 if err != nil {
@@ -113,24 +120,75 @@ func (vs *AnalyticsEventService) GetGeneralEvent(msi string) (*XscAnalyticsGener
113120 return & response , errorutils .CheckError (err )
114121}
115122
123+ func convertToDeprecatedEventStruct (event XscAnalyticsGeneralEvent ) XscAnalyticsGeneralEventDeprecated {
124+ var deprecatedGitInfo XscGitInfoContextDeprecated
125+ if event .GitInfo != nil {
126+ deprecatedGitInfo = XscGitInfoContextDeprecated {
127+ GitRepoUrl : event .GitInfo .Source .GitRepoHttpsCloneUrl ,
128+ GitRepoName : event .GitInfo .Source .GitRepoName ,
129+ GitProject : event .GitInfo .Source .GitProject ,
130+ BranchName : event .GitInfo .Source .BranchName ,
131+ CommitHash : event .GitInfo .Source .CommitHash ,
132+ CommitMessage : event .GitInfo .Source .CommitMessage ,
133+ CommitAuthor : event .GitInfo .Source .CommitAuthor ,
134+ GitProvider : event .GitInfo .GitProvider ,
135+ Technologies : event .GitInfo .Technologies ,
136+ }
137+ }
138+ return XscAnalyticsGeneralEventDeprecated {
139+ XscAnalyticsBasicGeneralEvent : event .XscAnalyticsBasicGeneralEvent ,
140+ GitInfo : & deprecatedGitInfo ,
141+ IsGitInfoFlow : event .IsGitInfoFlow ,
142+ }
143+ }
144+
116145// XscAnalyticsGeneralEvent extend the basic struct with Frogbot related info.
146+ type XscAnalyticsGeneralEventDeprecated struct {
147+ XscAnalyticsBasicGeneralEvent
148+ GitInfo * XscGitInfoContextDeprecated `json:"gitinfo,omitempty"`
149+ IsGitInfoFlow bool `json:"is_gitinfo_flow,omitempty"`
150+ }
151+
152+ type XscGitInfoContextDeprecated struct {
153+ GitRepoUrl string `json:"git_repo_url"`
154+ GitRepoName string `json:"git_repo_name,omitempty"`
155+ GitProject string `json:"git_project,omitempty"`
156+ GitProvider string `json:"git_provider,omitempty"`
157+ Technologies []string `json:"technologies,omitempty"`
158+ BranchName string `json:"branch_name"`
159+ LastCommit string `json:"last_commit,omitempty"`
160+ CommitHash string `json:"commit_hash"`
161+ CommitMessage string `json:"commit_message,omitempty"`
162+ CommitAuthor string `json:"commit_author,omitempty"`
163+ }
164+
117165type XscAnalyticsGeneralEvent struct {
118166 XscAnalyticsBasicGeneralEvent
119167 GitInfo * XscGitInfoContext `json:"gitinfo,omitempty"`
120168 IsGitInfoFlow bool `json:"is_gitinfo_flow,omitempty"`
121169}
122170
123171type XscGitInfoContext struct {
124- GitRepoHttpsCloneUrl string `json:"git_repo_url"`
125- GitRepoName string `json:"git_repo_name,omitempty"`
126- GitProject string `json:"git_project,omitempty"`
127- GitProvider string `json:"git_provider,omitempty"`
128- Technologies []string `json:"technologies,omitempty"`
129- BranchName string `json:"branch_name"`
130- LastCommitUrl string `json:"last_commit,omitempty"`
131- LastCommitHash string `json:"commit_hash"`
132- LastCommitMessage string `json:"commit_message,omitempty"`
133- LastCommitAuthor string `json:"commit_author,omitempty"`
172+ Source CommitContext `json:"source"`
173+ Target * CommitContext `json:"target,omitempty"`
174+ PullRequest * PullRequestContext `json:"pull_request,omitempty"`
175+ GitProvider string `json:"git_provider,omitempty"`
176+ Technologies []string `json:"technologies,omitempty"`
177+ }
178+
179+ type CommitContext struct {
180+ GitRepoHttpsCloneUrl string `json:"git_repo_url"`
181+ GitRepoName string `json:"git_repo_name,omitempty"`
182+ GitProject string `json:"git_project,omitempty"`
183+ BranchName string `json:"branch_name"`
184+ CommitHash string `json:"commit_hash"`
185+ CommitMessage string `json:"commit_message,omitempty"`
186+ CommitAuthor string `json:"commit_author,omitempty"`
187+ }
188+
189+ type PullRequestContext struct {
190+ PullRequestId int `json:"pull_request_id,omitempty"`
191+ PullRequestTitle string `json:"pull_request_title,omitempty"`
134192}
135193
136194type XscAnalyticsGeneralEventFinalize struct {
0 commit comments