Skip to content
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

added support for azure devops #1654

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
linting
- Removed all go-lint issues
aayeshaarshad committed Apr 16, 2024
commit a1af7e8ed9dd71a25ca4dd43c5c9965ed0f7c2ad
4 changes: 2 additions & 2 deletions pkg/apis/pipelinesascode/keys/keys.go
Original file line number Diff line number Diff line change
@@ -54,8 +54,8 @@ const (
MaxKeepRuns = pipelinesascode.GroupName + "/max-keep-runs"
LogURL = pipelinesascode.GroupName + "/log-url"
ExecutionOrder = pipelinesascode.GroupName + "/execution-order"
ProjectId = pipelinesascode.GroupName + "/project-id"
RepositoryId = pipelinesascode.GroupName + "/repository-id"
ProjectID = pipelinesascode.GroupName + "/project-id"
RepositoryID = pipelinesascode.GroupName + "/repository-id"
// PublicGithubAPIURL default is "https://api.github.com" but it can be overridden by X-GitHub-Enterprise-Host header.
PublicGithubAPIURL = "https://api.github.com"
// InstallationURL gives us the Installation ID for the GitHub Application.
12 changes: 6 additions & 6 deletions pkg/kubeinteraction/labels.go
Original file line number Diff line number Diff line change
@@ -55,8 +55,8 @@ func AddLabelsAndAnnotations(event *info.Event, pipelineRun *tektonv1.PipelineRu
keys.GitProvider: providerConfig.Name,
keys.State: StateStarted,
keys.ControllerInfo: fmt.Sprintf(`{"name":"%s","configmap":"%s","secret":"%s"}`, paramsinfo.Controller.Name, paramsinfo.Controller.Configmap, paramsinfo.Controller.Secret),
keys.RepositoryId: event.RepositoryId,
keys.ProjectId: event.ProjectId,
keys.RepositoryID: event.RepositoryID,
keys.ProjectID: event.ProjectID,
}

if event.PullRequestNumber != 0 {
@@ -84,11 +84,11 @@ func AddLabelsAndAnnotations(event *info.Event, pipelineRun *tektonv1.PipelineRu

// Azure devops

if event.RepositoryId != "" {
annotations[keys.RepositoryId] = event.RepositoryId
if event.RepositoryID != "" {
annotations[keys.RepositoryID] = event.RepositoryID
}
if event.ProjectId != "" {
annotations[keys.ProjectId] = event.ProjectId
if event.ProjectID != "" {
annotations[keys.ProjectID] = event.ProjectID
}

for k, v := range labels {
6 changes: 3 additions & 3 deletions pkg/params/info/events.go
Original file line number Diff line number Diff line change
@@ -63,9 +63,9 @@ type Event struct {
SourceProjectID int
TargetProjectID int

//AzureDevops
RepositoryId string
ProjectId string
// AzureDevops
RepositoryID string
ProjectID string
}

type State struct {
4 changes: 2 additions & 2 deletions pkg/provider/azuredevops/acl.go
Original file line number Diff line number Diff line change
@@ -9,12 +9,12 @@ import (
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/info"
)

// ToDo: implement this function
// ToDo: implement this function.
func (v *Provider) CheckPolicyAllowing(context.Context, *info.Event, []string) (bool, string) {
return false, ""
}

// ToDo: implement this function
// ToDo: implement this function.
func (v *Provider) IsAllowed(context.Context, *info.Event) (bool, error) {
return true, nil
}
126 changes: 55 additions & 71 deletions pkg/provider/azuredevops/azuredevops.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"strconv"
"strings"

@@ -91,24 +90,24 @@ func (v *Provider) CreateStatus(ctx context.Context, event *info.Event, statusOp
},
}
commitStatusArgs := git.CreateCommitStatusArgs{
Project: &event.ProjectId,
RepositoryId: &event.RepositoryId,
Project: &event.ProjectID,
RepositoryId: &event.RepositoryID,
CommitId: &event.SHA,
GitCommitStatusToCreate: &gitStatus,
}
if _, err := v.Client.CreateCommitStatus(ctx, commitStatusArgs); err != nil {
return fmt.Errorf("failed to create commit status: %v", err)
return fmt.Errorf("failed to create commit status: %w", err)
}
case "git.pullrequest.created", "git.pullrequest.updated":
gitPullRequestStatusArgs := git.GetPullRequestStatusesArgs{
PullRequestId: &event.PullRequestNumber,
Project: &event.ProjectId,
RepositoryId: &event.RepositoryId,
Project: &event.ProjectID,
RepositoryId: &event.RepositoryID,
}

status, err := v.Client.GetPullRequestStatuses(ctx, gitPullRequestStatusArgs)
if err != nil {
return fmt.Errorf("failed to fetch pull request statuses: %v", err)
return fmt.Errorf("failed to fetch pull request statuses: %w", err)
}

if status == nil || len(*status) == 0 {
@@ -117,7 +116,7 @@ func (v *Provider) CreateStatus(ctx context.Context, event *info.Event, statusOp
return err
}
} else {
//azure UpdatePullRequestStatuses only Support remove, so first remove the old status and then updated with new one
// azure UpdatePullRequestStatuses only Support remove, so first remove the old status and then updated with new one

err := updatePRStatus(ctx, status, event, v)
if err != nil {
@@ -148,12 +147,12 @@ func updatePRStatus(ctx context.Context, status *[]git.GitPullRequestStatus, eve

gitUpdatePullRequestStatus := git.UpdatePullRequestStatusesArgs{
PatchDocument: &patchDocument,
Project: &event.ProjectId,
RepositoryId: &event.RepositoryId,
Project: &event.ProjectID,
RepositoryId: &event.RepositoryID,
PullRequestId: &event.PullRequestNumber,
}
if err := v.Client.UpdatePullRequestStatuses(ctx, gitUpdatePullRequestStatus); err != nil {
return fmt.Errorf("failed to update pull request status: %v", err)
return fmt.Errorf("failed to update pull request status: %w", err)
}
return nil
}
@@ -172,12 +171,12 @@ func createPRStatus(ctx context.Context, v *Provider, event *info.Event, statusO

prStatusArgs := git.CreatePullRequestStatusArgs{
PullRequestId: &event.PullRequestNumber,
Project: &event.ProjectId,
RepositoryId: &event.RepositoryId,
Project: &event.ProjectID,
RepositoryId: &event.RepositoryID,
Status: &gitPullRequestStatus,
}
if _, err := v.Client.CreatePullRequestStatus(ctx, prStatusArgs); err != nil {
return fmt.Errorf("failed to create pull request status: %v", err)
return fmt.Errorf("failed to create pull request status: %w", err)
}
return nil
}
@@ -192,35 +191,34 @@ func (v *Provider) GetCommitInfo(ctx context.Context, event *info.Event) error {
"exiting... (hint: did you forget setting a secret on your repo?)")
}

RepositoryId := event.RepositoryId
projectId := event.ProjectId
RepositoryID := event.RepositoryID
projectID := event.ProjectID
sha := event.SHA

// If SHA is not provided, try to fetch it from the branch or pull request
if sha == "" {
if event.HeadBranch != "" {

refName := fmt.Sprintf("refs/heads/%s", event.HeadBranch)
refs, err := v.Client.GetRefs(ctx, git.GetRefsArgs{
RepositoryId: &RepositoryId,
RepositoryId: &RepositoryID,
Filter: &refName,
Project: &projectId,
Project: &projectID,
})
if err != nil {
return fmt.Errorf("failed to get branch info: %v", err)
return fmt.Errorf("failed to get branch info: %w", err)
}
// Assuming refs is a pointer to a slice, we check its length like this:
if len(refs.Value) > 0 {
sha = *refs.Value[0].ObjectId
}
} else if event.PullRequestNumber != 0 {
pr, err := v.Client.GetPullRequest(ctx, git.GetPullRequestArgs{
RepositoryId: &RepositoryId,
RepositoryId: &RepositoryID,
PullRequestId: &event.PullRequestNumber,
Project: &projectId,
Project: &projectID,
})
if err != nil {
return fmt.Errorf("failed to get pull request: %v", err)
return fmt.Errorf("failed to get pull request: %w", err)
}
sha = *pr.LastMergeSourceCommit.CommitId
event.HeadBranch = *pr.SourceRefName
@@ -230,16 +228,15 @@ func (v *Provider) GetCommitInfo(ctx context.Context, event *info.Event) error {
if sha != "" {
commit, err := v.Client.GetCommit(ctx, git.GetCommitArgs{
CommitId: &sha,
RepositoryId: &RepositoryId,
Project: &projectId,
RepositoryId: &RepositoryID,
Project: &projectID,
})
if err != nil {
return fmt.Errorf("failed to get commit: %v", err)
return fmt.Errorf("failed to get commit: %w", err)
}
event.SHAURL = *commit.RemoteUrl
event.SHATitle = strings.Split(*commit.Comment, "\n\n")[0]
event.SHA = *commit.CommitId

} else {
return fmt.Errorf("unable to determine commit SHA")
}
@@ -254,58 +251,55 @@ func (v *Provider) GetConfig() *info.ProviderConfig {
}

func (v *Provider) GetFiles(ctx context.Context, event *info.Event) (changedfiles.ChangedFiles, error) {

filesChanged, err := v.Client.GetChanges(ctx, git.GetChangesArgs{
RepositoryId: &event.RepositoryId,
RepositoryId: &event.RepositoryID,
CommitId: &event.SHA,
})

if err != nil {
v.Logger.Errorf("Failed to get changes for commit %s: %v", &event.SHA, err)
v.Logger.Errorf("Failed to get changes for commit %s: %w", &event.SHA, err)
}

changesJson, err := json.Marshal(filesChanged.Changes)
changesJSON, err := json.Marshal(filesChanged.Changes)
if err != nil {
v.Logger.Errorf("Failed to marshal changes: %v", err)
v.Logger.Errorf("Failed to marshal changes: %w", err)
return changedfiles.ChangedFiles{}, err
}

var changes []types.Change
if err := json.Unmarshal(changesJson, &changes); err != nil {
log.Fatalf("JSON Unmarshal error: %v", err)
if err := json.Unmarshal(changesJSON, &changes); err != nil {
v.Logger.Errorf("JSON Unmarshal error: %w", err)
}

changedFiles := &changedfiles.ChangedFiles{}

for _, c := range changes {

switch c.ChangeType {
case "edit":
changedFiles.All = append(changedFiles.Added, c.Item.Path)
changedFiles.Modified = append(changedFiles.Added, c.Item.Path)
changedFiles.All = append(changedFiles.All, c.Item.Path)
changedFiles.Modified = append(changedFiles.Modified, c.Item.Path)
case "add":
changedFiles.All = append(changedFiles.Added, c.Item.Path)
changedFiles.All = append(changedFiles.All, c.Item.Path)
changedFiles.Added = append(changedFiles.Added, c.Item.Path)
case "delete":
changedFiles.All = append(changedFiles.Added, c.Item.Path)
changedFiles.Deleted = append(changedFiles.Added, c.Item.Path)
changedFiles.All = append(changedFiles.All, c.Item.Path)
changedFiles.Deleted = append(changedFiles.Deleted, c.Item.Path)
case "rename":
changedFiles.All = append(changedFiles.Added, c.Item.Path)
changedFiles.Renamed = append(changedFiles.Added, c.Item.Path)
changedFiles.All = append(changedFiles.All, c.Item.Path)
changedFiles.Renamed = append(changedFiles.Renamed, c.Item.Path)
}
}

return *changedFiles, nil
}

// GetTaskURI TODO: Implement ME.
func (v *Provider) GetTaskURI(ctx context.Context, event *info.Event, uri string) (bool, string, error) {
func (v *Provider) GetTaskURI(context.Context, *info.Event, string) (bool, string, error) {
return false, "", nil
}

func (v *Provider) GetFileInsideRepo(ctx context.Context, runevent *info.Event, path, target string) (string, error) {
repositoryID := runevent.RepositoryId
ProjectId := runevent.ProjectId
repositoryID := runevent.RepositoryID
ProjectID := runevent.ProjectID

version := runevent.SHA
versionType := git.GitVersionTypeValues.Commit
@@ -321,7 +315,7 @@ func (v *Provider) GetFileInsideRepo(ctx context.Context, runevent *info.Event,

reader, err := v.Client.GetItemContent(ctx, git.GetItemContentArgs{
RepositoryId: &repositoryID,
Project: &ProjectId,
Project: &ProjectID,
Path: &path,
VersionDescriptor: &gitVersionDescriptor,
})
@@ -337,14 +331,12 @@ func (v *Provider) GetFileInsideRepo(ctx context.Context, runevent *info.Event,
}

return string(content), nil

}

// GetTektonDir implements provider.Interface.
func (v *Provider) GetTektonDir(ctx context.Context, runevent *info.Event, path, provenance string) (string, error) {

repositoryID := runevent.RepositoryId
ProjectId := runevent.ProjectId
repositoryID := runevent.RepositoryID
ProjectID := runevent.ProjectID
var version string
var versionType git.GitVersionType

@@ -366,13 +358,12 @@ func (v *Provider) GetTektonDir(ctx context.Context, runevent *info.Event, path,
// Check if the path exists and is a directory
item, err := v.Client.GetItem(ctx, git.GetItemArgs{
RepositoryId: &repositoryID,
Project: &ProjectId,
Project: &ProjectID,
Path: &path,
VersionDescriptor: &gitVersionDescriptor,
})

if err != nil {
return "", fmt.Errorf("failed to fetch the item: %v", err)
return "", fmt.Errorf("failed to fetch the item: %w", err)
}

if item == nil {
@@ -382,37 +373,33 @@ func (v *Provider) GetTektonDir(ctx context.Context, runevent *info.Event, path,
// Get the SHA of the directory and fetch the tree
tree, err := v.Client.GetTree(ctx, git.GetTreeArgs{
RepositoryId: &repositoryID,
Project: &ProjectId,
Project: &ProjectID,
Sha1: item.ObjectId,
Recursive: toBoolPtr(true),
})

if err != nil {
return "", fmt.Errorf("failed to fetch the tree: %v", err)
return "", fmt.Errorf("failed to fetch the tree: %w", err)
}

// Concatenate all YAML files found within the tree entries
result, err := v.concatAllYamlFiles(ctx, tree.TreeEntries, repositoryID, ProjectId)
result, err := v.concatAllYamlFiles(ctx, tree.TreeEntries, repositoryID, ProjectID)
if err != nil {
return "", err
}
return result, nil

}

func toBoolPtr(b bool) *bool {
return &b
}

func (v *Provider) concatAllYamlFiles(ctx context.Context, entries *[]git.GitTreeEntryRef, repositoryID string, projectId string) (string, error) {
func (v *Provider) concatAllYamlFiles(ctx context.Context, entries *[]git.GitTreeEntryRef, repositoryID, projectID string) (string, error) {
var allTemplates string

for _, entry := range *entries {
if *entry.GitObjectType == git.GitObjectTypeValues.Blob && (strings.HasSuffix(*entry.RelativePath, ".yaml") || strings.HasSuffix(*entry.RelativePath, ".yml")) {

// Use the object ID (SHA) of the blob to fetch its content
data, err := v.getObject(ctx, repositoryID, projectId, *entry.ObjectId)

data, err := v.getObject(ctx, repositoryID, projectID, *entry.ObjectId)
if err != nil {
return "", err
}
@@ -431,10 +418,10 @@ func (v *Provider) concatAllYamlFiles(ctx context.Context, entries *[]git.GitTre
return allTemplates, nil
}

func (v *Provider) getObject(ctx context.Context, repositoryID string, projectId string, sha string) ([]byte, error) {
func (v *Provider) getObject(ctx context.Context, repositoryID, projectID, sha string) ([]byte, error) {
reader, err := v.Client.GetBlobContent(ctx, git.GetBlobContentArgs{
RepositoryId: &repositoryID,
Project: &projectId,
Project: &projectID,
Sha1: &sha,
})
if err != nil {
@@ -458,13 +445,10 @@ func (v *Provider) SetClient(_ context.Context, run *params.Run, event *info.Eve
return fmt.Errorf("no git_provider.secret has been set in the repo crd")
}

organizationUrl := event.Organization
connection := azuredevops.NewPatConnection(organizationUrl, event.Provider.Token)

organizationURL := event.Organization
connection := azuredevops.NewPatConnection(organizationURL, event.Provider.Token)
ctx := context.Background()

v.Client, err = git.NewClient(ctx, connection)

if err != nil {
return err
}
@@ -480,6 +464,6 @@ func (v *Provider) SetLogger(logger *zap.SugaredLogger) {
v.Logger = logger
}

func (v *Provider) Validate(ctx context.Context, params *params.Run, event *info.Event) error {
func (v *Provider) Validate(context.Context, *params.Run, *info.Event) error {
return nil
}
14 changes: 7 additions & 7 deletions pkg/provider/azuredevops/azuredevops_test.go
Original file line number Diff line number Diff line change
@@ -46,27 +46,27 @@ func (m *MockGitClient) CreateAnnotatedTag(ctx context.Context, args git.CreateA
return nil, nil
}

func Setup(t *testing.T) (*MockGitClient, *http.ServeMux, func()) {
func Setup() (*MockGitClient, *http.ServeMux, func()) {
mux := http.NewServeMux()
server := httptest.NewServer(mux)
tearDown := func() {
server.Close()
}

mockClient := &MockGitClient{
createCommitStatus: func(ctx context.Context, args git.CreateCommitStatusArgs) (*git.GitStatus, error) {
createCommitStatus: func(context.Context, git.CreateCommitStatusArgs) (*git.GitStatus, error) {
return &git.GitStatus{}, nil
},
getPullRequestStatuses: func(ctx context.Context, args git.GetPullRequestStatusesArgs) (*[]git.GitPullRequestStatus, error) {
getPullRequestStatuses: func(context.Context, git.GetPullRequestStatusesArgs) (*[]git.GitPullRequestStatus, error) {
return &[]git.GitPullRequestStatus{}, nil
},
updatePullRequestStatus: func(ctx context.Context, args git.UpdatePullRequestStatusesArgs) error {
updatePullRequestStatus: func(context.Context, git.UpdatePullRequestStatusesArgs) error {
return nil
},
createPullRequestStatus: func(ctx context.Context, args git.CreatePullRequestStatusArgs) (*git.GitPullRequestStatus, error) {
createPullRequestStatus: func(context.Context, git.CreatePullRequestStatusArgs) (*git.GitPullRequestStatus, error) {
return &git.GitPullRequestStatus{}, nil
},
createAnnotatedTag: func(ctx context.Context, args git.CreateAnnotatedTagArgs) (*git.GitAnnotatedTag, error) {
createAnnotatedTag: func(context.Context, git.CreateAnnotatedTagArgs) (*git.GitAnnotatedTag, error) {
return &git.GitAnnotatedTag{}, nil
},
}
@@ -91,7 +91,7 @@ func getProvider(mockClient *MockGitClient) *Provider {
}

func TestCreateStatus(t *testing.T) {
mockClient, _, tearDown := Setup(t)
mockClient, _, tearDown := Setup()
defer tearDown()

ctx := context.Background()
58 changes: 26 additions & 32 deletions pkg/provider/azuredevops/parse_payload.go
Original file line number Diff line number Diff line change
@@ -15,14 +15,11 @@ import (
types "github.com/openshift-pipelines/pipelines-as-code/pkg/provider/azuredevops/types"
)

func (v *Provider) ParsePayload(_ context.Context, _ *params.Run, request *http.Request,
payload string,
) (*info.Event, error) {

func (v *Provider) ParsePayload(_ context.Context, _ *params.Run, _ *http.Request, payload string) (*info.Event, error) {
var genericEvent servicehooks.Event
err := json.Unmarshal([]byte(payload), &genericEvent)
if err != nil {
return nil, fmt.Errorf("error unmarshalling payload into Event: %v", err)
return nil, fmt.Errorf("error unmarshalling payload into Event: %w", err)
}

if genericEvent.EventType == nil {
@@ -34,41 +31,39 @@ func (v *Provider) ParsePayload(_ context.Context, _ *params.Run, request *http.

resourceBytes, err := json.Marshal(genericEvent.Resource)
if err != nil {
return nil, fmt.Errorf("error marshalling resource: %v", err)
return nil, fmt.Errorf("error marshalling resource: %w", err)
}

switch *genericEvent.EventType {
case "git.push":

var pushEvent types.PushEventResource
if err := json.Unmarshal(resourceBytes, &pushEvent); err != nil {
return nil, fmt.Errorf("error unmarshalling push event resource: %v", err)
return nil, fmt.Errorf("error unmarshalling push event resource: %w", err)
}
if len(pushEvent.Commits) > 0 {
processedEvent.SHA = pushEvent.Commits[0].CommitId
processedEvent.SHAURL = pushEvent.Commits[0].Url
processedEvent.SHA = pushEvent.Commits[0].CommitID
processedEvent.SHAURL = pushEvent.Commits[0].URL
processedEvent.SHATitle = pushEvent.Commits[0].Comment
}

processedEvent.EventType = *genericEvent.EventType
processedEvent.Sender = pushEvent.PushedBy.DisplayName
baseURL, err := extractBaseURL(pushEvent.Repository.RemoteUrl)
baseURL, err := extractBaseURL(pushEvent.Repository.RemoteURL)
if err != nil {
fmt.Println("Error:", err)
return nil, fmt.Errorf("not able to extract organization url")
}
processedEvent.Organization = baseURL
fmt.Println("Base URL:", baseURL)

processedEvent.Repository = pushEvent.Repository.RemoteUrl
processedEvent.RepositoryId = pushEvent.Repository.Id
processedEvent.ProjectId = pushEvent.Repository.Project.Id
processedEvent.URL = pushEvent.Repository.RemoteUrl
processedEvent.Repository = pushEvent.Repository.RemoteURL
processedEvent.RepositoryID = pushEvent.Repository.ID
processedEvent.ProjectID = pushEvent.Repository.Project.ID
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 // or it could be remoteUrl or it could be other; need to verify
processedEvent.HeadURL = pushEvent.Repository.Url // or it could be remoteUrl or it could be other; need to verify
processedEvent.BaseURL = pushEvent.Repository.URL // or it could be remoteUrl or it could be other; need to verify
processedEvent.HeadURL = pushEvent.Repository.URL // or it could be remoteUrl or it could be other; need to verify
if len(pushEvent.RefUpdates) > 0 {
branchName := ExtractBranchName(pushEvent.RefUpdates[0].Name)
processedEvent.BaseBranch = branchName
@@ -78,14 +73,14 @@ func (v *Provider) ParsePayload(_ context.Context, _ *params.Run, request *http.
case "git.pullrequest.created", "git.pullrequest.updated":
var prEvent types.PullRequestEventResource
if err := json.Unmarshal(resourceBytes, &prEvent); err != nil {
return nil, fmt.Errorf("error unmarshalling pull request event resource: %v", err)
return nil, fmt.Errorf("error unmarshalling pull request event resource: %w", err)
}

processedEvent.EventType = *genericEvent.EventType
processedEvent.PullRequestNumber = prEvent.PullRequestId
processedEvent.PullRequestNumber = prEvent.PullRequestID
processedEvent.PullRequestTitle = prEvent.Title
processedEvent.SHA = prEvent.LastMergeSourceCommit.CommitId
processedEvent.SHAURL = prEvent.LastMergeSourceCommit.Url
processedEvent.SHA = prEvent.LastMergeSourceCommit.CommitID
processedEvent.SHAURL = prEvent.LastMergeSourceCommit.URL
processedEvent.SHATitle = prEvent.LastMergeSourceCommit.Comment

// Extract branch names from the ref names
@@ -95,22 +90,21 @@ func (v *Provider) ParsePayload(_ context.Context, _ *params.Run, request *http.
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)
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

baseURL, err := extractBaseURL(remoteUrl)
baseURL, err := extractBaseURL(remoteURL)
if err != nil {
fmt.Println("Error:", err)
return nil, fmt.Errorf("not able to extract organization url")
}
processedEvent.Organization = baseURL
processedEvent.Repository = *prEvent.Repository.WebUrl
processedEvent.RepositoryId = prEvent.Repository.Id
processedEvent.ProjectId = prEvent.Repository.Project.Id
processedEvent.URL = *prEvent.Repository.WebUrl
processedEvent.Repository = *prEvent.Repository.WebURL
processedEvent.RepositoryID = prEvent.Repository.ID
processedEvent.ProjectID = prEvent.Repository.Project.ID
processedEvent.URL = *prEvent.Repository.WebURL
processedEvent.Sender = prEvent.CreatedBy.DisplayName
default:
return nil, fmt.Errorf("event type %s is not supported", *genericEvent.EventType)
@@ -120,7 +114,7 @@ func (v *Provider) ParsePayload(_ context.Context, _ *params.Run, request *http.
}

// ExtractBranchName extracts the branch name from a full ref name.
// E.g., "refs/heads/master" -> "master"
// E.g., "refs/heads/master" -> "master".
func ExtractBranchName(refName string) string {
parts := strings.Split(refName, "/")
if len(parts) > 2 {
1 change: 1 addition & 0 deletions pkg/provider/azuredevops/parse_payload_test.go
Original file line number Diff line number Diff line change
@@ -130,6 +130,7 @@ func TestParsePayload(t *testing.T) {
})
}
}

func TestParsePayload_Errors(t *testing.T) {
tests := []struct {
name string
6 changes: 3 additions & 3 deletions pkg/provider/azuredevops/types/change.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package azuredevops

type Item struct {
CommitId string `json:"commitId"`
CommitID string `json:"commitId"`
GitObjectType string `json:"gitObjectType"`
IsFolder bool `json:"isFolder"`
ObjectId string `json:"objectId"`
OriginalObjectId string `json:"originalObjectId"`
ObjectID string `json:"objectId"`
OriginalObjectID string `json:"originalObjectId"`
Path string `json:"path"`
URL string `json:"url"`
}
44 changes: 22 additions & 22 deletions pkg/provider/azuredevops/types/types.go
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@ import (

type PullRequestEventResource struct {
Repository Repository `json:"repository"`
PullRequestId int `json:"pullRequestId"`
CodeReviewId int `json:"codeReviewId,omitempty"`
PullRequestID int `json:"pullRequestId"`
CodeReviewID int `json:"codeReviewId,omitempty"`
Status string `json:"status"`
CreatedBy User `json:"createdBy"`
CreationDate CustomTime `json:"creationDate"`
@@ -17,59 +17,59 @@ type PullRequestEventResource struct {
TargetRefName string `json:"targetRefName"`
MergeStatus string `json:"mergeStatus"`
IsDraft bool `json:"isDraft,omitempty"`
MergeId string `json:"mergeId"`
MergeID string `json:"mergeId"`
LastMergeSourceCommit Commit `json:"lastMergeSourceCommit"`
LastMergeTargetCommit Commit `json:"lastMergeTargetCommit"`
LastMergeCommit Commit `json:"lastMergeCommit,omitempty"`
Reviewers []User `json:"reviewers"`
Url string `json:"url"`
URL string `json:"url"`
Links Links `json:"_links"`
SupportsIterations bool `json:"supportsIterations,omitempty"`
ArtifactId string `json:"artifactId,omitempty"`
ArtifactID string `json:"artifactId,omitempty"`
}

type PushEventResource struct {
Commits []Commit `json:"commits"`
RefUpdates []RefUpdate `json:"refUpdates"`
Repository Repository `json:"repository"`
PushedBy User `json:"pushedBy"`
PushId int `json:"pushId"`
PushID int `json:"pushId"`
Date CustomTime `json:"date"`
Url string `json:"url"`
URL string `json:"url"`
}

type Commit struct {
CommitId string `json:"commitId,omitempty"`
CommitID string `json:"commitId,omitempty"`
Author User `json:"author,omitempty"`
Committer User `json:"committer,omitempty"`
Comment string `json:"comment,omitempty"`
Url string `json:"url,omitempty"`
URL string `json:"url,omitempty"`
}

type RefUpdate struct {
Name string `json:"name"`
OldObjectId string `json:"oldObjectId"`
NewObjectId string `json:"newObjectId"`
OldObjectID string `json:"oldObjectId"`
NewObjectID string `json:"newObjectId"`
}

type Repository struct {
Id string `json:"id"`
ID string `json:"id"`
Name string `json:"name"`
Url string `json:"url"`
URL string `json:"url"`
Project Project `json:"project"`
DefaultBranch string `json:"defaultBranch,omitempty"`
Size *int `json:"size,omitempty"`
RemoteUrl string `json:"remoteUrl"`
SshUrl *string `json:"sshUrl,omitempty"`
WebUrl *string `json:"webUrl,omitempty"`
RemoteURL string `json:"remoteUrl"`
SSHURL *string `json:"sshUrl,omitempty"`
WebURL *string `json:"webUrl,omitempty"`
IsDisabled *bool `json:"isDisabled,omitempty"`
IsInMaintenance *bool `json:"isInMaintenance,omitempty"`
}

type Project struct {
Id string `json:"id"`
ID string `json:"id"`
Name string `json:"name"`
Url string `json:"url"`
URL string `json:"url"`
State string `json:"state"`
Revision int `json:"revision,omitempty"`
Visibility string `json:"visibility"`
@@ -81,11 +81,11 @@ type User struct {
Email string `json:"email,omitempty"`
Date CustomTime `json:"date,omitempty"`
DisplayName string `json:"displayName,omitempty"`
Url string `json:"url,omitempty"`
URL string `json:"url,omitempty"`
Links Links `json:"_links,omitempty"`
Id string `json:"id,omitempty"`
ID string `json:"id,omitempty"`
UniqueName string `json:"uniqueName,omitempty"`
ImageUrl string `json:"imageUrl,omitempty"`
ImageURL string `json:"imageUrl,omitempty"`
Descriptor string `json:"descriptor,omitempty"`
}

@@ -96,7 +96,7 @@ type ResourceContainers struct {
}

type Container struct {
Id string `json:"id"`
ID string `json:"id"`
}

type Links struct {
8 changes: 4 additions & 4 deletions pkg/reconciler/event.go
Original file line number Diff line number Diff line change
@@ -103,11 +103,11 @@ func buildEventFromPipelineRun(pr *tektonv1.PipelineRun) *info.Event {
if organizationID, ok := prAnno[keys.URLOrg]; ok {
event.Organization = organizationID
}
if projectID, ok := prAnno[keys.ProjectId]; ok {
event.ProjectId = projectID
if projectID, ok := prAnno[keys.ProjectID]; ok {
event.ProjectID = projectID
}
if repositoryID, ok := prAnno[keys.RepositoryId]; ok {
event.RepositoryId = repositoryID
if repositoryID, ok := prAnno[keys.RepositoryID]; ok {
event.RepositoryID = repositoryID
}
}