Skip to content

Commit

Permalink
Using target commit instead of source in base info for azure (#189)
Browse files Browse the repository at this point in the history
* Using target commit instead of source in base info

* added pr status information for azure
  • Loading branch information
raghavharness authored Jun 6, 2022
1 parent 4c30731 commit 63b6fb0
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 24 deletions.
2 changes: 2 additions & 0 deletions scm/driver/azure/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 15 additions & 10 deletions scm/driver/azure/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/drone/go-scm/scm"
"github.com/drone/go-scm/scm/driver/internal/null"
)

type pullService struct {
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -163,15 +165,18 @@ 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",
Ref: fmt.Sprintf("refs/pull/%d/merge", from.PullRequestID),
Head: scm.Reference{
Sha: from.LastMergeSourceCommit.CommitID,
},
Base: scm.Reference{

Sha: from.LastMergeSourceCommit.CommitID,
Sha: from.LastMergeTargetCommit.CommitID,
},
Author: scm.User{
Login: from.CreatedBy.UniqueName,
Expand Down
4 changes: 2 additions & 2 deletions scm/driver/azure/testdata/commit.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions scm/driver/azure/testdata/commits.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion scm/driver/azure/testdata/pr.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"pullRequestId": 19,
"codeReviewId": 19,
"status": "active",
"status": "completed",
"createdBy": {
"id": "3ff4a20f-306e-677e-8a01-57f35e71f109",
"displayName": "tp",
Expand All @@ -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",
Expand Down
11 changes: 6 additions & 5 deletions scm/driver/azure/testdata/pr.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
"Body": "test_pr_body",
"Sha": "01768d964c03e97260af0bd8cd9e5cd1f9ac6356",
"Ref": "",
"Source": "refs/heads/pr_branch",
"Target": "refs/heads/main",
"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": "",
"Closed": false,
"Merged": false,
"Closed": true,
"Merged": true,
"Base": {
"Name": "",
"Path": "",
"Sha": "01768d964c03e97260af0bd8cd9e5cd1f9ac6356"
"Sha": "b748ab7eb49b8627214f22f631f878c4af9893b5"
},
"Head": {
"Name": "",
Expand Down

0 comments on commit 63b6fb0

Please sign in to comment.