Skip to content

Gitea Integrations issues fixes#33

Merged
Amazing-Stardom merged 10 commits into
masterfrom
fix/gitea-issues
May 3, 2026
Merged

Gitea Integrations issues fixes#33
Amazing-Stardom merged 10 commits into
masterfrom
fix/gitea-issues

Conversation

@Amazing-Stardom
Copy link
Copy Markdown
Contributor

@Amazing-Stardom Amazing-Stardom commented Apr 30, 2026

Gitea is a Git provider that LR supports as a PR review. But it has some bugs in posting comments.

Problems

  1. Comment was not posted in the right discussion.
  2. General Discussion was not identifying but posting in the last discussion.
  3. Inline questions asked with the LR bot were not answered in the right location.

Solution

  1. All 4 features are correctly happening without any issues.
  2. Anyone can mention the LR bot and get a reply back on correct discussion.

What's left for now

  1. Gitea Inline Comment Reply Issues : Gitea Inline Comment Reply Issues #34

LiveReview Pre-Commit Check: skipped manually
LiveReview Pre-Commit Check: ran (iter:3, coverage:100%)
LiveReview Pre-Commit Check: ran (iter:1, coverage:0%)
@Amazing-Stardom Amazing-Stardom marked this pull request as draft April 30, 2026 16:23
baseURL, owner, repo, prNumber, reviewID, len(replyText))
func (c *APIClient) postInlineCommentReplyMultipart(baseURL, owner, repo string, prNumber int, event *UnifiedWebhookEventV2, replyText string, reviewID, replyCommentID int64, username, password string) error {
log.Printf("[DIAG] postInlineCommentReplyMultipart ENTRY: baseURL=%s, owner=%s, repo=%s, prNumber=%d, reviewID=%d, replyCommentID=%d, replyTextLen=%d",
baseURL, owner, repo, prNumber, reviewID, replyCommentID, len(replyText))
…ccuracy

LiveReview Pre-Commit Check: ran (iter:3, coverage:68%)
@Amazing-Stardom
Copy link
Copy Markdown
Contributor Author

Severity: info

Implement Comprehensive Gitea Integration

Overview

This change set significantly enhances Gitea integration, improving webhook processing, API interactions, and comment handling. It standardizes network calls and refines how Gitea's unique inline review events are interpreted and processed. New documentation outlines known Gitea-specific issues.

Technical Highlights

  • docs/integrations/gitea/gitea_issues.md: Introduces dedicated documentation for known Gitea integration issues and their resolutions.
  • internal/api/unified_processor_v2.go: Adds logic to process Gitea reviewed actions as inline reviews, even with empty comment bodies.
  • internal/api/unified_processor_v2.go: Standardizes HTTP client usage for GitHub and Bitbucket via dedicated network packages.
  • internal/api/webhook_orchestrator_v2.go: Routes Gitea review_submission events to the handleCommentReplyFlow for inline comments.
  • internal/api/webhook_orchestrator_v2.go: Implements a pre-processing check to skip AI response generation for empty comment bodies.
  • internal/provider_input/gitea/gitea_conversion.go: Explicitly processes Gitea reviewed actions and enhances comment type classification.
  • internal/provider_input/gitea/gitea_provider.go: Enriches Gitea reviewed events by fetching associated review comments and identifying bot mentions.
  • internal/provider_input/gitea/gitea_provider.go: Introduces getExactLineFromHunk to accurately determine line numbers and file sides from diff hunks.
  • internal/provider_input/gitea/gitea_types.go: Adds DiffHunk field to GiteaReviewComment to capture complete diff context.
  • internal/provider_output/gitea/api_client.go: Refactors enrichCommentMetadata to build a comprehensive index for correct inline reply threading.
  • internal/provider_output/gitea/api_client.go: Updates postInlineCommentReplyMultipart to align with Gitea's form submission for inline replies.
  • internal/providers/gitea/gitea_provider.go: Adopts a new networkgitea package for centralized HTTP client and request handling.
  • internal/providers/gitea/gitea_provider.go: Adds formatGiteaComment to standardize Gitea review comment presentation.
  • osv-scanner.toml: Removes two previously ignored OSV vulnerabilities related to pgx.

Impact

  • Functionality: Enables robust and accurate processing of Gitea pull request reviews, including complex inline comments and replies.
  • Functionality: Standardizes network interactions across multiple providers (Gitea, GitHub, Bitbucket), improving consistency and maintainability.
  • Functionality: Optimizes resource usage by skipping AI processing for empty comment bodies.
  • Functionality: Improves security hygiene by addressing previously ignored OSV vulnerabilities.
  • Risk: Gitea's complex API for inline comments and threading may introduce new edge cases requiring ongoing monitoring.
  • Risk: The extensive changes to Gitea's webhook and API processing require thorough testing across various Gitea versions and scenarios.
  • Risk: Data model changes in UnifiedWebhookEventV2.Comment.Metadata and Position require downstream compatibility checks.

Comment thread internal/api/unified_processor_v2.go
Comment thread internal/api/webhook_orchestrator_v2.go
Comment thread internal/api/webhook_orchestrator_v2.go
Comment thread internal/provider_input/gitea/gitea_conversion.go
Comment thread internal/provider_input/gitea/gitea_conversion.go
Comment thread internal/provider_input/gitea/gitea_conversion.go
Comment thread internal/provider_input/gitea/gitea_conversion.go
Comment thread internal/provider_input/gitea/gitea_provider.go
Comment thread internal/provider_input/gitea/gitea_provider.go
Comment thread internal/provider_input/gitea/gitea_provider.go
Comment thread internal/provider_input/gitea/gitea_provider.go
LineType: lineType,
}
}
break // Take the first mention we find
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Severity: critical

This break statement contradicts the stated solution for 'Race Condition Handling for Multiple Bot Comments' (TODO #4 in gitea_issues.md).

Suggestions:

  1. Remove this break statement. The solution explicitly mentions 'Removed early break after finding first suitable comment' and 'Collect all suitable comments instead of breaking after first match'. This needs to be removed to implement the intended fix for race conditions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added to issue #34

Comment thread internal/provider_input/gitea/gitea_provider.go
Comment thread internal/provider_input/gitea/gitea_provider.go
Comment thread internal/provider_input/gitea/gitea_provider.go
Comment thread internal/provider_input/gitea/gitea_provider.go
Comment thread internal/provider_input/gitea/gitea_provider.go
Comment thread internal/provider_output/gitea/api_client.go
Comment thread internal/provider_output/gitea/api_client.go
Comment thread internal/provider_output/gitea/api_client.go
Comment thread internal/provider_output/gitea/api_client.go
Comment thread internal/provider_output/gitea/api_client.go
Comment thread internal/provider_output/gitea/api_client.go
Comment thread internal/provider_output/gitea/api_client.go
Comment thread internal/provider_output/gitea/api_client.go
Comment thread internal/provider_output/gitea/api_client.go
Comment thread internal/provider_output/gitea/api_client.go Outdated
Comment thread internal/providers/gitea/gitea_provider.go Outdated
Comment thread internal/providers/gitea/gitea_provider.go Outdated
Comment thread internal/providers/gitea/gitea_provider.go
Comment thread internal/providers/gitea/gitea_provider.go
Comment thread internal/providers/gitea/gitea_provider.go Outdated
Comment thread osv-scanner.toml
LiveReview Pre-Commit Check: ran (iter:1, coverage:0%)
LiveReview Pre-Commit Check: ran (iter:1, coverage:0%)
LiveReview Pre-Commit Check: ran (iter:1, coverage:0%)
@Amazing-Stardom Amazing-Stardom changed the title Fix/gitea issues Gitea Integrations issues fixes May 3, 2026
return true, ResponseScenarioV2{
Type: "review_submission",
Reason: "Gitea review submission (requires scan of inline comments)",
Confidence: 0.5, // Low confidence until we find a mention in the scan
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.

What is this confidence value? where it is used and why it is 0.5?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Gitea doesn't have proper webhooks.

whenever new comment posted, it doesn't have any data in the webhook.

So, there is a 50% probability whether the reply is needed or not based on fetching the recent comment posted in the PR.

So, it is set up to 0.5 to identify the confidence level of the comment.

}

req, err := http.NewRequest("GET", apiURL, nil)
req, err := networkgithub.NewRequest(http.MethodGet, apiURL, nil)
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.

Why did this change to networkGitHub? What is the difference?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This might not be related to Gitea issues, but this change has to be done due to rule 2 in Copilot instructions and security audits.

  1. All the network operations should be defined in a single module with proper security doc mentioned in the network. md
  2. This rule mainly focuses on any HTTP request that should be done through a single model.

Rule 2: https://github.com/HexmosTech/LiveReview/blob/master/.github/copilot-instructions.md#rule-2-code-organization-and-status-docs

}
// Construct the official API patch URL which reliably accepts PAT authentication.
// We prioritize this over the UI-based patch_url often found in webhook metadata.
baseURL := strings.TrimRight(token.ProviderURL, "/")
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.

What is the difference here from previous patchURL construction?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The old version was directly fetching the patch URL in the UI, which was added to send in the webhook.
which may need auth to view the page.

As I checked a few cases, the path URL was not sent in the webhook from the Gitea side.
So, I just reordered to use an actual API call with a PAT token to view diff.

@LinceMathew
Copy link
Copy Markdown
Contributor

Did you test other Git providers (eg: github) with these new changes?

@Amazing-Stardom
Copy link
Copy Markdown
Contributor Author

Did you test other Git providers (eg: github) with these new changes?

There were no major changes with other Git providers other than the network module refactor. So, it will work as expected.

LiveReview Pre-Commit Check: ran (iter:1, coverage:0%)
@Amazing-Stardom Amazing-Stardom marked this pull request as ready for review May 3, 2026 09:23
@LinceMathew
Copy link
Copy Markdown
Contributor

Did you test other Git providers (eg: github) with these new changes?

There were no major changes with other Git providers other than the network module refactor. So, it will work as expected.

did you tested?

@Amazing-Stardom
Copy link
Copy Markdown
Contributor Author

Did you test other Git providers (eg: github) with these new changes?

There were no major changes with other Git providers other than the network module refactor. So, it will work as expected.

did you tested?

Tested now.
No issues found.

@Amazing-Stardom Amazing-Stardom merged commit b94241a into master May 3, 2026
15 of 16 checks passed
@LinceMathew LinceMathew deleted the fix/gitea-issues branch May 18, 2026 15:56
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.

3 participants