Skip to content

Commit ab2f6e9

Browse files
authored
🐛 add nil-pointer check in issueActivityByProjectMember (#4642)
AuthorAssociation can technically be nil so add two checks Signed-off-by: Adam Korczynski <[email protected]>
1 parent c51abde commit ab2f6e9

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

probes/issueActivityByProjectMember/impl.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,18 @@ func hasActivityByCollaboratorOrHigher(issue *clients.Issue, threshold time.Time
9090
return false
9191
}
9292

93-
if issue.AuthorAssociation.Gte(clients.RepoAssociationCollaborator) &&
93+
hasAuthorAssociation := issue.AuthorAssociation != nil
94+
95+
if hasAuthorAssociation &&
96+
issue.AuthorAssociation.Gte(clients.RepoAssociationCollaborator) &&
9497
issue.CreatedAt != nil && issue.CreatedAt.After(threshold) {
9598
// The creator of the issue is a collaborator or higher.
9699
return true
97100
}
98101
for _, comment := range issue.Comments {
102+
if comment.AuthorAssociation == nil {
103+
continue
104+
}
99105
if comment.AuthorAssociation.Gte(clients.RepoAssociationCollaborator) &&
100106
comment.CreatedAt != nil &&
101107
comment.CreatedAt.After(threshold) {

probes/issueActivityByProjectMember/impl_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,22 @@ func Test_hasActivityByCollaboratorOrHigher(t *testing.T) {
225225
},
226226
want: true,
227227
},
228+
{
229+
name: "issue with nil AuthorAssociation",
230+
args: args{
231+
issue: &clients.Issue{
232+
CreatedAt: &twentyDaysAgo,
233+
AuthorAssociation: nil,
234+
Comments: []clients.IssueComment{
235+
{
236+
CreatedAt: &twentyDaysAgo,
237+
AuthorAssociation: nil,
238+
},
239+
},
240+
},
241+
},
242+
want: false,
243+
},
228244
}
229245
for _, tt := range tests {
230246
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)