From 429d52b3f0190dda3dffaf4b90931ebf285b2541 Mon Sep 17 00:00:00 2001 From: Omer Zidkoni Date: Tue, 8 Aug 2023 13:07:59 +0300 Subject: [PATCH 1/8] Add pull request url to PullRequestInfo --- go.mod | 7 ++- go.sum | 24 ++++++++-- vcsclient/azurerepos.go | 3 +- vcsclient/azurerepos_test.go | 40 ++++++++++++++--- vcsclient/bitbucketserver.go | 42 +++++++---------- vcsclient/bitbucketserver_test.go | 3 ++ vcsclient/github.go | 74 +++++++++++++++++------------- vcsclient/github_test.go | 7 ++- vcsclient/gitlab.go | 75 ++++++++++++++++--------------- vcsclient/gitlab_test.go | 10 ++++- vcsclient/vcsclient.go | 1 + 11 files changed, 177 insertions(+), 109 deletions(-) diff --git a/go.mod b/go.mod index 31b76c88..d57f5c9e 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/mitchellh/mapstructure v1.5.0 github.com/stretchr/testify v1.8.4 github.com/xanzy/go-gitlab v0.88.0 + golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691 golang.org/x/oauth2 v0.10.0 ) @@ -25,23 +26,25 @@ require ( github.com/cloudflare/circl v1.3.3 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/emirpasic/gods v1.18.1 // indirect + github.com/fatih/color v1.13.0 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect github.com/go-git/go-billy/v5 v5.4.1 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect + github.com/hashicorp/go-hclog v1.2.0 // indirect github.com/hashicorp/go-retryablehttp v0.7.2 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/kevinburke/ssh_config v1.2.0 // indirect + github.com/mattn/go-colorable v0.1.12 // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/sergi/go-diff v1.1.0 // indirect github.com/skeema/knownhosts v1.2.0 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect golang.org/x/crypto v0.11.0 // indirect - golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect - golang.org/x/mod v0.9.0 // indirect + golang.org/x/mod v0.11.0 // indirect golang.org/x/net v0.12.0 // indirect golang.org/x/sys v0.10.0 // indirect golang.org/x/time v0.3.0 // indirect diff --git a/go.sum b/go.sum index 28d3bcf1..d3bf8592 100644 --- a/go.sum +++ b/go.sum @@ -673,6 +673,9 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/envoyproxy/protoc-gen-validate v0.6.7/go.mod h1:dyJXwwfPK2VSqiB9Klm1J6romD608Ba7Hij42vrOBCo= github.com/envoyproxy/protoc-gen-validate v0.9.1/go.mod h1:OKNgG7TCp5pF4d6XftA0++PMirau2/yoOwVac3AbF2w= github.com/envoyproxy/protoc-gen-validate v0.10.0/go.mod h1:DRjgyB0I43LtJapqN6NiRwroiAU2PaFuvk/vjgh61ss= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= +github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/gfleury/go-bitbucket-v1 v0.0.0-20230626192437-8d7be5866751 h1:Ea58sAu8LX/NS7z3aeL+YX/7+FSd9jsxq6Ecpz7QEDM= @@ -817,8 +820,9 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0/go.mod h1:hgWBS7lorOAVIJEQMi4Zs github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3/go.mod h1:o//XUCC/F+yRGJoPO/VU0GSB0f8Nhgmxx0VIRUvaC0w= github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= -github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI= github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= +github.com/hashicorp/go-hclog v1.2.0 h1:La19f8d7WIlm4ogzNHB0JGqs5AUDAZ2UfCY4sJXcJdM= +github.com/hashicorp/go-hclog v1.2.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-retryablehttp v0.7.2 h1:AcYqCvkpalPnPF2pn0KamgwamS42TqUDDYFRKq/RAd0= github.com/hashicorp/go-retryablehttp v0.7.2/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= @@ -860,7 +864,15 @@ github.com/lyft/protoc-gen-star/v2 v2.0.1/go.mod h1:RcCdONR2ScXaYnQC5tUzxzlpA3WV github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A= github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= +github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-sqlite3 v1.14.14/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/microsoft/azure-devops-go-api/azuredevops v1.0.0-b5 h1:YH424zrwLTlyHSH/GzLMJeu5zhYVZSx5RQxGKm1h96s= @@ -974,8 +986,8 @@ golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/exp v0.0.0-20220827204233-334a2380cb91/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= -golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc= -golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= +golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691 h1:/yRP+0AN7mf5DkD3BAI6TOFnd51gEoDEb8o35jIFtgw= +golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= @@ -1017,8 +1029,9 @@ golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs= golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= +golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1133,6 +1146,7 @@ golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1141,6 +1155,7 @@ golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1184,6 +1199,7 @@ golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/vcsclient/azurerepos.go b/vcsclient/azurerepos.go index 99e71f3c..497ceabe 100644 --- a/vcsclient/azurerepos.go +++ b/vcsclient/azurerepos.go @@ -586,7 +586,7 @@ func parsePullRequestDetails(client *AzureReposClient, pullRequest git.GitPullRe prBody = *bodyPtr } - // When a pull request is from a forked repository,extract the owner. + // When a pull request is from a forked repository, extract the owner. sourceRepoOwner := owner if pullRequest.ForkSource != nil { if sourceRepoOwner = extractOwnerFromForkedRepoUrl(pullRequest.ForkSource); sourceRepoOwner == "" { @@ -597,6 +597,7 @@ func parsePullRequestDetails(client *AzureReposClient, pullRequest git.GitPullRe return PullRequestInfo{ ID: int64(*pullRequest.PullRequestId), Body: prBody, + URL: vcsutils.DefaultIfNotNil(pullRequest.Url), Source: BranchInfo{ Name: shortSourceName, Repository: repository, diff --git a/vcsclient/azurerepos_test.go b/vcsclient/azurerepos_test.go index 3148e172..127d8793 100644 --- a/vcsclient/azurerepos_test.go +++ b/vcsclient/azurerepos_test.go @@ -185,6 +185,7 @@ func TestAzureRepos_TestListOpenPullRequests(t *testing.T) { Count int } pullRequestId := 1 + url := "https://dev.azure.com/owner/project/_git/repo/pullrequest/47" res := ListOpenPullRequestsResponse{ Value: []git.GitPullRequest{ { @@ -192,6 +193,7 @@ func TestAzureRepos_TestListOpenPullRequests(t *testing.T) { Repository: &git.GitRepository{Name: &repo1}, SourceRefName: &branch1, TargetRefName: &branch2, + Url: &url, }, }, Count: 1, @@ -203,7 +205,14 @@ func TestAzureRepos_TestListOpenPullRequests(t *testing.T) { defer cleanUp() pullRequestsInfo, err := client.ListOpenPullRequests(ctx, "", repo1) assert.NoError(t, err) - assert.EqualValues(t, pullRequestsInfo, []PullRequestInfo{{ID: 1, Source: BranchInfo{Name: branch1, Repository: repo1}, Target: BranchInfo{Name: branch2, Repository: repo1}}}) + assert.EqualValues(t, pullRequestsInfo, []PullRequestInfo{ + { + ID: 1, + Source: BranchInfo{Name: branch1, Repository: repo1}, + Target: BranchInfo{Name: branch2, Repository: repo1}, + URL: url, + }, + }) badClient, cleanUp := createBadAzureReposClient(t, []byte{}) defer cleanUp() @@ -217,6 +226,7 @@ func TestAzureRepos_TestListOpenPullRequests(t *testing.T) { { PullRequestId: &pullRequestId, Description: &prBody, + Url: &url, Repository: &git.GitRepository{Name: &repo1}, SourceRefName: &branch1, TargetRefName: &branch2, @@ -231,7 +241,15 @@ func TestAzureRepos_TestListOpenPullRequests(t *testing.T) { defer cleanUp() pullRequestsInfo, err = client.ListOpenPullRequestsWithBody(ctx, "", repo1) assert.NoError(t, err) - assert.EqualValues(t, pullRequestsInfo, []PullRequestInfo{{ID: 1, Body: prBody, Source: BranchInfo{Name: branch1, Repository: repo1}, Target: BranchInfo{Name: branch2, Repository: repo1}}}) + assert.EqualValues(t, pullRequestsInfo, []PullRequestInfo{ + { + ID: 1, + Body: prBody, + Source: BranchInfo{Name: branch1, Repository: repo1}, + Target: BranchInfo{Name: branch2, Repository: repo1}, + URL: url, + }, + }) badClient, cleanUp = createBadAzureReposClient(t, []byte{}) defer cleanUp() @@ -246,6 +264,7 @@ func TestAzureReposClient_GetPullRequest(t *testing.T) { targetName := "master" forkedOwner := "jfrogForked" forkedSourceUrl := fmt.Sprintf("https://dev.azure.com/%s/201f2c7f-305a-446c-a1d6-a04ec811093b/_apis/git/repositories/82d33a66-8971-4279-9687-19c69e66e114", forkedOwner) + url := "https://dev.azure.com/owner/project/_git/repo/pullrequest/47" res := git.GitPullRequest{ SourceRefName: &sourceName, TargetRefName: &targetName, @@ -253,6 +272,7 @@ func TestAzureReposClient_GetPullRequest(t *testing.T) { ForkSource: &git.GitForkRef{ Repository: &git.GitRepository{Url: &forkedSourceUrl}, }, + Url: &url, } jsonRes, err := json.Marshal(res) assert.NoError(t, err) @@ -261,9 +281,12 @@ func TestAzureReposClient_GetPullRequest(t *testing.T) { defer cleanUp() pullRequestsInfo, err := client.GetPullRequestByID(ctx, owner, repoName, pullRequestId) assert.NoError(t, err) - assert.EqualValues(t, pullRequestsInfo, PullRequestInfo{ID: 1, + assert.EqualValues(t, pullRequestsInfo, PullRequestInfo{ + ID: 1, Source: BranchInfo{Name: sourceName, Repository: repoName, Owner: forkedOwner}, - Target: BranchInfo{Name: targetName, Repository: repoName, Owner: owner}}) + Target: BranchInfo{Name: targetName, Repository: repoName, Owner: owner}, + URL: url, + }) // Fail source repository owner extraction, should be empty string and not fail the process. res = git.GitPullRequest{ @@ -273,15 +296,20 @@ func TestAzureReposClient_GetPullRequest(t *testing.T) { ForkSource: &git.GitForkRef{ Repository: &git.GitRepository{Url: &repoName}, }, + Url: &url, } jsonRes, err = json.Marshal(res) assert.NoError(t, err) client, _ = createServerAndClient(t, vcsutils.AzureRepos, true, jsonRes, fmt.Sprintf("getPullRequests/%d", pullRequestId), createAzureReposHandler) pullRequestsInfo, err = client.GetPullRequestByID(ctx, owner, repoName, pullRequestId) assert.NoError(t, err) - assert.EqualValues(t, pullRequestsInfo, PullRequestInfo{ID: 1, + assert.EqualValues(t, pullRequestsInfo, PullRequestInfo{ + ID: 1, Source: BranchInfo{Name: sourceName, Repository: repoName, Owner: ""}, - Target: BranchInfo{Name: targetName, Repository: repoName, Owner: owner}}) + Target: BranchInfo{Name: targetName, Repository: repoName, Owner: owner}, + URL: url, + }, + ) // Bad client badClient, cleanUp := createBadAzureReposClient(t, []byte{}) diff --git a/vcsclient/bitbucketserver.go b/vcsclient/bitbucketserver.go index 425654e7..4c011f99 100644 --- a/vcsclient/bitbucketserver.go +++ b/vcsclient/bitbucketserver.go @@ -345,30 +345,12 @@ func (client *BitbucketServerClient) getOpenPullRequests(ctx context.Context, ow return nil, err } for _, pullRequest := range pullRequests { - var body string - if withBody { - body = pullRequest.Description - } if pullRequest.Open { - var sourceOwner string - sourceOwner, err = getSourceRepositoryOwner(pullRequest) - if err != nil { + var pullRequestInfo PullRequestInfo + if pullRequestInfo, err = mapBitbucketServerPullRequestToPullRequestInfo(pullRequest, withBody, owner); err != nil { return nil, err } - results = append(results, PullRequestInfo{ - ID: int64(pullRequest.ID), - Body: body, - Source: BranchInfo{ - Name: pullRequest.FromRef.DisplayID, - Repository: pullRequest.FromRef.Repository.Slug, - Owner: sourceOwner, - }, - Target: BranchInfo{ - Name: pullRequest.ToRef.DisplayID, - Repository: pullRequest.ToRef.Repository.Slug, - Owner: owner, - }, - }) + results = append(results, pullRequestInfo) } } } @@ -392,16 +374,26 @@ func (client *BitbucketServerClient) GetPullRequestByID(ctx context.Context, own if err != nil { return } + pullRequestInfo, err = mapBitbucketServerPullRequestToPullRequestInfo(pullRequest, false, owner) + return +} + +func mapBitbucketServerPullRequestToPullRequestInfo(pullRequest bitbucketv1.PullRequest, withBody bool, owner string) (PullRequestInfo, error) { sourceOwner, err := getSourceRepositoryOwner(pullRequest) if err != nil { - return + return PullRequestInfo{}, err + } + var body string + if withBody { + body = pullRequest.Description } - pullRequestInfo = PullRequestInfo{ + return PullRequestInfo{ ID: int64(pullRequest.ID), Source: BranchInfo{Name: pullRequest.FromRef.ID, Repository: pullRequest.ToRef.Repository.Slug, Owner: sourceOwner}, Target: BranchInfo{Name: pullRequest.ToRef.ID, Repository: pullRequest.ToRef.Repository.Slug, Owner: owner}, - } - return + Body: body, + URL: pullRequest.Links.Self[0].Href, + }, nil } // AddPullRequestComment on Bitbucket server diff --git a/vcsclient/bitbucketserver_test.go b/vcsclient/bitbucketserver_test.go index 36ddbcf2..b5b4f169 100644 --- a/vcsclient/bitbucketserver_test.go +++ b/vcsclient/bitbucketserver_test.go @@ -225,6 +225,7 @@ func TestBitbucketServer_ListOpenPullRequests(t *testing.T) { ID: 101, Source: BranchInfo{Name: "feature-ABC-123", Repository: repo1, Owner: forkedOwner}, Target: BranchInfo{Name: "master", Repository: repo1, Owner: owner}, + URL: "https://link/to/pullrequest", }, result[0]) // With body: @@ -237,6 +238,7 @@ func TestBitbucketServer_ListOpenPullRequests(t *testing.T) { Body: "hello world", Source: BranchInfo{Name: "feature-ABC-123", Repository: repo1, Owner: forkedOwner}, Target: BranchInfo{Name: "master", Repository: repo1, Owner: owner}, + URL: "https://link/to/pullrequest", }, result[0]) } @@ -256,6 +258,7 @@ func TestBitbucketServerClient_GetPullRequest(t *testing.T) { ID: int64(pullRequestId), Source: BranchInfo{Name: "refs/heads/new_vul_2", Repository: "repoName", Owner: "~fromOwner"}, Target: BranchInfo{Name: "refs/heads/master", Repository: "repoName", Owner: owner}, + URL: "https://git.bbServerHost.info/users/owner/repos/repoName/pull-requests/6", }, result) // Failed owner extraction diff --git a/vcsclient/github.go b/vcsclient/github.go index 1d2ec3ae..18ec85c9 100644 --- a/vcsclient/github.go +++ b/vcsclient/github.go @@ -336,27 +336,53 @@ func (client *GitHubClient) GetPullRequestByID(ctx context.Context, owner, repos } } - sourceBranch, err1 := extractBranchFromLabel(vcsutils.DefaultIfNotNil(pullRequest.Head.Label)) - targetBranch, err2 := extractBranchFromLabel(vcsutils.DefaultIfNotNil(pullRequest.Base.Label)) - err = errors.Join(err1, err2) - if err != nil { - return PullRequestInfo{}, err + return mapGitHubPullRequestToPullRequestInfo(pullRequest, false) +} + +func mapGitHubPullRequestToPullRequestInfo(ghPullRequest *github.PullRequest, withBody bool) (PullRequestInfo, error) { + var sourceBranch, targetBranch string + var err1, err2 error + if ghPullRequest != nil && ghPullRequest.Head != nil && ghPullRequest.Base != nil { + sourceBranch, err1 = extractBranchFromLabel(vcsutils.DefaultIfNotNil(ghPullRequest.Head.Label)) + targetBranch, err2 = extractBranchFromLabel(vcsutils.DefaultIfNotNil(ghPullRequest.Base.Label)) + err := errors.Join(err1, err2) + if err != nil { + return PullRequestInfo{}, err + } + } + + var sourceRepoName, sourceRepoOwner string + if ghPullRequest.Head.Repo != nil && ghPullRequest.Head.Repo.Owner != nil { + sourceRepoName = vcsutils.DefaultIfNotNil(ghPullRequest.Head.Repo.Name) + sourceRepoOwner = vcsutils.DefaultIfNotNil(ghPullRequest.Head.Repo.Owner.Login) + } + + var targetRepoName, targetRepoOwner string + if ghPullRequest.Base.Repo != nil && ghPullRequest.Base.Repo.Owner != nil { + targetRepoName = vcsutils.DefaultIfNotNil(ghPullRequest.Base.Repo.Name) + targetRepoOwner = vcsutils.DefaultIfNotNil(ghPullRequest.Base.Repo.Owner.Login) + } + + var body string + if withBody { + body = vcsutils.DefaultIfNotNil(ghPullRequest.Body) } - prInfo := PullRequestInfo{ - ID: int64(pullRequestId), + return PullRequestInfo{ + ID: vcsutils.DefaultIfNotNil(ghPullRequest.ID), + URL: vcsutils.DefaultIfNotNil(ghPullRequest.HTMLURL), + Body: body, Source: BranchInfo{ Name: sourceBranch, - Repository: vcsutils.DefaultIfNotNil(pullRequest.Head.Repo.Name), - Owner: vcsutils.DefaultIfNotNil(pullRequest.Head.Repo.Owner.Login), + Repository: sourceRepoName, + Owner: sourceRepoOwner, }, Target: BranchInfo{ Name: targetBranch, - Repository: vcsutils.DefaultIfNotNil(pullRequest.Base.Repo.Name), - Owner: vcsutils.DefaultIfNotNil(pullRequest.Base.Repo.Owner.Login), + Repository: targetRepoName, + Owner: targetRepoOwner, }, - } - return prInfo, nil + }, nil } // Extracts branch name from the following expected label format repo:branch @@ -830,25 +856,13 @@ func mapGitHubCommentToCommentInfoList(commentsList []*github.IssueComment) (res } func mapGitHubPullRequestToPullRequestInfoList(pullRequestList []*github.PullRequest, withBody bool) (res []PullRequestInfo, err error) { + var mappedPullRequest PullRequestInfo for _, pullRequest := range pullRequestList { - var body string - if withBody { - body = *pullRequest.Body + mappedPullRequest, err = mapGitHubPullRequestToPullRequestInfo(pullRequest, withBody) + if err != nil { + return } - res = append(res, PullRequestInfo{ - ID: int64(vcsutils.DefaultIfNotNil(pullRequest.Number)), - Body: body, - Source: BranchInfo{ - Name: vcsutils.DefaultIfNotNil(pullRequest.Head.Ref), - Repository: vcsutils.DefaultIfNotNil(pullRequest.Head.Repo.Name), - Owner: vcsutils.DefaultIfNotNil(pullRequest.Head.Repo.Owner.Login), - }, - Target: BranchInfo{ - Name: vcsutils.DefaultIfNotNil(pullRequest.Base.Ref), - Repository: vcsutils.DefaultIfNotNil(pullRequest.Base.Repo.Name), - Owner: vcsutils.DefaultIfNotNil(pullRequest.Base.Repo.Owner.Login), - }, - }) + res = append(res, mappedPullRequest) } return } diff --git a/vcsclient/github_test.go b/vcsclient/github_test.go index 0605cd9b..2d2e98f9 100644 --- a/vcsclient/github_test.go +++ b/vcsclient/github_test.go @@ -534,9 +534,10 @@ func TestGitHubClient_ListOpenPullRequests(t *testing.T) { assert.Len(t, result, 1) assert.NoError(t, err) assert.EqualValues(t, PullRequestInfo{ - ID: 1, + ID: 1347, Source: BranchInfo{Name: "new-topic", Repository: "Hello-World", Owner: owner}, Target: BranchInfo{Name: "master", Repository: "Hello-World", Owner: owner}, + URL: "https://github.com/octocat/Hello-World/pull/1347", }, result[0]) _, err = createBadGitHubClient(t).ListPullRequestComments(ctx, owner, repo1, 1) @@ -548,10 +549,11 @@ func TestGitHubClient_ListOpenPullRequests(t *testing.T) { assert.Len(t, result, 1) assert.NoError(t, err) assert.EqualValues(t, PullRequestInfo{ - ID: 1, + ID: 1347, Body: "hello world", Source: BranchInfo{Name: "new-topic", Repository: "Hello-World", Owner: owner}, Target: BranchInfo{Name: "master", Repository: "Hello-World", Owner: owner}, + URL: "https://github.com/octocat/Hello-World/pull/1347", }, result[0]) _, err = createBadGitHubClient(t).ListPullRequestComments(ctx, owner, repo1, 1) @@ -577,6 +579,7 @@ func TestGitHubClient_GetPullRequestByID(t *testing.T) { ID: int64(pullRequestId), Source: BranchInfo{Name: "new-topic", Repository: "Hello-World", Owner: owner}, Target: BranchInfo{Name: "master", Repository: "Hello-World", Owner: forkedOwner}, + URL: "https://github.com/octocat/Hello-World/pull/1347", }, result) // Bad Labels diff --git a/vcsclient/gitlab.go b/vcsclient/gitlab.go index da1e4ad9..842adb5a 100644 --- a/vcsclient/gitlab.go +++ b/vcsclient/gitlab.go @@ -269,7 +269,7 @@ func (client *GitLabClient) getOpenPullRequests(ctx context.Context, owner, repo if err != nil { return []PullRequestInfo{}, err } - return mapGitLabMergeRequestToPullRequestInfoList(mergeRequests, client, owner, repository, withBody) + return client.mapGitLabMergeRequestToPullRequestInfoList(mergeRequests, owner, repository, withBody) } // GetPullRequestInfoById on GitLab @@ -284,17 +284,7 @@ func (client *GitLabClient) GetPullRequestByID(_ context.Context, owner, reposit return PullRequestInfo{}, err } } - sourceOwner := owner - if mergeRequest.SourceProjectID != mergeRequest.TargetProjectID { - if sourceOwner, err = getProjectOwnerByID(mergeRequest.SourceProjectID, client); err != nil { - return PullRequestInfo{}, err - } - } - pullRequestInfo = PullRequestInfo{ - ID: int64(mergeRequest.ID), - Source: BranchInfo{Name: mergeRequest.SourceBranch, Repository: repository, Owner: sourceOwner}, - Target: BranchInfo{Name: mergeRequest.TargetBranch, Repository: repository, Owner: owner}, - } + pullRequestInfo, err = client.mapGitLabMergeRequestToPullRequestInfo(mergeRequest, false, owner, repository) return } @@ -599,37 +589,48 @@ func mapGitLabNotesToCommentInfoList(notes []*gitlab.Note) (res []CommentInfo) { return } -func mapGitLabMergeRequestToPullRequestInfoList(mergeRequests []*gitlab.MergeRequest, client *GitLabClient, owner, repository string, withBody bool) (res []PullRequestInfo, err error) { +func (client *GitLabClient) mapGitLabMergeRequestToPullRequestInfoList(mergeRequests []*gitlab.MergeRequest, owner, repository string, withBody bool) (res []PullRequestInfo, err error) { for _, mergeRequest := range mergeRequests { - var body string - if withBody { - body = mergeRequest.Description + var mergeRequestInfo PullRequestInfo + if mergeRequestInfo, err = client.mapGitLabMergeRequestToPullRequestInfo(mergeRequest, withBody, owner, repository); err != nil { + return } - sourceOwner := owner - if mergeRequest.SourceProjectID != mergeRequest.TargetProjectID { - if sourceOwner, err = getProjectOwnerByID(mergeRequest.SourceProjectID, client); err != nil { - return - } - } - res = append(res, PullRequestInfo{ - ID: int64(mergeRequest.IID), - Body: body, - Source: BranchInfo{ - Name: mergeRequest.SourceBranch, - Repository: repository, - Owner: sourceOwner, - }, - Target: BranchInfo{ - Name: mergeRequest.TargetBranch, - Repository: repository, - Owner: owner, - }, - }) + res = append(res, mergeRequestInfo) } return } -func getProjectOwnerByID(projectID int, client *GitLabClient) (string, error) { +func (client *GitLabClient) mapGitLabMergeRequestToPullRequestInfo(mergeRequest *gitlab.MergeRequest, withBody bool, owner, repository string) (PullRequestInfo, error) { + var body string + if withBody { + body = mergeRequest.Description + } + sourceOwner := owner + var err error + if mergeRequest.SourceProjectID != mergeRequest.TargetProjectID { + if sourceOwner, err = client.getProjectOwnerByID(mergeRequest.SourceProjectID); err != nil { + return PullRequestInfo{}, err + } + } + + return PullRequestInfo{ + ID: int64(mergeRequest.IID), + Body: body, + Source: BranchInfo{ + Name: mergeRequest.SourceBranch, + Repository: repository, + Owner: sourceOwner, + }, + URL: mergeRequest.WebURL, + Target: BranchInfo{ + Name: mergeRequest.TargetBranch, + Repository: repository, + Owner: owner, + }, + }, nil +} + +func (client *GitLabClient) getProjectOwnerByID(projectID int) (string, error) { project, glResponse, err := client.glClient.Projects.GetProject(projectID, &gitlab.GetProjectOptions{}) if err != nil { return "", err diff --git a/vcsclient/gitlab_test.go b/vcsclient/gitlab_test.go index ce21f846..1cd05ffd 100644 --- a/vcsclient/gitlab_test.go +++ b/vcsclient/gitlab_test.go @@ -224,6 +224,7 @@ func TestGitLabClient_ListOpenPullRequests(t *testing.T) { ID: 302, Source: BranchInfo{Name: "test1", Repository: repo1, Owner: owner}, Target: BranchInfo{Name: "master", Repository: repo1, Owner: owner}, + URL: "https://gitlab.example.com/my-group/my-project/merge_requests/1", }, result[0]) // With body @@ -235,6 +236,7 @@ func TestGitLabClient_ListOpenPullRequests(t *testing.T) { Body: "hello world", Source: BranchInfo{Name: "test1", Repository: repo1, Owner: owner}, Target: BranchInfo{Name: "master", Repository: repo1, Owner: owner}, + URL: "https://gitlab.example.com/my-group/my-project/merge_requests/1", }, result[0]) } @@ -255,6 +257,7 @@ func TestGitLabClient_GetPullRequestByID(t *testing.T) { ID: 1, Source: BranchInfo{Name: "manual-job-rules", Repository: repoName, Owner: owner}, Target: BranchInfo{Name: "master", Repository: repoName, Owner: owner}, + URL: "https://gitlab.com/marcel.amirault/test-project/-/merge_requests/133", }, result) // Bad client @@ -732,14 +735,17 @@ func TestGitLabClient_getProjectOwnerByID(t *testing.T) { client, cleanUp := createServerAndClient(t, vcsutils.GitLab, false, response, fmt.Sprintf("/api/v4/projects/%d", projectID), createGitLabHandler) defer cleanUp() - projectOwner, err := getProjectOwnerByID(projectID, client.(*GitLabClient)) + + glClient := client.(*GitLabClient) + projectOwner, err := glClient.getProjectOwnerByID(projectID) assert.NoError(t, err) assert.Equal(t, "test", projectOwner) badClient, badClientCleanUp := createServerAndClient(t, vcsutils.GitLab, false, nil, fmt.Sprintf("/api/v4/projects/%d", projectID), createGitLabHandler) defer badClientCleanUp() - projectOwner, err = getProjectOwnerByID(projectID, badClient.(*GitLabClient)) + badGlClient := badClient.(*GitLabClient) + projectOwner, err = badGlClient.getProjectOwnerByID(projectID) assert.Error(t, err) assert.NotEqual(t, "test", projectOwner) } diff --git a/vcsclient/vcsclient.go b/vcsclient/vcsclient.go index d4df7464..c63a3b02 100644 --- a/vcsclient/vcsclient.go +++ b/vcsclient/vcsclient.go @@ -300,6 +300,7 @@ type CommentInfo struct { type PullRequestInfo struct { ID int64 Body string + URL string Source BranchInfo Target BranchInfo } From b871985eab1e58ea4c487d5b8306ca160ad960a6 Mon Sep 17 00:00:00 2001 From: Omer Zidkoni Date: Tue, 8 Aug 2023 13:13:32 +0300 Subject: [PATCH 2/8] Add pull request url to PullRequestInfo --- vcsclient/gitlab_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vcsclient/gitlab_test.go b/vcsclient/gitlab_test.go index 1cd05ffd..e1896360 100644 --- a/vcsclient/gitlab_test.go +++ b/vcsclient/gitlab_test.go @@ -736,7 +736,8 @@ func TestGitLabClient_getProjectOwnerByID(t *testing.T) { fmt.Sprintf("/api/v4/projects/%d", projectID), createGitLabHandler) defer cleanUp() - glClient := client.(*GitLabClient) + glClient, ok := client.(*GitLabClient) + assert.True(t, ok) projectOwner, err := glClient.getProjectOwnerByID(projectID) assert.NoError(t, err) assert.Equal(t, "test", projectOwner) @@ -744,7 +745,8 @@ func TestGitLabClient_getProjectOwnerByID(t *testing.T) { badClient, badClientCleanUp := createServerAndClient(t, vcsutils.GitLab, false, nil, fmt.Sprintf("/api/v4/projects/%d", projectID), createGitLabHandler) defer badClientCleanUp() - badGlClient := badClient.(*GitLabClient) + badGlClient, ok := badClient.(*GitLabClient) + assert.True(t, ok) projectOwner, err = badGlClient.getProjectOwnerByID(projectID) assert.Error(t, err) assert.NotEqual(t, "test", projectOwner) From 16839f4f674bcc7e0c123f68364e69f721e48e00 Mon Sep 17 00:00:00 2001 From: Omer Zidkoni Date: Tue, 8 Aug 2023 13:26:44 +0300 Subject: [PATCH 3/8] Add pull request url to PullRequestInfo --- vcsclient/bitbucketserver.go | 4 ++-- vcsclient/gitlab_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/vcsclient/bitbucketserver.go b/vcsclient/bitbucketserver.go index 4c011f99..358d6faf 100644 --- a/vcsclient/bitbucketserver.go +++ b/vcsclient/bitbucketserver.go @@ -389,8 +389,8 @@ func mapBitbucketServerPullRequestToPullRequestInfo(pullRequest bitbucketv1.Pull } return PullRequestInfo{ ID: int64(pullRequest.ID), - Source: BranchInfo{Name: pullRequest.FromRef.ID, Repository: pullRequest.ToRef.Repository.Slug, Owner: sourceOwner}, - Target: BranchInfo{Name: pullRequest.ToRef.ID, Repository: pullRequest.ToRef.Repository.Slug, Owner: owner}, + Source: BranchInfo{Name: pullRequest.FromRef.DisplayID, Repository: pullRequest.ToRef.Repository.Slug, Owner: sourceOwner}, + Target: BranchInfo{Name: pullRequest.ToRef.DisplayID, Repository: pullRequest.ToRef.Repository.Slug, Owner: owner}, Body: body, URL: pullRequest.Links.Self[0].Href, }, nil diff --git a/vcsclient/gitlab_test.go b/vcsclient/gitlab_test.go index e1896360..cd27a579 100644 --- a/vcsclient/gitlab_test.go +++ b/vcsclient/gitlab_test.go @@ -254,7 +254,7 @@ func TestGitLabClient_GetPullRequestByID(t *testing.T) { result, err := client.GetPullRequestByID(ctx, owner, repoName, pullRequestId) assert.NoError(t, err) assert.EqualValues(t, PullRequestInfo{ - ID: 1, + ID: 133, Source: BranchInfo{Name: "manual-job-rules", Repository: repoName, Owner: owner}, Target: BranchInfo{Name: "master", Repository: repoName, Owner: owner}, URL: "https://gitlab.com/marcel.amirault/test-project/-/merge_requests/133", From 6002d6846251529094601668c97baa120137c1f9 Mon Sep 17 00:00:00 2001 From: Omer Zidkoni Date: Tue, 8 Aug 2023 13:32:51 +0300 Subject: [PATCH 4/8] Add pull request url to PullRequestInfo --- vcsclient/bitbucketserver_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vcsclient/bitbucketserver_test.go b/vcsclient/bitbucketserver_test.go index b5b4f169..16eacca3 100644 --- a/vcsclient/bitbucketserver_test.go +++ b/vcsclient/bitbucketserver_test.go @@ -256,8 +256,8 @@ func TestBitbucketServerClient_GetPullRequest(t *testing.T) { assert.NoError(t, err) assert.EqualValues(t, PullRequestInfo{ ID: int64(pullRequestId), - Source: BranchInfo{Name: "refs/heads/new_vul_2", Repository: "repoName", Owner: "~fromOwner"}, - Target: BranchInfo{Name: "refs/heads/master", Repository: "repoName", Owner: owner}, + Source: BranchInfo{Name: "new_vul_2", Repository: "repoName", Owner: "~fromOwner"}, + Target: BranchInfo{Name: "master", Repository: "repoName", Owner: owner}, URL: "https://git.bbServerHost.info/users/owner/repos/repoName/pull-requests/6", }, result) From a615f3a93d5af4f571366d8e33d368936b8c60c4 Mon Sep 17 00:00:00 2001 From: Omer Zidkoni Date: Fri, 11 Aug 2023 15:01:31 +0300 Subject: [PATCH 5/8] CR Changes & fix linter issues --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index e9b5c87b..ccd7c929 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,5 +1,5 @@ - [ ] All [tests](https://github.com/jfrog/froggit-go/actions/workflows/test.yml) passed. If this feature is not already covered by the tests, I added new tests. - [ ] I used `go fmt ./...` for formatting the code before submitting the pull request. -- [ ] This feature is included on all supported VCS providers - GitHub, Bitbucket cloud, Bitbucket server, and GitLab. +- [ ] This feature is included on all supported VCS providers - GitHub, Bitbucket cloud, Bitbucket server, GitLab and Azure Repos. --- From c266806016eb38c9066fb9c04bb60d2a999302dd Mon Sep 17 00:00:00 2001 From: Omer Zidkoni Date: Sun, 13 Aug 2023 14:02:57 +0300 Subject: [PATCH 6/8] fix pr --- vcsclient/github.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/vcsclient/github.go b/vcsclient/github.go index 18ec85c9..8af21ac6 100644 --- a/vcsclient/github.go +++ b/vcsclient/github.go @@ -352,15 +352,21 @@ func mapGitHubPullRequestToPullRequestInfo(ghPullRequest *github.PullRequest, wi } var sourceRepoName, sourceRepoOwner string - if ghPullRequest.Head.Repo != nil && ghPullRequest.Head.Repo.Owner != nil { - sourceRepoName = vcsutils.DefaultIfNotNil(ghPullRequest.Head.Repo.Name) - sourceRepoOwner = vcsutils.DefaultIfNotNil(ghPullRequest.Head.Repo.Owner.Login) + if ghPullRequest.Head.Repo == nil { + return PullRequestInfo{}, errors.New("the target repository information is missing when fetching the pull request details") } + if ghPullRequest.Head.Repo.Owner == nil { + return PullRequestInfo{}, errors.New("the target repository owner name is missing when fetching the pull request details") + } + sourceRepoName = vcsutils.DefaultIfNotNil(ghPullRequest.Head.Repo.Name) + sourceRepoOwner = vcsutils.DefaultIfNotNil(ghPullRequest.Head.Repo.Owner.Login) var targetRepoName, targetRepoOwner string - if ghPullRequest.Base.Repo != nil && ghPullRequest.Base.Repo.Owner != nil { - targetRepoName = vcsutils.DefaultIfNotNil(ghPullRequest.Base.Repo.Name) - targetRepoOwner = vcsutils.DefaultIfNotNil(ghPullRequest.Base.Repo.Owner.Login) + if ghPullRequest.Base.Repo == nil { + return PullRequestInfo{}, errors.New("the source repository information is missing when fetching the pull request details") + } + if ghPullRequest.Base.Repo.Owner == nil { + return PullRequestInfo{}, errors.New("the source repository owner name is missing when fetching the pull request details") } var body string From 451cdf5ade9e2922d54fbf4d8deb48e60d63b3b0 Mon Sep 17 00:00:00 2001 From: Omer Zidkoni Date: Sun, 13 Aug 2023 14:05:23 +0300 Subject: [PATCH 7/8] update go mod --- go.mod | 2 +- go.sum | 25 ++++--------------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index 0aa7bfa7..5cadae81 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,7 @@ require ( github.com/mitchellh/mapstructure v1.5.0 github.com/stretchr/testify v1.8.4 github.com/xanzy/go-gitlab v0.88.0 + golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 golang.org/x/oauth2 v0.10.0 ) @@ -40,7 +41,6 @@ require ( github.com/skeema/knownhosts v1.2.0 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect golang.org/x/crypto v0.11.0 // indirect - golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect golang.org/x/mod v0.9.0 // indirect golang.org/x/net v0.13.0 // indirect golang.org/x/sys v0.10.0 // indirect diff --git a/go.sum b/go.sum index 3934ec48..7e30e2eb 100644 --- a/go.sum +++ b/go.sum @@ -673,9 +673,6 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/envoyproxy/protoc-gen-validate v0.6.7/go.mod h1:dyJXwwfPK2VSqiB9Klm1J6romD608Ba7Hij42vrOBCo= github.com/envoyproxy/protoc-gen-validate v0.9.1/go.mod h1:OKNgG7TCp5pF4d6XftA0++PMirau2/yoOwVac3AbF2w= github.com/envoyproxy/protoc-gen-validate v0.10.0/go.mod h1:DRjgyB0I43LtJapqN6NiRwroiAU2PaFuvk/vjgh61ss= -github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= -github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/gfleury/go-bitbucket-v1 v0.0.0-20230626192437-8d7be5866751 h1:Ea58sAu8LX/NS7z3aeL+YX/7+FSd9jsxq6Ecpz7QEDM= @@ -820,9 +817,8 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0/go.mod h1:hgWBS7lorOAVIJEQMi4Zs github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3/go.mod h1:o//XUCC/F+yRGJoPO/VU0GSB0f8Nhgmxx0VIRUvaC0w= github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= +github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI= github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= -github.com/hashicorp/go-hclog v1.2.0 h1:La19f8d7WIlm4ogzNHB0JGqs5AUDAZ2UfCY4sJXcJdM= -github.com/hashicorp/go-hclog v1.2.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-retryablehttp v0.7.2 h1:AcYqCvkpalPnPF2pn0KamgwamS42TqUDDYFRKq/RAd0= github.com/hashicorp/go-retryablehttp v0.7.2/go.mod h1:Jy/gPYAdjqffZ/yFGCFV2doI5wjtH1ewM9u8iYVjtX8= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= @@ -864,15 +860,7 @@ github.com/lyft/protoc-gen-star/v2 v2.0.1/go.mod h1:RcCdONR2ScXaYnQC5tUzxzlpA3WV github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A= github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= -github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-sqlite3 v1.14.14/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/microsoft/azure-devops-go-api/azuredevops v1.0.0-b5 h1:YH424zrwLTlyHSH/GzLMJeu5zhYVZSx5RQxGKm1h96s= @@ -986,8 +974,8 @@ golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/exp v0.0.0-20220827204233-334a2380cb91/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= -golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691 h1:/yRP+0AN7mf5DkD3BAI6TOFnd51gEoDEb8o35jIFtgw= -golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= +golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc= +golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= @@ -1029,9 +1017,8 @@ golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs= golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= -golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1092,7 +1079,6 @@ golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/net v0.13.0 h1:Nvo8UFsZ8X3BhAC9699Z1j7XQ3rsZnUUm7jfBEk1ueY= golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= @@ -1148,7 +1134,6 @@ golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1157,7 +1142,6 @@ golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1201,7 +1185,6 @@ golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= From 2b3f2d4418cbd0edaf66ecd945349d6414011de7 Mon Sep 17 00:00:00 2001 From: Omer Zidkoni Date: Sun, 13 Aug 2023 14:14:35 +0300 Subject: [PATCH 8/8] fix test --- vcsclient/github.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/vcsclient/github.go b/vcsclient/github.go index 8af21ac6..bca63265 100644 --- a/vcsclient/github.go +++ b/vcsclient/github.go @@ -353,21 +353,23 @@ func mapGitHubPullRequestToPullRequestInfo(ghPullRequest *github.PullRequest, wi var sourceRepoName, sourceRepoOwner string if ghPullRequest.Head.Repo == nil { - return PullRequestInfo{}, errors.New("the target repository information is missing when fetching the pull request details") + return PullRequestInfo{}, errors.New("the source repository information is missing when fetching the pull request details") } if ghPullRequest.Head.Repo.Owner == nil { - return PullRequestInfo{}, errors.New("the target repository owner name is missing when fetching the pull request details") + return PullRequestInfo{}, errors.New("the source repository owner name is missing when fetching the pull request details") } sourceRepoName = vcsutils.DefaultIfNotNil(ghPullRequest.Head.Repo.Name) sourceRepoOwner = vcsutils.DefaultIfNotNil(ghPullRequest.Head.Repo.Owner.Login) var targetRepoName, targetRepoOwner string if ghPullRequest.Base.Repo == nil { - return PullRequestInfo{}, errors.New("the source repository information is missing when fetching the pull request details") + return PullRequestInfo{}, errors.New("the target repository information is missing when fetching the pull request details") } if ghPullRequest.Base.Repo.Owner == nil { - return PullRequestInfo{}, errors.New("the source repository owner name is missing when fetching the pull request details") + return PullRequestInfo{}, errors.New("the target repository owner name is missing when fetching the pull request details") } + targetRepoName = vcsutils.DefaultIfNotNil(ghPullRequest.Base.Repo.Name) + targetRepoOwner = vcsutils.DefaultIfNotNil(ghPullRequest.Base.Repo.Owner.Login) var body string if withBody {