Skip to content

feat(gitter): affected commits graph walking#4974

Merged
Ly-Joey merged 40 commits into
google:masterfrom
Ly-Joey:feat-gitter-affected-commits
Mar 20, 2026
Merged

feat(gitter): affected commits graph walking#4974
Ly-Joey merged 40 commits into
google:masterfrom
Ly-Joey:feat-gitter-affected-commits

Conversation

@Ly-Joey

@Ly-Joey Ly-Joey commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

Add graph related logic and find affected commits to gitter

Definition of affected commits:

A commit is affected when: from at least one introduced that is an ancestor of the commit, there is no path between them that passes through a fix. A fix can either be a fixed commit, or the children of a lastAffected commit.

Key changes

New endpoint:

  • POST /affected-commits:
    • Accepts a list of events (each containing an eventType (introduced, fixed, lastAffected, or limit) and commit hash)
    • Returns a list of affected commits and refs (tags and branches)

Cherry-pick Detection (optional):
Expand introduced, fixed, limit commits to include their cherry-picked equivalents (determined with PatchID)

@Ly-Joey

Ly-Joey commented Mar 9, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces significant new functionality for determining affected commits by walking the git graph. However, it also introduces several critical security vulnerabilities, primarily related to command injection and SSRF. The most severe issue is in buildCommitGraph, where user-controlled data is concatenated into a shell command, and new endpoints lack the protocol validation present in existing ones, allowing for command execution via git protocols. Additionally, a potential Denial of Service vulnerability due to unvalidated input length during hash parsing was identified. Beyond these security concerns, a critical bug was found in the graph building logic, and there are opportunities to improve code structure and testing practices to enhance maintainability and robustness.

Comment thread go/cmd/gitter/gitter.go Outdated
Comment thread go/cmd/gitter/repository.go Outdated
Comment thread go/cmd/gitter/gitter.go Outdated
Comment thread go/cmd/gitter/gitter_test.go
Comment thread go/cmd/gitter/repository.go Outdated
Comment thread go/cmd/gitter/repository_test.go Outdated
Comment thread go/cmd/gitter/repository_test.go Outdated
@Ly-Joey Ly-Joey force-pushed the feat-gitter-affected-commits branch from 4227a68 to 97b9e25 Compare March 10, 2026 02:19
@Ly-Joey

Ly-Joey commented Mar 10, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces a new /affected-commits API endpoint to the gitter service, enabling clients to query for commits affected by specific events (introduced, fixed, last_affected, limit) within a Git repository. This includes implementing graph traversal logic (Affected and Limit methods) with support for cherry-pick detection, defining new Protobuf messages for the API response, and adding URL validation to both the new and existing /cache handlers. The Commit struct was updated to use Refs instead of Tags, and rootCommits were added to the Repository struct. Review comments highlighted several areas for improvement: optimizing regex compilation for URL validation in both cacheHandler and affectedCommitsHandler by compiling it once at the package level; enhancing test robustness and readability in TestAffectedCommitsHandler by using EventType constants instead of hardcoded strings; clarifying the Limit function's assumption about linear history when traversing commits by following only the first parent; and correcting a bug in the decodeSHA1 helper function in repository_test.go where fmt.Sprintf incorrectly pads with spaces instead of zeros, which would cause hex.DecodeString to fail.

Comment thread go/cmd/gitter/gitter.go Outdated
Comment thread go/cmd/gitter/gitter_test.go
Comment thread go/cmd/gitter/repository.go Outdated
Comment thread go/cmd/gitter/repository_test.go Outdated
@Ly-Joey Ly-Joey marked this pull request as ready for review March 10, 2026 04:59

@another-rex another-rex left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh btw for the bfs and the queue, did you know about: https://pkg.go.dev/container/list

@Ly-Joey Ly-Joey requested a review from another-rex March 18, 2026 03:59
Comment thread deployment/clouddeploy/gke-workers/base/gitter.yaml Outdated
Comment thread go/cmd/gitter/gitter.go Outdated
Comment thread go/cmd/gitter/gitter.go Outdated
Comment thread go/cmd/gitter/gitter.go Outdated
Comment thread go/cmd/gitter/repository.go
another-rex
another-rex previously approved these changes Mar 19, 2026

@another-rex another-rex left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! LGTM

Comment thread go/cmd/gitter/gitter.go Outdated
@Ly-Joey Ly-Joey requested a review from another-rex March 20, 2026 02:06
@Ly-Joey Ly-Joey enabled auto-merge (squash) March 20, 2026 02:28
@Ly-Joey Ly-Joey merged commit 095169d into google:master Mar 20, 2026
23 checks passed
tymzd pushed a commit to tymzd/osv.dev that referenced this pull request Apr 13, 2026
Add graph related logic and find affected commits to gitter

Definition of affected commits:
> A `commit` is affected when: from at least one `introduced` that is an
ancestor of the `commit`, there is no path between them that passes
through a fix. A fix can either be a `fixed` commit, or the children of
a `lastAffected` commit.

### Key changes
New endpoint: 
- `POST /affected-commits`: 
- Accepts a list of events (each containing an eventType (introduced,
fixed, lastAffected, or limit) and commit hash)
  - Returns a list of affected commits and refs (tags and branches)

Cherry-pick Detection (optional): 
Expand introduced, fixed, limit commits to include their cherry-picked
equivalents (determined with PatchID)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants