Skip to content

Commit

Permalink
handle IOOR panic.
Browse files Browse the repository at this point in the history
  • Loading branch information
ahrav committed Aug 17, 2023
1 parent 55b9d48 commit 8051c84
Showing 1 changed file with 67 additions and 65 deletions.
132 changes: 67 additions & 65 deletions pkg/sources/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -1022,90 +1022,92 @@ func (s *Source) scanComments(ctx context.Context, repoPath string, chunksChan c
break
}
}
} else {
// Normal repository URL (https://github.com/<owner>/<repo>).
owner := trimmedURL[1]
repo := trimmedURL[2]

var (
sortType = "created"
directionType = "desc"
allComments = 0
)

if s.includeIssueComments {
}
return s.handleComments(ctx, repoPath, trimmedURL, repoURL, chunksChan)
}

s.log.Info("scanning github issue comments", "repository", repoPath)
func (s *Source) handleComments(ctx context.Context, repoPath string, trimmedURL []string, repoURL *url.URL, chunksChan chan *sources.Chunk) error {
// Normal repository URL (https://github.com/<owner>/<repo>).
if len(trimmedURL) < 3 {
return fmt.Errorf("url missing owner and/or repo: '%s'", repoURL.String())
}
owner := trimmedURL[1]
repo := trimmedURL[2]

issueOpts := &github.IssueListCommentsOptions{
Sort: &sortType,
Direction: &directionType,
ListOptions: github.ListOptions{
PerPage: defaultPagination,
Page: 1,
},
}
var (
sortType = "created"
directionType = "desc"
allComments = 0
)

for {
issueComments, resp, err := s.apiClient.Issues.ListComments(ctx, owner, repo, allComments, issueOpts)
if s.handleRateLimit(err, resp) {
break
}
if s.includeIssueComments {
s.log.Info("scanning github issue comments", "repository", repoPath)

if err != nil {
return err
}
issueOpts := &github.IssueListCommentsOptions{
Sort: &sortType,
Direction: &directionType,
ListOptions: github.ListOptions{
PerPage: defaultPagination,
Page: 1,
},
}

err = s.chunkIssueComments(ctx, repo, issueComments, chunksChan, repoPath)
if err != nil {
return err
}
for {
issueComments, resp, err := s.apiClient.Issues.ListComments(ctx, owner, repo, allComments, issueOpts)
if s.handleRateLimit(err, resp) {
break
}

issueOpts.ListOptions.Page++
if err != nil {
return err
}

if len(issueComments) < defaultPagination {
break
}
if err = s.chunkIssueComments(ctx, repo, issueComments, chunksChan, repoPath); err != nil {
return err
}

issueOpts.ListOptions.Page++

if len(issueComments) < defaultPagination {
break
}
}

if s.includePRComments {
s.log.Info("scanning github pull request comments", "repository", repoPath)
}

prOpts := &github.PullRequestListCommentsOptions{
Sort: sortType,
Direction: directionType,
ListOptions: github.ListOptions{
PerPage: defaultPagination,
Page: 1,
},
}
if s.includePRComments {
s.log.Info("scanning github pull request comments", "repository", repoPath)

for {
prComments, resp, err := s.apiClient.PullRequests.ListComments(ctx, owner, repo, allComments, prOpts)
if s.handleRateLimit(err, resp) {
break
}
prOpts := &github.PullRequestListCommentsOptions{
Sort: sortType,
Direction: directionType,
ListOptions: github.ListOptions{
PerPage: defaultPagination,
Page: 1,
},
}

if err != nil {
return err
}
for {
prComments, resp, err := s.apiClient.PullRequests.ListComments(ctx, owner, repo, allComments, prOpts)
if s.handleRateLimit(err, resp) {
break
}

err = s.chunkPullRequestComments(ctx, repo, prComments, chunksChan, repoPath)
if err != nil {
return err
}
if err != nil {
return err
}

prOpts.ListOptions.Page++
if err = s.chunkPullRequestComments(ctx, repo, prComments, chunksChan, repoPath); err != nil {
return err
}

if len(prComments) < defaultPagination {
break
}
prOpts.ListOptions.Page++

if len(prComments) < defaultPagination {
break
}
}
}

return nil
}

Expand Down Expand Up @@ -1189,7 +1191,7 @@ func (s *Source) chunkGistComments(ctx context.Context, gistUrl string, comments
Timestamp: sanitizer.UTF8(comment.GetCreatedAt().String()),
// Fetching this information requires making an additional API call.
// We may want to include this in the future.
//Visibility: s.visibilityOf(ctx, repoPath),
// Visibility: s.visibilityOf(ctx, repoPath),
},
},
},
Expand Down

0 comments on commit 8051c84

Please sign in to comment.