-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update XscGitInfoContext struct #1089
Open
orz25
wants to merge
10
commits into
jfrog:dev
Choose a base branch
from
orz25:update-git-info-context
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0c8b855
Update XscGitInfoContext struct
orz25 6a1dd51
Add deprecated struct
orz25 0a64920
Add min version const
orz25 2a04024
Add convert logic
orz25 16281dd
Updated logic
orz25 04cf756
Fix test
orz25 98f1752
Fix test
orz25 cea2934
Fix test
orz25 35b5a2c
Pass xray version
orz25 96404aa
fix test
orz25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,13 @@ package services | |
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/jfrog/jfrog-client-go/auth" | ||
"github.com/jfrog/jfrog-client-go/http/jfroghttpclient" | ||
"github.com/jfrog/jfrog-client-go/utils" | ||
"github.com/jfrog/jfrog-client-go/utils/errorutils" | ||
servicesutils "github.com/jfrog/jfrog-client-go/xsc/services/utils" | ||
xscutils "github.com/jfrog/jfrog-client-go/xsc/services/utils" | ||
"net/http" | ||
) | ||
|
||
const ( | ||
|
@@ -66,10 +66,20 @@ func (vs *AnalyticsEventService) sendGetRequest(msi string) (resp *http.Response | |
} | ||
|
||
// AddGeneralEvent add general event in Xsc and returns msi generated by Xsc. | ||
func (vs *AnalyticsEventService) AddGeneralEvent(event XscAnalyticsGeneralEvent) (string, error) { | ||
requestContent, err := json.Marshal(event) | ||
if err != nil { | ||
return "", errorutils.CheckError(err) | ||
func (vs *AnalyticsEventService) AddGeneralEvent(event XscAnalyticsGeneralEvent, xrayVersion string) (string, error) { | ||
var requestContent []byte | ||
if err := utils.ValidateMinimumVersion(utils.Xray, xrayVersion, servicesutils.MinXrayVersionNewGitInfoContext); err != nil { | ||
// use deprecated event struct | ||
deprecatedEvent := convertToDeprecatedEventStruct(event) | ||
requestContent, err = json.Marshal(deprecatedEvent) | ||
if err != nil { | ||
return "", errorutils.CheckError(err) | ||
} | ||
orz25 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
requestContent, err = json.Marshal(event) | ||
if err != nil { | ||
return "", errorutils.CheckError(err) | ||
} | ||
orz25 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
resp, body, err := vs.sendPostRequest(requestContent) | ||
if err != nil { | ||
|
@@ -113,24 +123,75 @@ func (vs *AnalyticsEventService) GetGeneralEvent(msi string) (*XscAnalyticsGener | |
return &response, errorutils.CheckError(err) | ||
} | ||
|
||
func convertToDeprecatedEventStruct(event XscAnalyticsGeneralEvent) XscAnalyticsGeneralEventDeprecated { | ||
var deprecatedGitInfo XscGitInfoContextDeprecated | ||
if event.GitInfo != nil { | ||
deprecatedGitInfo = XscGitInfoContextDeprecated{ | ||
GitRepoUrl: event.GitInfo.Source.GitRepoHttpsCloneUrl, | ||
GitRepoName: event.GitInfo.Source.GitRepoName, | ||
GitProject: event.GitInfo.Source.GitProject, | ||
BranchName: event.GitInfo.Source.BranchName, | ||
CommitHash: event.GitInfo.Source.CommitHash, | ||
CommitMessage: event.GitInfo.Source.CommitMessage, | ||
CommitAuthor: event.GitInfo.Source.CommitAuthor, | ||
GitProvider: event.GitInfo.GitProvider, | ||
Technologies: event.GitInfo.Technologies, | ||
} | ||
} | ||
return XscAnalyticsGeneralEventDeprecated{ | ||
XscAnalyticsBasicGeneralEvent: event.XscAnalyticsBasicGeneralEvent, | ||
GitInfo: &deprecatedGitInfo, | ||
IsGitInfoFlow: event.IsGitInfoFlow, | ||
} | ||
} | ||
|
||
// XscAnalyticsGeneralEvent extend the basic struct with Frogbot related info. | ||
type XscAnalyticsGeneralEventDeprecated struct { | ||
XscAnalyticsBasicGeneralEvent | ||
GitInfo *XscGitInfoContextDeprecated `json:"gitinfo,omitempty"` | ||
IsGitInfoFlow bool `json:"is_gitinfo_flow,omitempty"` | ||
} | ||
|
||
type XscGitInfoContextDeprecated struct { | ||
GitRepoUrl string `json:"git_repo_url"` | ||
GitRepoName string `json:"git_repo_name,omitempty"` | ||
GitProject string `json:"git_project,omitempty"` | ||
GitProvider string `json:"git_provider,omitempty"` | ||
Technologies []string `json:"technologies,omitempty"` | ||
BranchName string `json:"branch_name"` | ||
LastCommit string `json:"last_commit,omitempty"` | ||
CommitHash string `json:"commit_hash"` | ||
CommitMessage string `json:"commit_message,omitempty"` | ||
CommitAuthor string `json:"commit_author,omitempty"` | ||
} | ||
|
||
type XscAnalyticsGeneralEvent struct { | ||
XscAnalyticsBasicGeneralEvent | ||
GitInfo *XscGitInfoContext `json:"gitinfo,omitempty"` | ||
IsGitInfoFlow bool `json:"is_gitinfo_flow,omitempty"` | ||
} | ||
|
||
type XscGitInfoContext struct { | ||
GitRepoHttpsCloneUrl string `json:"git_repo_url"` | ||
GitRepoName string `json:"git_repo_name,omitempty"` | ||
GitProject string `json:"git_project,omitempty"` | ||
GitProvider string `json:"git_provider,omitempty"` | ||
Technologies []string `json:"technologies,omitempty"` | ||
BranchName string `json:"branch_name"` | ||
LastCommitUrl string `json:"last_commit,omitempty"` | ||
LastCommitHash string `json:"commit_hash"` | ||
LastCommitMessage string `json:"commit_message,omitempty"` | ||
LastCommitAuthor string `json:"commit_author,omitempty"` | ||
Source CommitContext `json:"source,omitempty"` | ||
orz25 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
PullRequest *PullRequestContext `json:"pull_request,omitempty"` | ||
GitProvider string `json:"git_provider,omitempty"` | ||
Technologies []string `json:"technologies,omitempty"` | ||
} | ||
|
||
type CommitContext struct { | ||
GitRepoHttpsCloneUrl string `json:"git_repo_url"` | ||
GitRepoName string `json:"git_repo_name,omitempty"` | ||
GitProject string `json:"git_project,omitempty"` | ||
BranchName string `json:"branch_name"` | ||
CommitHash string `json:"commit_hash"` | ||
CommitMessage string `json:"commit_message,omitempty"` | ||
CommitAuthor string `json:"commit_author,omitempty"` | ||
} | ||
|
||
type PullRequestContext struct { | ||
PullRequestId int `json:"pull_request_id,omitempty"` | ||
PullRequestTitle string `json:"pull_request_title,omitempty"` | ||
TargetBranchName string `json:"target_branch_name,omitempty"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would extract this variable from this struct to stand at |
||
} | ||
|
||
type XscAnalyticsGeneralEventFinalize struct { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can also detect the version instead of getting the version as arg if you want:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I first tried this option but had two thoughts: