Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
- code cleanup
  • Loading branch information
aayeshaarshad committed May 6, 2024
1 parent 15005da commit fd7c2c3
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 17 deletions.
1 change: 0 additions & 1 deletion pkg/provider/azuredevops/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func (v *Provider) Detect(req *http.Request, payload string, logger *zap.Sugared
normalizedEventType := strings.ReplaceAll(*event.EventType, "-", ".")
if strings.Contains(normalizedEventType, eventType) {
logger = logger.With("provider", "azuredevops", "event-type", eventType)
// Simplified switch, expand as needed based on the Azure DevOps events you handle
switch eventType {
case "git.push", "git.pullrequest.created", "git.pullrequest.updated", "git.pullrequest.comment":
return setLoggerAndProceed(true, "", nil)
Expand Down
3 changes: 1 addition & 2 deletions pkg/provider/azuredevops/detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ func TestProvider_Detect(t *testing.T) {
gitPush := "git.push"
gitPRCreated := "git.pullrequest.created"
gitPRUpdated := "git.pullrequest.updated"
// Define more event types as needed

tests := []struct {
name string
Expand Down Expand Up @@ -80,7 +79,7 @@ func TestProvider_Detect(t *testing.T) {
header.Set("X-Azure-DevOps-EventType", tt.eventType)
req := &http.Request{Header: header}

v := Provider{} // Assuming Provider is your Azure DevOps provider struct
v := Provider{}
isADO, processReq, _, reason, err := v.Detect(req, string(payload), logger)

if tt.wantErr {
Expand Down
11 changes: 1 addition & 10 deletions pkg/provider/azuredevops/parse_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func (v *Provider) ParsePayload(_ context.Context, _ *params.Run, req *http.Requ
processedEvent := info.NewEvent()

processedEvent.EventType = req.Header.Get("X-Azure-DevOps-EventType")
// processedEvent.EventType = *genericEvent.EventType

resourceBytes, err := json.Marshal(genericEvent.Resource)
if err != nil {
Expand Down Expand Up @@ -63,7 +62,6 @@ func (v *Provider) ParsePayload(_ context.Context, _ *params.Run, req *http.Requ
processedEvent.URL = pushEvent.Repository.RemoteURL
processedEvent.DefaultBranch = pushEvent.Repository.DefaultBranch
processedEvent.TriggerTarget = triggertype.Push
// Assuming the repository URL can serve as both BaseURL and HeadURL for viewing purposes
processedEvent.BaseURL = pushEvent.Repository.URL
processedEvent.HeadURL = pushEvent.Repository.URL
if len(pushEvent.RefUpdates) > 0 {
Expand All @@ -84,19 +82,12 @@ func (v *Provider) ParsePayload(_ context.Context, _ *params.Run, req *http.Requ
processedEvent.SHAURL = prEvent.LastMergeSourceCommit.URL
processedEvent.SHATitle = prEvent.LastMergeSourceCommit.Comment

// Extract branch names from the ref names
// Azure DevOps ref names are full references (refs/heads/branchName), so we'll extract the branch name
processedEvent.BaseBranch = ExtractBranchName(prEvent.TargetRefName)
processedEvent.HeadBranch = ExtractBranchName(prEvent.SourceRefName)
processedEvent.DefaultBranch = prEvent.Repository.DefaultBranch

// Constructing URLs
remoteURL := *prEvent.Repository.WebURL
// processedEvent.BaseURL = fmt.Sprintf("%s?version=GB%s", remoteURL, processedEvent.BaseBranch)
// processedEvent.HeadURL = fmt.Sprintf("%s?version=GB%s", remoteURL, processedEvent.HeadBranch)

processedEvent.TriggerTarget = triggertype.PullRequest

remoteURL := *prEvent.Repository.WebURL
baseURL, err := ExtractBaseURL(remoteURL)
if err != nil {
return nil, fmt.Errorf("not able to extract organization url")
Expand Down
4 changes: 1 addition & 3 deletions pkg/provider/azuredevops/parse_payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

func TestParsePayload(t *testing.T) {
// Mock request setup
mockRequest := &http.Request{}

// Mock context
Expand Down Expand Up @@ -115,7 +114,7 @@ func TestParsePayload(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := Provider{} // Assuming this is your Azure DevOps provider
v := Provider{}
run := &params.Run{}

gotEvent, err := v.ParsePayload(ctx, run, mockRequest, tt.payload)
Expand All @@ -126,7 +125,6 @@ func TestParsePayload(t *testing.T) {

assert.Equal(t, tt.wantEvent.EventType, gotEvent.EventType)
assert.Equal(t, tt.wantEvent.SHA, gotEvent.SHA)
// Add more assertions as needed
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/azuredevops/test/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (m *MockCoreClient) GetTeamMembersWithExtendedProperties(ctx context.Contex

var teamMembers []webapi.TeamMember
for _, memberID := range members {
identityID := memberID // Simplifying identity ID use case
identityID := memberID
teamMembers = append(teamMembers, webapi.TeamMember{
Identity: &webapi.IdentityRef{Id: &identityID},
})
Expand Down

0 comments on commit fd7c2c3

Please sign in to comment.