- 
                Notifications
    
You must be signed in to change notification settings  - Fork 2.1k
 
Implemented Graphql requests for Github PR's, Issues and comments scanning #4431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 22 commits
ac2c609
              48a35a5
              f827313
              24571ec
              5d96170
              cda3e75
              f2ff9ca
              a9dc2e0
              871a490
              3f78ee1
              a96a2ea
              1b0af83
              e6fff98
              0b738a4
              2ab5514
              9b9761e
              2fdf5cd
              c3a4de9
              f6445af
              53bc5f1
              4ddb045
              ed85e32
              aa88342
              531985f
              5d00b5a
              d420cc2
              b993a03
              3d2fd13
              615cc9f
              434e92a
              8a5b356
              0c4cda5
              765392d
              095e366
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -27,6 +27,7 @@ import ( | |
| "github.com/trufflesecurity/trufflehog/v3/pkg/cache/simple" | ||
| "github.com/trufflesecurity/trufflehog/v3/pkg/common" | ||
| "github.com/trufflesecurity/trufflehog/v3/pkg/context" | ||
| "github.com/trufflesecurity/trufflehog/v3/pkg/feature" | ||
| "github.com/trufflesecurity/trufflehog/v3/pkg/giturl" | ||
| "github.com/trufflesecurity/trufflehog/v3/pkg/handlers" | ||
| "github.com/trufflesecurity/trufflehog/v3/pkg/pb/source_metadatapb" | ||
| 
          
            
          
           | 
    @@ -1096,8 +1097,14 @@ func (s *Source) scanComments(ctx context.Context, repoPath string, repoInfo rep | |
| if s.includeGistComments && isGistUrl(urlParts) && !s.ignoreGists { | ||
| return s.processGistComments(ctx, urlString, urlParts, repoInfo, reporter, cutoffTime) | ||
| } else if s.includeIssueComments || s.includePRComments { | ||
| return s.processRepoComments(ctx, repoInfo, reporter, cutoffTime) | ||
| // if we need to use graphql api for repo issues, prs and comments | ||
| if feature.UseGithubGraphqlAPI.Load() { | ||
| return s.processRepoIssueandPRsWithCommentsGraphql(ctx, repoInfo, reporter, cutoffTime) | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (No need to do anything here, just musing) Hrm, w/ the old code passing  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sound's good we can do it in a separate optimization PR.  | 
||
| } | ||
| 
     | 
||
| return s.processIssueandPRsWithCommentsREST(ctx, repoInfo, reporter, cutoffTime) | ||
| } | ||
| 
     | 
||
| return nil | ||
| } | ||
| 
     | 
||
| 
          
            
          
           | 
    @@ -1264,7 +1271,7 @@ var ( | |
| state = "all" | ||
| ) | ||
| 
     | 
||
| func (s *Source) processRepoComments(ctx context.Context, repoInfo repoInfo, reporter sources.ChunkReporter, cutoffTime *time.Time) error { | ||
| func (s *Source) processIssueandPRsWithCommentsREST(ctx context.Context, repoInfo repoInfo, reporter sources.ChunkReporter, cutoffTime *time.Time) error { | ||
                
       | 
||
| if s.includeIssueComments { | ||
| ctx.Logger().V(2).Info("Scanning issues") | ||
| if err := s.processIssues(ctx, repoInfo, reporter); err != nil { | ||
| 
        
          
        
         | 
    @@ -1288,6 +1295,28 @@ func (s *Source) processRepoComments(ctx context.Context, repoInfo repoInfo, rep | |
| return nil | ||
| } | ||
| 
     | 
||
| func (s *Source) processRepoIssueandPRsWithCommentsGraphql(ctx context.Context, repoInfo repoInfo, reporter sources.ChunkReporter, cutoffTime *time.Time) error { | ||
| if s.includeIssueComments { | ||
| ctx.Logger().V(2).Info("Scanning issues") | ||
| if err := s.processIssuesWithComments(ctx, repoInfo, reporter, cutoffTime); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| 
     | 
||
| if s.includePRComments { | ||
| ctx.Logger().V(2).Info("Scanning pull requests") | ||
| if err := s.processPRWithComments(ctx, repoInfo, reporter, cutoffTime); err != nil { | ||
| return err | ||
| } | ||
| 
     | 
||
| if err := s.processReviewThreads(ctx, repoInfo, reporter, cutoffTime); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| 
     | 
||
| return nil | ||
| } | ||
| 
     | 
||
| func (s *Source) processIssues(ctx context.Context, repoInfo repoInfo, reporter sources.ChunkReporter) error { | ||
| bodyTextsOpts := &github.IssueListByRepoOptions{ | ||
| Sort: sortType, | ||
| 
          
            
          
           | 
    ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's start this off as
falseso it's not automatically turned on for EE customers (we can/should make ittruefor OSS after we get the flag in EE)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, regretfully I think the initialism is
GraphQL--if we're gonna do it forRESTwe should probably do it here tooThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll temporarily turn it off. I didn't quite understand your second comment - just to clarify, we don’t use any initialism for REST.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I was just saying the "QL" is capitalized;
Graphql->GraphQLThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done