-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: assess commits on PR for
Author
and Verification
Signed-off-by: Paul Horton <[email protected]>
- Loading branch information
Showing
2 changed files
with
121 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -289,10 +289,12 @@ func TestHandlePullRequestIsCollaboratorError(t *testing.T) { | |
GHImpl = origGithubImpl | ||
}() | ||
mockAuthorLogin := "myAuthorLogin" | ||
mockRepositoryCommits := []*github.RepositoryCommit{{Author: &github.User{Login: &mockAuthorLogin}}} | ||
mockRepositoryCommits := getMockRepositoryCommitsSigned(mockAuthorLogin) | ||
forcedError := fmt.Errorf("forced IsCollaborator error") | ||
GHImpl = &GHInterfaceMock{ | ||
PullRequestsMock: PullRequestsMock{mockRepositoryCommits: mockRepositoryCommits}, | ||
PullRequestsMock: PullRequestsMock{ | ||
mockRepositoryCommits: mockRepositoryCommits, | ||
}, | ||
RepositoriesMock: RepositoriesMock{ | ||
isCollaboratorErr: forcedError, | ||
}, | ||
|
@@ -325,9 +327,11 @@ func TestHandlePullRequestIsCollaboratorTrueCollaborator(t *testing.T) { | |
GHImpl = origGithubImpl | ||
}() | ||
mockAuthorLogin := "myAuthorLogin" | ||
mockRepositoryCommits := []*github.RepositoryCommit{{Author: &github.User{Login: &mockAuthorLogin}}} | ||
mockRepositoryCommits := getMockRepositoryCommitsSigned(mockAuthorLogin) | ||
GHImpl = &GHInterfaceMock{ | ||
PullRequestsMock: PullRequestsMock{mockRepositoryCommits: mockRepositoryCommits}, | ||
PullRequestsMock: PullRequestsMock{ | ||
mockRepositoryCommits: mockRepositoryCommits, | ||
}, | ||
RepositoriesMock: RepositoriesMock{ | ||
isCollaboratorResult: true, | ||
}, | ||
|
@@ -370,7 +374,7 @@ func TestHandlePullRequestCreateLabelError(t *testing.T) { | |
GHImpl = origGithubImpl | ||
}() | ||
mockAuthorLogin := "myAuthorLogin" | ||
mockRepositoryCommits := []*github.RepositoryCommit{{Author: &github.User{Login: &mockAuthorLogin}}} | ||
mockRepositoryCommits := getMockRepositoryCommitsSigned(mockAuthorLogin) | ||
forcedError := fmt.Errorf("forced CreateLabel error") | ||
GHImpl = &GHInterfaceMock{ | ||
PullRequestsMock: PullRequestsMock{mockRepositoryCommits: mockRepositoryCommits}, | ||
|
@@ -407,7 +411,7 @@ func TestHandlePullRequestAddLabelsToIssueError(t *testing.T) { | |
GHImpl = origGithubImpl | ||
}() | ||
mockAuthorLogin := "myAuthorLogin" | ||
mockRepositoryCommits := []*github.RepositoryCommit{{Author: &github.User{Login: &mockAuthorLogin}}} | ||
mockRepositoryCommits := getMockRepositoryCommitsSigned(mockAuthorLogin) | ||
forcedError := fmt.Errorf("forced AddLabelsToIssue error") | ||
GHImpl = &GHInterfaceMock{ | ||
PullRequestsMock: PullRequestsMock{mockRepositoryCommits: mockRepositoryCommits}, | ||
|
@@ -457,7 +461,7 @@ func TestHandlePullRequestGetAppError(t *testing.T) { | |
GHImpl = origGithubImpl | ||
}() | ||
mockAuthorLogin := "myAuthorLogin" | ||
mockRepositoryCommits := []*github.RepositoryCommit{{Author: &github.User{Login: &mockAuthorLogin}}} | ||
mockRepositoryCommits := getMockRepositoryCommitsSigned(mockAuthorLogin) | ||
GHImpl = &GHInterfaceMock{ | ||
PullRequestsMock: PullRequestsMock{mockRepositoryCommits: mockRepositoryCommits}, | ||
IssuesMock: IssuesMock{ | ||
|
@@ -578,13 +582,23 @@ func TestHandlePullRequestListCommits(t *testing.T) { | |
Login: github.String(login), | ||
Email: github.String("[email protected]"), | ||
}, | ||
Commit: &github.Commit{ | ||
Verification: &github.SignatureVerification{ | ||
Verified: github.Bool(true), | ||
}, | ||
}, | ||
SHA: github.String("johnSHA"), | ||
}, | ||
{ | ||
Author: &github.User{ | ||
Login: github.String(login2), | ||
Email: github.String("[email protected]"), | ||
}, | ||
Commit: &github.Commit{ | ||
Verification: &github.SignatureVerification{ | ||
Verified: github.Bool(true), | ||
}, | ||
}, | ||
SHA: github.String("doeSHA"), | ||
}, | ||
} | ||
|
@@ -646,7 +660,8 @@ func TestHandlePullRequestListCommitsNoAuthor(t *testing.T) { | |
// Date: github.Timestamp.Local(), | ||
}, | ||
}, | ||
SHA: github.String("johnSHA"), | ||
SHA: github.String("johnSHA"), | ||
HTMLURL: github.String("https://github.com"), | ||
}, | ||
} | ||
GHImpl = &GHInterfaceMock{ | ||
|
@@ -712,7 +727,8 @@ func TestHandlePullRequestListCommitsUnsignedCommit(t *testing.T) { | |
Payload: nil, | ||
}, | ||
}, | ||
SHA: github.String("johnSHA"), | ||
SHA: github.String("johnSHA"), | ||
HTMLURL: github.String("https://github.com"), | ||
}, | ||
} | ||
GHImpl = &GHInterfaceMock{ | ||
|
@@ -905,3 +921,19 @@ func TestReviewPriorPRs(t *testing.T) { | |
|
||
assert.NoError(t, ReviewPriorPRs(logger, mockDB, &user)) | ||
} | ||
|
||
func getMockRepositoryCommitsSigned(mockAuthorLogin string) []*github.RepositoryCommit { | ||
mockRepositoryCommits := []*github.RepositoryCommit{ | ||
{ | ||
Author: &github.User{ | ||
Login: &mockAuthorLogin, | ||
}, | ||
Commit: &github.Commit{ | ||
Verification: &github.SignatureVerification{ | ||
Verified: github.Bool(true), | ||
}, | ||
}, | ||
}, | ||
} | ||
return mockRepositoryCommits | ||
} |