A Drone/Harness CI plugin to post comments on pull requests across multiple SCM providers using go-scm.
| Feature | GitHub | GitLab | Bitbucket | Gitea | Gogs | Harness Code |
|---|---|---|---|---|---|---|
| π¬ PR Comments | β | β | β | β | β | β |
| π Inline Code Comments | β | β | β | β | β | β |
| π Commit Status | β | β | β | β | β | β |
| π Batch Comments from JSON | β | β | β | β | β | β |
kind: pipeline
type: docker
name: comment
steps:
- name: post-comment
image: abhinavharness/comment-plugin
settings:
scm_provider: github
token:
from_secret: github_token
repo: owner/repo
pr_number: ${DRONE_PULL_REQUEST}
comment_body: "Build passed! β
"kind: pipeline
type: docker
name: code-review
steps:
- name: ai-review
image: abhinavharness/drone-ai-review:latest
settings:
enable_bugs: true
enable_performance: true
review_output_file: /drone/src/reviews.json
- name: post-reviews
image: abhinavharness/comment-plugin
settings:
scm_provider: harness
token:
from_secret: harness_token
harness_account_id: ${HARNESS_ACCOUNT_ID}
repo: my-repo
pr_number: ${PR_NUMBER}
comments_file: /drone/src/reviews.json
trigger:
event:
- pull_requestAll parameters can be configured through the settings block in your .drone.yml file or as environment variables.
| Parameter | Environment Variable | Type | Required | Description |
|---|---|---|---|---|
scm_provider |
SCM_PROVIDER |
string | β | SCM provider: github, gitlab, bitbucket, gitea, gogs, harness |
token |
TOKEN |
string | β | Authentication token |
repo |
REPO |
string | β | Repository (owner/repo or repo name for Harness) |
scm_endpoint |
SCM_ENDPOINT |
string | Custom API endpoint for self-hosted instances |
| Parameter | Environment Variable | Type | Default | Description |
|---|---|---|---|---|
pr_number |
PR_NUMBER |
integer | Pull request number | |
comment_body |
COMMENT_BODY |
string | Comment text | |
file_path |
FILE_PATH |
string | File path for inline comments | |
line |
LINE |
integer | Line number for inline comments | |
comments_file |
COMMENTS_FILE |
string | Path to JSON file with batch comments |
| Parameter | Environment Variable | Type | Default | Description |
|---|---|---|---|---|
commit_sha |
COMMIT_SHA |
string | Commit SHA for status | |
status_state |
STATUS_STATE |
string | Status: pending, success, failure, error |
|
status_context |
STATUS_CONTEXT |
string | Status check name | |
status_desc |
STATUS_DESC |
string | Status description | |
status_url |
STATUS_URL |
string | Link URL for status |
| Parameter | Environment Variable | Type | Description |
|---|---|---|---|
harness_account_id |
HARNESS_ACCOUNT_ID |
string | Harness account ID (required for Harness) |
harness_org_id |
HARNESS_ORG_ID |
string | Harness organization ID (optional) |
harness_project_id |
HARNESS_PROJECT_ID |
string | Harness project ID (optional) |
| Parameter | Environment Variable | Type | Default | Description |
|---|---|---|---|---|
debug |
DEBUG |
boolean | false | Enable debug logging |
dry_run |
DRY_RUN |
boolean | false | Log actions without posting |
Post a general comment on a pull request:
settings:
scm_provider: github
token:
from_secret: github_token
repo: owner/repo
pr_number: ${DRONE_PULL_REQUEST}
comment_body: "Build completed successfully! π"Post a comment on a specific line of code:
settings:
scm_provider: github
token:
from_secret: github_token
repo: owner/repo
pr_number: ${DRONE_PULL_REQUEST}
file_path: src/main.go
line: 42
comment_body: "Consider using a constant here"Set a commit status check:
settings:
scm_provider: github
token:
from_secret: github_token
repo: owner/repo
commit_sha: ${DRONE_COMMIT_SHA}
status_state: success
status_context: ci/lint
status_desc: "Linting passed"
status_url: ${DRONE_BUILD_LINK}Post multiple inline comments from a JSON file (perfect for AI code reviews):
settings:
scm_provider: harness
token:
from_secret: harness_token
harness_account_id: ACCOUNT_ID
repo: my-repo
pr_number: ${PR_NUMBER}
comments_file: /path/to/reviews.jsonThe comments_file should contain a JSON object with a reviews array:
{
"reviews": [
{
"file_path": "src/main.go",
"line_number_start": 42,
"line_number_end": 42,
"type": "performance",
"review": "Consider using a more efficient algorithm here"
},
{
"file_path": "src/utils.go",
"line_number_start": 100,
"line_number_end": 105,
"type": "bug",
"review": "Potential null pointer dereference"
}
]
}| Field | Type | Description |
|---|---|---|
file_path |
string | Path to the file |
line_number_start |
integer | Starting line number |
line_number_end |
integer | Ending line number |
type |
string | Review type (e.g., bug, performance, scalability, code_smell) |
review |
string | The review comment text |
| Type | Emoji | Description |
|---|---|---|
bug |
π | Critical bugs and errors |
performance |
β‘ | Performance issues |
scalability |
π | Scalability concerns |
code_smell |
π | Code quality issues |
| custom | π | Any custom category |
Comments are formatted with the type as a prefix: **performance:** Your review text
This plugin works seamlessly with ai-review-prompt-plugin:
kind: pipeline
type: docker
name: ai-code-review
steps:
# Step 1: Generate AI review prompt
- name: generate-prompt
image: abhinavharness/drone-ai-review:latest
settings:
enable_bugs: true
enable_performance: true
enable_scalability: true
enable_code_smell: true
review_output_file: /drone/src/reviews.json
# Step 2: Run AI model (example with OpenAI)
- name: run-ai-review
image: your-ai-runner:latest
commands:
- cat /drone/src/output/task.txt | openai-api > /drone/src/reviews.json
# Step 3: Post comments to PR
- name: post-comments
image: abhinavharness/comment-plugin
settings:
scm_provider: harness
token:
from_secret: harness_token
harness_account_id: ${HARNESS_ACCOUNT_ID}
repo: ${DRONE_REPO_NAME}
pr_number: ${DRONE_PULL_REQUEST}
comments_file: /drone/src/reviews.json
trigger:
event:
- pull_request- step:
type: Plugin
name: Post Comment
spec:
connectorRef: dockerhub
image: abhinavharness/comment-plugin
settings:
scm_provider: harness
token: <+secrets.getValue("harness_token")>
harness_account_id: <+account.identifier>
repo: <+pipeline.properties.ci.codebase.repoName>
pr_number: <+codebase.prNumber>
comment_body: "Pipeline completed! β
"- step:
type: Plugin
name: Post AI Reviews
spec:
connectorRef: dockerhub
image: abhinavharness/comment-plugin
settings:
scm_provider: harness
token: <+secrets.getValue("harness_token")>
harness_account_id: <+account.identifier>
repo: <+pipeline.properties.ci.codebase.repoName>
pr_number: <+codebase.prNumber>
comments_file: /harness/reviews.json- Go 1.21 or higher
- Docker (with buildx for multi-arch builds)
- Git
- Clone the repository:
git clone https://github.com/abhinav-harness/comment-plugin.git
cd comment-plugin- Install dependencies:
go mod download- Build the plugin:
go build -o comment-plugin ./cmd/plugin- Run tests:
go test -v ./...- Run locally:
export SCM_PROVIDER="github"
export TOKEN="your-token"
export REPO="owner/repo"
export PR_NUMBER="1"
export COMMENT_BODY="Test comment"
./comment-plugin# Build local image
docker build -t comment-plugin .
# Build multi-arch and push
docker buildx build --platform linux/amd64,linux/arm64 \
-t abhinavharness/comment-plugin:latest \
--push .- Verify the token has write permissions to the repository
- Check that
pr_numberis set correctly - Enable
debug: trueto see detailed logs
- The plugin handles missing files gracefully (logs warning and continues)
- Verify the file path is correct and accessible in the container
- Check that the previous step wrote the file successfully
- Ensure
harness_account_idis set correctly - Verify the token has access to the repository
- Check that the repository name matches exactly
- Ensure
file_pathandlineare both provided - For batch comments, verify
line_number_startandline_number_endare set - The file path must match a file changed in the PR
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Apache 2.0 License - see LICENSE file for details.
- GitHub Issues: https://github.com/abhinav-harness/comment-plugin/issues
- Docker Hub: https://hub.docker.com/r/abhinavharness/comment-plugin
- ai-review-prompt-plugin - Generate AI review prompts for code review
- go-scm - Unified SCM client library