Skip to content

Commit

Permalink
fix typecheck golangci assertions
Browse files Browse the repository at this point in the history
Closes #404

Signed-off-by: Chmouel Boudjnah <[email protected]>
  • Loading branch information
chmouel committed Jan 27, 2022
1 parent e982869 commit 1f6e6fd
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
7 changes: 6 additions & 1 deletion pkg/matcher/annotation_tasks_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ func (rt RemoteTasks) convertTotask(data string) (*tektonv1beta1.Task, error) {
return nil, fmt.Errorf("we have a task that is not looking like a kubernetes resource: task: %s resource: %w", data, err)
}

return obj.(*tektonv1beta1.Task), nil
task, ok := obj.(*tektonv1beta1.Task)
if !ok {
return nil, fmt.Errorf("this doesn't seem to be a proper task")
}

return task, nil
}

func (rt RemoteTasks) getTask(ctx context.Context, providerintf provider.Interface, task string) (*tektonv1beta1.Task, error) {
Expand Down
8 changes: 6 additions & 2 deletions pkg/provider/bitbucketcloud/test/bbcloudtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ func SetupBBCloudClient(t *testing.T) (*bitbucket.Client, *http.ServeMux, func()
func MuxComments(t *testing.T, mux *http.ServeMux, event *info.Event, comments []types.Comment) {
assert.Assert(t, event.Event != nil)

prID := fmt.Sprintf("%d", event.Event.(*types.PullRequestEvent).PullRequest.ID)
pr, ok := event.Event.(*types.PullRequestEvent)
assert.Assert(t, ok)
prID := fmt.Sprintf("%d", pr.PullRequest.ID)
mux.HandleFunc("/repositories/"+event.Organization+"/"+event.Repository+"/pullrequests/"+prID+"/comments/",
func(rw http.ResponseWriter, r *http.Request) {
members := &types.Comments{
Expand Down Expand Up @@ -146,7 +148,9 @@ func MuxCreateCommitstatus(t *testing.T, mux *http.ServeMux, event *info.Event,
func MuxCreateComment(t *testing.T, mux *http.ServeMux, event *info.Event,
expectedCommentSubstr string) {
assert.Assert(t, event.Event != nil)
prID := fmt.Sprintf("%d", event.Event.(*types.PullRequestEvent).PullRequest.ID)
prev, ok := event.Event.(*types.PullRequestEvent)
assert.Assert(t, ok)
prID := fmt.Sprintf("%d", prev.PullRequest.ID)

path := fmt.Sprintf("/repositories/%s/%s/pullrequests/%s/comments", event.Organization, event.Repository, prID)
mux.HandleFunc(path, func(rw http.ResponseWriter, r *http.Request) {
Expand Down
6 changes: 5 additions & 1 deletion pkg/provider/bitbucketserver/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ func (v *Provider) checkOkToTestCommentFromApprovedMember(event *info.Event) (bo

for _, comment := range allPages {
activities := &activitiesTypes{}
err := json.Unmarshal(comment.([]byte), activities)
cbyte, ok := comment.([]byte)
if !ok {
return false, fmt.Errorf("cannot convert comment to bytes")
}
err := json.Unmarshal(cbyte, activities)
if err != nil {
return false, err
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/provider/bitbucketserver/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ func paginate(apiResultfunc apiResultfunc) ([]interface{}, error) {
if !ok {
break
}
if isLastPage.(bool) {
isLastPageb, ok := isLastPage.(bool)
if !ok {
break
}

if isLastPageb {
break
}
}
Expand Down
6 changes: 5 additions & 1 deletion test/bitbucket_cloud_pullrequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ func TestBitbucketCloudPullRequest(t *testing.T) {

pr, repobranch := createPR(t, bprovider, runcnx, bcrepo, opts, title, targetNS, targetRefName)
defer bitbucketTearDown(ctx, t, runcnx, bprovider, opts, pr.ID, targetRefName, targetNS)
checkSuccess(ctx, t, runcnx, opts, pullRequestEvent, targetNS, repobranch.Target["hash"].(string), title)

hash, ok := repobranch.Target["hash"].(string)
assert.Assert(t, ok)

checkSuccess(ctx, t, runcnx, opts, pullRequestEvent, targetNS, hash, title)
}

func createPR(t *testing.T, bprovider bitbucketcloud.Provider, runcnx *params.Run, bcrepo *bitbucket.Repository, opts E2EOptions, title, targetNS, targetRefName string) (*types.PullRequest, *bitbucket.RepositoryBranch) {
Expand Down

0 comments on commit 1f6e6fd

Please sign in to comment.