From 34d64cb00348338c727d0b10e57fc6e9092d916f Mon Sep 17 00:00:00 2001 From: raghavharness Date: Thu, 2 Jun 2022 18:26:45 +0530 Subject: [PATCH 1/5] Using target commit instead of source in base info --- scm/driver/azure/pr.go | 2 +- scm/driver/azure/testdata/pr.json.golden | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scm/driver/azure/pr.go b/scm/driver/azure/pr.go index 2d9282892..7281de36d 100644 --- a/scm/driver/azure/pr.go +++ b/scm/driver/azure/pr.go @@ -171,7 +171,7 @@ func convertPullRequest(from *pr) *scm.PullRequest { }, Base: scm.Reference{ - Sha: from.LastMergeSourceCommit.CommitID, + Sha: from.LastMergeTargetCommit.CommitID, }, Author: scm.User{ Login: from.CreatedBy.UniqueName, diff --git a/scm/driver/azure/testdata/pr.json.golden b/scm/driver/azure/testdata/pr.json.golden index 291b6f063..5dfdf4231 100644 --- a/scm/driver/azure/testdata/pr.json.golden +++ b/scm/driver/azure/testdata/pr.json.golden @@ -14,7 +14,7 @@ "Base": { "Name": "", "Path": "", - "Sha": "01768d964c03e97260af0bd8cd9e5cd1f9ac6356" + "Sha": "b748ab7eb49b8627214f22f631f878c4af9893b5" }, "Head": { "Name": "", From a150b40a00bd7a9399daa35af64e1ba33d159ccc Mon Sep 17 00:00:00 2001 From: raghavharness Date: Fri, 3 Jun 2022 12:19:44 +0530 Subject: [PATCH 2/5] added pr status information for azure --- scm/driver/azure/pr.go | 18 +++++++++++------- scm/driver/azure/testdata/pr.json | 3 ++- scm/driver/azure/testdata/pr.json.golden | 4 ++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/scm/driver/azure/pr.go b/scm/driver/azure/pr.go index 7281de36d..e7008f3cc 100644 --- a/scm/driver/azure/pr.go +++ b/scm/driver/azure/pr.go @@ -10,6 +10,7 @@ import ( "time" "github.com/drone/go-scm/scm" + "github.com/drone/go-scm/scm/driver/internal/null" ) type pullService struct { @@ -99,13 +100,14 @@ type pr struct { URL string `json:"url"` ImageURL string `json:"imageUrl"` } `json:"createdBy"` - CreationDate time.Time `json:"creationDate"` - Title string `json:"title"` - Description string `json:"description"` - SourceRefName string `json:"sourceRefName"` - TargetRefName string `json:"targetRefName"` - MergeStatus string `json:"mergeStatus"` - MergeID string `json:"mergeId"` + CreationDate time.Time `json:"creationDate"` + ClosedDate null.String `json:"closedDate"` + Title string `json:"title"` + Description string `json:"description"` + SourceRefName string `json:"sourceRefName"` + TargetRefName string `json:"targetRefName"` + MergeStatus string `json:"mergeStatus"` + MergeID string `json:"mergeId"` LastMergeSourceCommit struct { CommitID string `json:"commitId"` URL string `json:"url"` @@ -166,6 +168,8 @@ func convertPullRequest(from *pr) *scm.PullRequest { Source: from.SourceRefName, Target: from.TargetRefName, Link: from.URL, + Closed: from.ClosedDate.Valid, + Merged: from.Status == "completed", Head: scm.Reference{ Sha: from.LastMergeSourceCommit.CommitID, }, diff --git a/scm/driver/azure/testdata/pr.json b/scm/driver/azure/testdata/pr.json index b721e0dae..e419af010 100644 --- a/scm/driver/azure/testdata/pr.json +++ b/scm/driver/azure/testdata/pr.json @@ -15,7 +15,7 @@ }, "pullRequestId": 19, "codeReviewId": 19, - "status": "active", + "status": "completed", "createdBy": { "id": "3ff4a20f-306e-677e-8a01-57f35e71f109", "displayName": "tp", @@ -24,6 +24,7 @@ "imageUrl": "https://dev.azure.com/tphoney/_api/_common/identityImage?id=3ff4a20f-306e-677e-8a01-57f35e71f109" }, "creationDate": "2022-03-04T13:34:54.3177724Z", + "closedDate": "2022-06-03T06:33:42.2405472Z", "title": "test_pr", "description": "test_pr_body", "sourceRefName": "refs/heads/pr_branch", diff --git a/scm/driver/azure/testdata/pr.json.golden b/scm/driver/azure/testdata/pr.json.golden index 5dfdf4231..e466c3f64 100644 --- a/scm/driver/azure/testdata/pr.json.golden +++ b/scm/driver/azure/testdata/pr.json.golden @@ -9,8 +9,8 @@ "Fork": "", "Link": "https://dev.azure.com/tphoney/d350c9c0-7749-4ff8-a78f-f9c1f0e56729/_apis/git/repositories/fde2d21f-13b9-4864-a995-83329045289a/pullRequests/19", "Diff": "", - "Closed": false, - "Merged": false, + "Closed": true, + "Merged": true, "Base": { "Name": "", "Path": "", From d710695323590320d2681ccc1c4e44d8abae55a3 Mon Sep 17 00:00:00 2001 From: raghavharness Date: Fri, 3 Jun 2022 12:25:32 +0530 Subject: [PATCH 3/5] trim branch ref for azure --- scm/driver/azure/pr.go | 4 ++-- scm/driver/azure/testdata/pr.json.golden | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scm/driver/azure/pr.go b/scm/driver/azure/pr.go index e7008f3cc..7a057492b 100644 --- a/scm/driver/azure/pr.go +++ b/scm/driver/azure/pr.go @@ -165,8 +165,8 @@ func convertPullRequest(from *pr) *scm.PullRequest { Title: from.Title, Body: from.Description, Sha: from.LastMergeSourceCommit.CommitID, - Source: from.SourceRefName, - Target: from.TargetRefName, + Source: scm.TrimRef(from.SourceRefName), + Target: scm.TrimRef(from.TargetRefName), Link: from.URL, Closed: from.ClosedDate.Valid, Merged: from.Status == "completed", diff --git a/scm/driver/azure/testdata/pr.json.golden b/scm/driver/azure/testdata/pr.json.golden index e466c3f64..03ebfc377 100644 --- a/scm/driver/azure/testdata/pr.json.golden +++ b/scm/driver/azure/testdata/pr.json.golden @@ -4,8 +4,8 @@ "Body": "test_pr_body", "Sha": "01768d964c03e97260af0bd8cd9e5cd1f9ac6356", "Ref": "", - "Source": "refs/heads/pr_branch", - "Target": "refs/heads/main", + "Source": "pr_branch", + "Target": "main", "Fork": "", "Link": "https://dev.azure.com/tphoney/d350c9c0-7749-4ff8-a78f-f9c1f0e56729/_apis/git/repositories/fde2d21f-13b9-4864-a995-83329045289a/pullRequests/19", "Diff": "", From bd8cf35e9554455cbd32df8164e35baed3db8e8d Mon Sep 17 00:00:00 2001 From: raghavharness Date: Fri, 3 Jun 2022 12:44:16 +0530 Subject: [PATCH 4/5] Added pr ref details for azure --- scm/driver/azure/git.go | 2 ++ scm/driver/azure/pr.go | 1 + scm/driver/azure/testdata/commits.json.golden | 12 ++++++------ scm/driver/azure/testdata/pr.json.golden | 1 + 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/scm/driver/azure/git.go b/scm/driver/azure/git.go index e61ec6236..435023ab9 100644 --- a/scm/driver/azure/git.go +++ b/scm/driver/azure/git.go @@ -221,11 +221,13 @@ func convertCommit(from *gitCommit) *scm.Commit { Sha: from.CommitID, Link: from.URL, Author: scm.Signature{ + Login: from.Author.Name, Name: from.Author.Name, Email: from.Author.Email, Date: from.Author.Date, }, Committer: scm.Signature{ + Login: from.Committer.Name, Name: from.Committer.Name, Email: from.Committer.Email, Date: from.Committer.Date, diff --git a/scm/driver/azure/pr.go b/scm/driver/azure/pr.go index 7a057492b..a5bb93479 100644 --- a/scm/driver/azure/pr.go +++ b/scm/driver/azure/pr.go @@ -170,6 +170,7 @@ func convertPullRequest(from *pr) *scm.PullRequest { Link: from.URL, Closed: from.ClosedDate.Valid, Merged: from.Status == "completed", + Ref: fmt.Sprintf("refs/pull/%d/merge", from.PullRequestID), Head: scm.Reference{ Sha: from.LastMergeSourceCommit.CommitID, }, diff --git a/scm/driver/azure/testdata/commits.json.golden b/scm/driver/azure/testdata/commits.json.golden index 7f2eb4a47..a42699cf2 100644 --- a/scm/driver/azure/testdata/commits.json.golden +++ b/scm/driver/azure/testdata/commits.json.golden @@ -6,14 +6,14 @@ "Name": "tp", "Email": "tp@harness.io", "Date": "2022-03-04T12:19:58Z", - "Login": "", + "Login": "tp", "Avatar": "" }, "Committer": { "Name": "tp", "Email": "tp@harness.io", "Date": "2022-03-04T12:19:58Z", - "Login": "", + "Login": "tp", "Avatar": "" }, "Link": "https://dev.azure.com/tphoney/d350c9c0-7749-4ff8-a78f-f9c1f0e56729/_apis/git/repositories/fde2d21f-13b9-4864-a995-83329045289a/commits/e0aee6aa543294d62520fb906689da6710af149c" @@ -25,14 +25,14 @@ "Name": "tp", "Email": "tp@harness.io", "Date": "2022-03-04T12:19:57Z", - "Login": "", + "Login": "tp", "Avatar": "" }, "Committer": { "Name": "tp", "Email": "tp@harness.io", "Date": "2022-03-04T12:19:57Z", - "Login": "", + "Login": "tp", "Avatar": "" }, "Link": "https://dev.azure.com/tphoney/d350c9c0-7749-4ff8-a78f-f9c1f0e56729/_apis/git/repositories/fde2d21f-13b9-4864-a995-83329045289a/commits/1fe456794debece7c4125b9e283b601c974977a9" @@ -44,14 +44,14 @@ "Name": "tp", "Email": "tp@harness.io", "Date": "2022-03-04T12:19:56Z", - "Login": "", + "Login": "tp", "Avatar": "" }, "Committer": { "Name": "tp", "Email": "tp@harness.io", "Date": "2022-03-04T12:19:56Z", - "Login": "", + "Login": "tp", "Avatar": "" }, "Link": "https://dev.azure.com/tphoney/d350c9c0-7749-4ff8-a78f-f9c1f0e56729/_apis/git/repositories/fde2d21f-13b9-4864-a995-83329045289a/commits/dc49e8e6e22bb3456366a09365ce9e72912f26b5" diff --git a/scm/driver/azure/testdata/pr.json.golden b/scm/driver/azure/testdata/pr.json.golden index 03ebfc377..5e59c583b 100644 --- a/scm/driver/azure/testdata/pr.json.golden +++ b/scm/driver/azure/testdata/pr.json.golden @@ -6,6 +6,7 @@ "Ref": "", "Source": "pr_branch", "Target": "main", + "Ref": "refs/pull/19/merge", "Fork": "", "Link": "https://dev.azure.com/tphoney/d350c9c0-7749-4ff8-a78f-f9c1f0e56729/_apis/git/repositories/fde2d21f-13b9-4864-a995-83329045289a/pullRequests/19", "Diff": "", From 1c70b4e75f8094b131a5f66e6bfac3f612e89b29 Mon Sep 17 00:00:00 2001 From: raghavharness Date: Fri, 3 Jun 2022 13:05:53 +0530 Subject: [PATCH 5/5] test fix --- scm/driver/azure/testdata/commit.json.golden | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scm/driver/azure/testdata/commit.json.golden b/scm/driver/azure/testdata/commit.json.golden index 36b73b3cf..1659822a9 100644 --- a/scm/driver/azure/testdata/commit.json.golden +++ b/scm/driver/azure/testdata/commit.json.golden @@ -5,14 +5,14 @@ "Name": "tp", "Email": "tp@harness.io", "Date": "2022-03-15T17:08:22Z", - "Login": "", + "Login": "tp", "Avatar": "" }, "Committer": { "Name": "tp", "Email": "tp@harness.io", "Date": "2022-03-15T17:08:22Z", - "Login": "", + "Login": "tp", "Avatar": "" }, "Link": "https://dev.azure.com/tphoney/d350c9c0-7749-4ff8-a78f-f9c1f0e56729/_apis/git/repositories/fde2d21f-13b9-4864-a995-83329045289a/commits/14897f4465d2d63508242b5cbf68aa2865f693e7"