Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ac2c609
Added graphql API for issues and PRs
kashifkhan0771 Aug 28, 2025
48a35a5
Merge branch 'main' into feature/oss-209
kashifkhan0771 Aug 29, 2025
f827313
enhancements
kashifkhan0771 Aug 29, 2025
24571ec
more cleanup
kashifkhan0771 Aug 29, 2025
5d96170
more enhancements
kashifkhan0771 Aug 29, 2025
cda3e75
some final touches
kashifkhan0771 Aug 29, 2025
f2ff9ca
some more cleanup
kashifkhan0771 Aug 29, 2025
a9dc2e0
Merge branch 'main' into feature/oss-209
kashifkhan0771 Aug 29, 2025
871a490
tweaked threads vars
kashifkhan0771 Sep 1, 2025
3f78ee1
minor changes
kashifkhan0771 Sep 1, 2025
a96a2ea
scan the markdown text not plain text
kashifkhan0771 Sep 1, 2025
1b0af83
ratelimit handling
kashifkhan0771 Sep 2, 2025
e6fff98
added ratelimit handling
kashifkhan0771 Sep 2, 2025
0b738a4
lint error fix
kashifkhan0771 Sep 2, 2025
2ab5514
Merge branch 'main' into feature/oss-209
kashifkhan0771 Sep 2, 2025
9b9761e
refactored the thread review comments chunking
kashifkhan0771 Sep 3, 2025
2fdf5cd
Merge branch 'main' into feature/oss-209
kashifkhan0771 Sep 3, 2025
c3a4de9
final commit - probably
kashifkhan0771 Sep 3, 2025
f6445af
Merge branch 'main' into feature/oss-209
kashifkhan0771 Sep 5, 2025
53bc5f1
refactored the rate limit handling
kashifkhan0771 Sep 5, 2025
4ddb045
adjusted comments
kashifkhan0771 Sep 5, 2025
ed85e32
Merge branch 'main' into feature/oss-209
kashifkhan0771 Sep 8, 2025
aa88342
Merge branch 'main' into feature/oss-209
kashifkhan0771 Sep 9, 2025
531985f
Merge branch 'main' into feature/oss-209
kashifkhan0771 Sep 10, 2025
5d00b5a
Merge branch 'main' into feature/oss-209
kashifkhan0771 Sep 11, 2025
d420cc2
resolved comments
kashifkhan0771 Sep 11, 2025
b993a03
remove old camel case func
kashifkhan0771 Sep 11, 2025
3d2fd13
renamed featureflag
kashifkhan0771 Sep 15, 2025
615cc9f
resolved martin's comments
kashifkhan0771 Oct 20, 2025
434e92a
Merge branch 'main' into feature/oss-209
kashifkhan0771 Oct 22, 2025
8a5b356
updated test cases
kashifkhan0771 Oct 22, 2025
0c4cda5
Merge branch 'main' into feature/oss-209
kashifkhan0771 Oct 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,9 @@ func run(state overseer.State) {
feature.UseSimplifiedGitlabEnumeration.Store(true)
feature.GitlabProjectsPerPage.Store(100)

// OSS Default using github graphql api for issues, pr's and comments
feature.UseGithubGraphQLAPI.Store(false)

conf := &config.Config{}
if *configFilename != "" {
var err error
Expand Down
1 change: 1 addition & 0 deletions pkg/feature/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var (
UseSimplifiedGitlabEnumeration atomic.Bool
UseGitMirror atomic.Bool
GitlabProjectsPerPage atomic.Int64
UseGithubGraphQLAPI atomic.Bool // use github graphql api to fetch issues, pr's and comments
)

type AtomicString struct {
Expand Down
39 changes: 37 additions & 2 deletions pkg/sources/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1105,8 +1106,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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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 cutoffTime just the once was kind of 🤷🏻 , but now that we're carrying it around everywhere, it makes me think it'd be nice if we processed s.commentsTimeframeDays up top in Init, that way we don't need to drill it down everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
}

Expand Down Expand Up @@ -1273,7 +1280,10 @@ 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 {
Expand All @@ -1297,6 +1307,31 @@ 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,
Expand Down
59 changes: 59 additions & 0 deletions pkg/sources/github/github_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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/pb/credentialspb"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/source_metadatapb"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/sourcespb"
Expand Down Expand Up @@ -968,6 +969,64 @@ func TestSource_Validate(t *testing.T) {
}
}

func TestSource_ScanCommentsWithGraphql(t *testing.T) {
feature.UseGithubGraphQLAPI.Store(true)

ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

source := &sourcespb.GitHub{
Repositories: []string{"https://github.com/trufflesecurity/driftwood.git"},
IncludeIssueComments: true,
IncludePullRequestComments: true,
Credential: &sourcespb.GitHub_Unauthenticated{},
}

wantChunk := sources.Chunk{
SourceType: sourcespb.SourceType_SOURCE_TYPE_GITHUB,
SourceName: "test source",
SourceMetadata: &source_metadatapb.MetaData{
Data: &source_metadatapb.MetaData_Github{
Github: &source_metadatapb.Github{
Link: "https://github.com/trufflesecurity/driftwood.git/issues/1",
Username: "truffle-sandbox",
Timestamp: "2023-06-22 23:33:46 +0000 UTC",
},
},
},
Verify: false,
}

s := Source{}

conn, err := anypb.New(source)
assert.NoError(t, err)

err = s.Init(ctx, "test-source", 0, 0, false, conn, 4)
assert.NoError(t, err)

chunksCh := make(chan *sources.Chunk, 1)
go func() {
// Close the channel
defer close(chunksCh)
err = s.Chunks(ctx, chunksCh)
assert.NoError(t, err)
}()

i := 0
for gotChunk := range chunksCh {
// Skip chunks that are not comments.
if gotChunk.SourceMetadata.GetGithub().GetCommit() != "" {
continue
}
i++
githubCommentCheckFunc(gotChunk, &wantChunk, i, t, "test-source")
}

// Confirm all comments were processed.
assert.Equal(t, i, 5)
}

type countChunkReporter struct {
chunkCount int
errCount int
Expand Down
Loading