Skip to content

Commit

Permalink
Fix wrong pull request branch parsing in Azure (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
omerzi authored Aug 21, 2023
1 parent 3904186 commit e4c1bb7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions vcsclient/azurerepos.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"github.com/go-git/go-git/v5/plumbing"
"github.com/jfrog/froggit-go/vcsutils"
"github.com/jfrog/gofrog/datastructures"
"github.com/microsoft/azure-devops-go-api/azuredevops"
Expand Down Expand Up @@ -610,8 +611,8 @@ func (client *AzureReposClient) GetModifiedFiles(ctx context.Context, _, reposit

func parsePullRequestDetails(client *AzureReposClient, pullRequest git.GitPullRequest, owner, repository string, withBody bool) PullRequestInfo {
// Trim the branches prefix and get the actual branches name
shortSourceName := (*pullRequest.SourceRefName)[strings.LastIndex(*pullRequest.SourceRefName, "/")+1:]
shortTargetName := (*pullRequest.TargetRefName)[strings.LastIndex(*pullRequest.TargetRefName, "/")+1:]
shortSourceName := plumbing.ReferenceName(*pullRequest.SourceRefName).Short()
shortTargetName := plumbing.ReferenceName(*pullRequest.TargetRefName).Short()

var prBody string
bodyPtr := pullRequest.Description
Expand Down
6 changes: 4 additions & 2 deletions vcsclient/azurerepos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,17 @@ func TestAzureRepos_TestListOpenPullRequests(t *testing.T) {

// Test with body
prBody := "hello world"
branch1WithPrefix := "refs/heads/" + branch1
branch2WithPrefix := "refs/heads/" + branch2
res = ListOpenPullRequestsResponse{
Value: []git.GitPullRequest{
{
PullRequestId: &pullRequestId,
Description: &prBody,
Url: &url,
Repository: &git.GitRepository{Name: &repo1},
SourceRefName: &branch1,
TargetRefName: &branch2,
SourceRefName: &branch1WithPrefix,
TargetRefName: &branch2WithPrefix,
},
},
Count: 1,
Expand Down

0 comments on commit e4c1bb7

Please sign in to comment.