Skip to content

Commit dc22d50

Browse files
committed
PR comments
Signed-off-by: Jamie Magee <jamie.magee@gmail.com>
1 parent 5e3f27c commit dc22d50

File tree

4 files changed

+47
-23
lines changed

4 files changed

+47
-23
lines changed

clients/azuredevopsrepo/audit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ func (a *auditHandler) setup() error {
6464
*entry.ProjectName == a.repourl.project &&
6565
(*entry.Data)["RepoName"] == a.repourl.name {
6666
a.createdAt = entry.Timestamp.Time
67-
break
67+
return
6868
}
6969
}
7070

7171
if *auditLog.HasMore {
7272
continuationToken = *auditLog.ContinuationToken
7373
} else {
74-
break
74+
return
7575
}
7676
}
7777
})

clients/azuredevopsrepo/commits.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,12 @@ func (handler *commitsHandler) setup() error {
111111
return
112112
}
113113

114-
// If there are fewer commits than requested, the first commit is the createdAt date
115-
if len(*commits) < handler.commitDepth {
114+
switch {
115+
case len(*commits) == 0:
116+
handler.firstCommitCreatedAt = time.Time{}
117+
case len(*commits) < handler.commitDepth:
116118
handler.firstCommitCreatedAt = (*commits)[len(*commits)-1].Committer.Date.Time
117-
} else {
119+
default:
118120
firstCommit, err := handler.getFirstCommit(handler.ctx, git.GetCommitsArgs{
119121
RepositoryId: &handler.repourl.id,
120122
SearchCriteria: &git.GitQueryCommitsCriteria{

clients/azuredevopsrepo/work_items.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ import (
2626
)
2727

2828
var (
29-
errSystemCreatedByFieldNotMap = fmt.Errorf("error: System.CreatedBy field is not a map")
30-
errSystemCreatedDateFieldNotString = fmt.Errorf("error: System.CreatedDate field is not a string")
29+
errSystemCreatedByFieldNotMap = fmt.Errorf("error: System.CreatedBy field is not a map")
30+
errSystemCreatedByFieldNotUniqueName = fmt.Errorf("error: System.CreatedBy field does not contain a UniqueName")
31+
errSystemCreatedDateFieldNotString = fmt.Errorf("error: System.CreatedDate field is not a string")
3132
)
3233

3334
type (
@@ -71,7 +72,6 @@ func (w *workItemsHandler) init(ctx context.Context, repourl *Repo) {
7172

7273
func (w *workItemsHandler) setup() error {
7374
w.once.Do(func() {
74-
// Fetch URI, CreatedAt, Author, and Issue comments
7575
wiql := `
7676
SELECT [System.Id]
7777
FROM WorkItems
@@ -112,6 +112,11 @@ func (w *workItemsHandler) setup() error {
112112
w.errSetup = errSystemCreatedByFieldNotMap
113113
return
114114
}
115+
uniqueName, ok := createdBy["uniqueName"].(string)
116+
if !ok {
117+
w.errSetup = errSystemCreatedByFieldNotUniqueName
118+
return
119+
}
115120
createdDate, ok := (*wi.Fields)["System.CreatedDate"].(string)
116121
if !ok {
117122
w.errSetup = errSystemCreatedDateFieldNotString
@@ -129,7 +134,7 @@ func (w *workItemsHandler) setup() error {
129134
issue := clients.Issue{
130135
URI: wi.Url,
131136
CreatedAt: &parsedTime,
132-
Author: &clients.User{Login: createdBy["uniqueName"].(string)},
137+
Author: &clients.User{Login: uniqueName},
133138
AuthorAssociation: &repoAssociation,
134139
Comments: make([]clients.IssueComment, 0),
135140
}
@@ -152,7 +157,7 @@ func (w *workItemsHandler) setup() error {
152157

153158
comment := clients.IssueComment{
154159
CreatedAt: &workItemComment.CreatedDate.Time,
155-
Author: &clients.User{Login: *workItemComment.CreatedBy.DisplayName},
160+
Author: &clients.User{Login: *workItemComment.CreatedBy.UniqueName},
156161
AuthorAssociation: &repoAssociation,
157162
}
158163

clients/azuredevopsrepo/work_items_test.go

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"time"
2424

2525
"github.com/microsoft/azure-devops-go-api/azuredevops/v7"
26+
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/webapi"
2627
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/workitemtracking"
2728

2829
"github.com/ossf/scorecard/v5/clients"
@@ -31,10 +32,10 @@ import (
3132
func TestWorkItemsHandler_listIssues(t *testing.T) {
3233
t.Parallel()
3334
tests := []struct {
34-
mockSetup func(*workItemsHandler)
35-
want []clients.Issue
36-
wantErrStr string
3735
name string
36+
wantErrStr string
37+
mockSetup func(*workItemsHandler)
38+
want []clients.Issue
3839
}{
3940
{
4041
name: "happy path",
@@ -51,9 +52,14 @@ func TestWorkItemsHandler_listIssues(t *testing.T) {
5152
createdDate := "2024-01-01T00:00:00Z"
5253
workItemDetails := &[]workitemtracking.WorkItem{
5354
{
54-
Id: toPtr(1),
55-
Url: toPtr("http://example.com"),
56-
Fields: &map[string]interface{}{"System.CreatedDate": createdDate},
55+
Id: toPtr(1),
56+
Url: toPtr("http://example.com"),
57+
Fields: &map[string]interface{}{
58+
"System.CreatedDate": createdDate,
59+
"System.CreatedBy": map[string]interface{}{
60+
"uniqueName": "test-user",
61+
},
62+
},
5763
},
5864
}
5965
w.getWorkItems = func(ctx context.Context, args workitemtracking.GetWorkItemsArgs) (*[]workitemtracking.WorkItem, error) {
@@ -63,7 +69,7 @@ func TestWorkItemsHandler_listIssues(t *testing.T) {
6369
commentTime := time.Date(2024, 1, 2, 0, 0, 0, 0, time.UTC)
6470
comments := &workitemtracking.CommentList{
6571
Comments: &[]workitemtracking.Comment{
66-
{CreatedDate: &azuredevops.Time{Time: commentTime}},
72+
{CreatedDate: &azuredevops.Time{Time: commentTime}, CreatedBy: &webapi.IdentityRef{UniqueName: toPtr("test-user")}},
6773
},
6874
}
6975
w.getWorkItemComments = func(ctx context.Context, args workitemtracking.GetCommentsArgs) (*workitemtracking.CommentList, error) {
@@ -72,10 +78,16 @@ func TestWorkItemsHandler_listIssues(t *testing.T) {
7278
},
7379
want: []clients.Issue{
7480
{
75-
URI: toPtr("http://example.com"),
76-
CreatedAt: toPtr(time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)),
81+
URI: toPtr("http://example.com"),
82+
CreatedAt: toPtr(time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)),
83+
Author: &clients.User{Login: "test-user"},
84+
AuthorAssociation: toPtr(clients.RepoAssociationMember),
7785
Comments: []clients.IssueComment{
78-
{CreatedAt: toPtr(time.Date(2024, 1, 2, 0, 0, 0, 0, time.UTC))},
86+
{
87+
CreatedAt: toPtr(time.Date(2024, 1, 2, 0, 0, 0, 0, time.UTC)),
88+
Author: &clients.User{Login: "test-user"},
89+
AuthorAssociation: toPtr(clients.RepoAssociationMember),
90+
},
7991
},
8092
},
8193
},
@@ -120,9 +132,14 @@ func TestWorkItemsHandler_listIssues(t *testing.T) {
120132
createdDate := "2024-01-01T00:00:00Z"
121133
workItemDetails := &[]workitemtracking.WorkItem{
122134
{
123-
Id: toPtr(1),
124-
Url: toPtr("http://example.com"),
125-
Fields: &map[string]interface{}{"System.CreatedDate": createdDate},
135+
Id: toPtr(1),
136+
Url: toPtr("http://example.com"),
137+
Fields: &map[string]interface{}{
138+
"System.CreatedDate": createdDate,
139+
"System.CreatedBy": map[string]interface{}{
140+
"uniqueName": "test-user",
141+
},
142+
},
126143
},
127144
}
128145
w.getWorkItems = func(ctx context.Context, args workitemtracking.GetWorkItemsArgs) (*[]workitemtracking.WorkItem, error) {

0 commit comments

Comments
 (0)