Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 2, 2025

This PR implements the ability to post coverage results as comments to GitHub pull requests, GitLab merge requests, Gitea pull requests, and Gogs pull requests, addressing the need for better CI/CD integration as a pre-merge gate.

Features Added

Multi-Platform Support with Official SDKs

  • GitHub: Posts comments via official github.com/google/go-github/v67 SDK with token authentication
  • GitLab: Posts notes via official gitlab.com/gitlab-org/api/client-go SDK with private token authentication
  • Gitea: Posts review comments via official code.gitea.io/sdk/gitea v0.21.0 SDK with token authentication
  • Gogs: Posts issue comments via community github.com/gogits/go-gogs-client SDK with token authentication
  • Self-hosted instances: Configurable base URLs for enterprise deployments

Rich Markdown Comments

Comments include:

  • Overall pass/fail status with visual indicators (✅/❌)
  • Total coverage summary in table format
  • Detailed breakdown of failing files and packages
  • Specific improvement suggestions with required percentages
  • Tool attribution and professional formatting

Configuration Options

New CLI flags:

--comment                           # Enable comment posting
--comment-platform string           # Platform: github|gitlab|gitea|gogs
--comment-token string              # API authentication token
--comment-repository string         # Repository identifier (owner/repo)
--comment-pr int                    # Pull/merge request ID
--comment-base-url string           # Custom API base URL
--comment-update                    # Update existing vs create new comment

YAML configuration support:

comment:
  enabled: true
  platform:
    type: github
    token: ghp_xxxxxxxxxxxxxxxxxxxx
    repository: owner/repo-name
    pullRequestId: 123
    includeColors: true
    updateExisting: false

Example Usage

# GitHub PR comment
go-covercheck coverage.out \
  --comment \
  --comment-platform github \
  --comment-token $GITHUB_TOKEN \
  --comment-repository owner/repo \
  --comment-pr 123

# GitLab MR with custom instance
go-covercheck coverage.out \
  --comment \
  --comment-platform gitlab \
  --comment-base-url https://gitlab.company.com \
  --comment-token $GITLAB_TOKEN \
  --comment-repository group/project \
  --comment-pr 456

# Gitea PR with official SDK
go-covercheck coverage.out \
  --comment \
  --comment-platform gitea \
  --comment-base-url https://gitea.company.com \
  --comment-token $GITEA_TOKEN \
  --comment-repository owner/repo \
  --comment-pr 789

# Gogs PR with community SDK
go-covercheck coverage.out \
  --comment \
  --comment-platform gogs \
  --comment-base-url https://gogs.company.com \
  --comment-token $GOGS_TOKEN \
  --comment-repository owner/repo \
  --comment-pr 101

Implementation Details

Architecture with Official SDKs

  • Clean interface-driven design with Poster interface
  • All platforms now use official or well-maintained Go SDKs for maximum reliability and type safety:
    • GitHub: github.com/google/go-github/v67 (~90 lines, was ~180 with manual HTTP)
    • GitLab: gitlab.com/gitlab-org/api/client-go (~85 lines, was ~180 with manual HTTP)
    • Gitea: code.gitea.io/sdk/gitea v0.21.0 (~115 lines, was ~170 with manual HTTP)
    • Gogs: github.com/gogits/go-gogs-client (~110 lines) - community SDK maintained by Gogs team
  • Markdown formatter that preserves visual formatting across platforms
  • Comprehensive error handling and validation

Benefits of SDK Integration

  • Type Safety: Proper Go structs for all API operations
  • Better Error Handling: SDKs provide descriptive error messages and handle edge cases
  • Maintainability: Significantly reduced code complexity across all platforms
  • API Coverage: Official SDKs stay current with platform API changes
  • Enterprise Support: Proper handling of self-hosted instances

Authentication Requirements

Each platform requires an API token:

  • GitHub: Personal Access Token or GitHub App token with repo scope
  • GitLab: Personal Access Token or Project Access Token with api scope
  • Gitea: Application Token with repository permissions
  • Gogs: Access Token with repository permissions

Backward Compatibility

  • Feature is completely optional and disabled by default
  • Zero impact on existing workflows when not enabled
  • All existing tests continue to pass
  • Maintains existing CLI and configuration structure

Error Handling

  • Validates required configuration before attempting API calls
  • Provides clear error messages for missing tokens, invalid repositories, etc.
  • Graceful fallback behavior (continues execution if comment posting fails)
  • Platform-specific error handling leveraging SDK capabilities

The implementation now consistently uses official or well-maintained tooling across all four major Git hosting platforms, providing a robust foundation for CI/CD integration with enterprise-grade reliability.

Fixes #36.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] [Feature] add the ability to post results to github, gitlab, gitea, others… Add PR/MR comment posting support for GitHub, GitLab, and Gitea Aug 2, 2025
Copilot AI requested a review from mach6 August 2, 2025 05:29
Copy link
Owner

Choose a reason for hiding this comment

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

Is there a gitea go module you can use?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! I've refactored the Gitea implementation to use the official Gitea Go SDK (code.gitea.io/sdk/gitea v0.21.0) instead of manual HTTP calls. This provides better type safety, error handling, and maintainability. The SDK reduces the code from ~170 lines to ~115 lines while offering more robust API integration. All tests continue to pass and the public interface remains unchanged. Commit: 3dd5afb

Copy link
Owner

Choose a reason for hiding this comment

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

Use the GitHub go module

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented! I've refactored the GitHub implementation to use the official github.com/google/go-github/v67 SDK instead of manual HTTP calls. This provides better type safety, error handling, and maintainability while reducing the code complexity from ~180 lines to ~90 lines. All tests continue to pass. Commit: 247253b

Copy link
Owner

@mach6 mach6 Aug 2, 2025

Choose a reason for hiding this comment

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

Is there a Gitlab go module that can be used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! I've implemented GitLab support using the official gitlab.com/gitlab-org/api/client-go SDK (which is the new official location after the deprecated github.com/xanzy/go-gitlab module was migrated). This provides better type safety, proper error handling, and reduces code complexity from ~180 lines to ~85 lines while offering more robust API integration. All tests continue to pass. Commit: 247253b

Copy link
Owner

@mach6 mach6 left a comment

Choose a reason for hiding this comment

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

Please see feedback

Copy link
Contributor Author

Copilot AI commented Aug 2, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/owner/repo/issues/123/comments
    • Triggering command: /tmp/go-build2432181412/b001/comment.test -test.testlogfile=/tmp/go-build2432181412/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (http block)
    • Triggering command: /tmp/go-build2451049526/b001/comment.test -test.testlogfile=/tmp/go-build2451049526/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (http block)
    • Triggering command: /tmp/go-build690437266/b381/comment.test -test.testlogfile=/tmp/go-build690437266/b381/testlog.txt -test.paniconexit0 -test.timeout=10m0s (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Add PR/MR comment posting support for GitHub, GitLab, and Gitea Add PR/MR comment posting support for GitHub, GitLab, and Gitea with official SDK integration Aug 2, 2025
Copilot AI requested a review from mach6 August 2, 2025 05:45
Copy link
Contributor Author

Copilot AI commented Aug 2, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/owner/repo/issues/123/comments
    • Triggering command: /tmp/go-build3270329313/b001/comment.test -test.testlogfile=/tmp/go-build3270329313/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (http block)
    • Triggering command: /tmp/go-build2576784041/b001/comment.test -test.testlogfile=/tmp/go-build2576784041/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true -test.run=TestGitHubPoster (http block)
    • Triggering command: /tmp/go-build3425692420/b001/comment.test -test.testlogfile=/tmp/go-build3425692420/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (http block)

If you need me to access, download, or install something from one of these locations, you can either:

@mach6
Copy link
Owner

mach6 commented Aug 2, 2025

Cool. Lets add support for gogs too!

Copy link
Contributor Author

Copilot AI commented Aug 2, 2025

Cool. Lets add support for gogs too!

Added Gogs support! The implementation uses the official github.com/gogits/go-gogs-client SDK maintained by the Gogs team. This provides:

  • Issue comment posting to Gogs pull requests
  • Full validation and error handling
  • Support for updating existing comments
  • Self-hosted instance configuration via --comment-base-url
  • Same interface as other platforms: --comment-platform gogs

Updated documentation, help text, and sample config to include Gogs alongside GitHub, GitLab, and Gitea. All tests pass and the implementation follows the same patterns as other platforms. Commit: b57bd66

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/owner/repo/issues/123/comments
    • Triggering command: /tmp/go-build2575050715/b001/comment.test -test.testlogfile=/tmp/go-build2575050715/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (http block)
  • https://api.github.com/search/repositories
    • Triggering command: curl -s REDACTED (http block)
  • try.gogs.io

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Add PR/MR comment posting support for GitHub, GitLab, and Gitea with official SDK integration Add PR/MR comment posting support for GitHub, GitLab, Gitea, and Gogs with official SDK integration Aug 2, 2025
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.

[Feature] add the ability to post results to github, gitlab, gitea, others…

2 participants