A Drone/Harness CI plugin to automatically commit changes and create pull requests across multiple SCM providers using go-scm.
This plugin automates the complete workflow of committing local changes, pushing to a branch, and creating a pull request - replacing complex bash scripts with a single, portable plugin.
| Feature | GitHub | GitLab | Bitbucket | Gitea | Gogs | Harness Code |
|---|---|---|---|---|---|---|
| πΏ Branch Creation | β | β | β | β | β | β |
| π Commit Changes | β | β | β | β | β | β |
| π Create Pull Request | β | β | β | β | β | β |
| π― Smart Branch Naming | β | β | β | β | β | β |
| π€ Output Variables | β | β | β | β | β | β |
| πͺ Single Commit | β | β | β | β | β | β |
- step:
type: Plugin
name: Push and Create PR
identifier: push_and_create_pr
spec:
connectorRef: account.harnessImage
image: himanshuagrawal/create-pr-plugin
settings:
scm_provider: harness
token: <+secrets.getValue("harness_api_key")>
harness_account_id: <+account.identifier>
harness_org_id: <+org.identifier>
harness_project_id: <+project.identifier>
repo: <+pipeline.properties.ci.codebase.repoName>
source_branch: <+codebase.branch>
netrc_machine: <+codebase.gitHttpUrl>
netrc_username: <+codebase.build.spec.username>
netrc_password: <+codebase.build.spec.password>
create_pr: true
pr_title: "Auto-fix by Harness AI"
pr_description: "Automated fixes for your code"kind: pipeline
type: docker
name: autofix
steps:
- name: run-autofix
image: node:18
commands:
- npm run lint:fix
- name: push-and-create-pr
image: himanshuagrawal/create-pr-plugin
settings:
scm_provider: github
token:
from_secret: github_token
repo: ${DRONE_REPO}
source_branch: ${DRONE_SOURCE_BRANCH}
create_pr: true
pr_title: "Automated fixes"All parameters can be configured through the settings block in your pipeline or as environment variables with PLUGIN_ prefix.
| Parameter | Environment Variable | Description |
|---|---|---|
scm_provider |
PLUGIN_SCM_PROVIDER |
SCM provider: github, gitlab, bitbucket, gitea, gogs, harness |
token |
PLUGIN_TOKEN |
Authentication token (PAT, API key) |
repo |
PLUGIN_REPO |
Repository (owner/repo or just repo-name for Harness) |
source_branch |
PLUGIN_SOURCE_BRANCH |
Current branch name |
| Parameter | Environment Variable | Description |
|---|---|---|
netrc_machine |
PLUGIN_NETRC_MACHINE |
Git server hostname (e.g., github.com) |
netrc_username |
PLUGIN_NETRC_USERNAME |
Git username |
netrc_password |
PLUGIN_NETRC_PASSWORD |
Git password/token |
| Parameter | Environment Variable | Default | Description |
|---|---|---|---|
branch_suffix |
PLUGIN_BRANCH_SUFFIX |
ai-autofix |
Suffix to add to branch name |
force_push |
PLUGIN_FORCE_PUSH |
true |
Force push to branch |
unique_per_execution |
PLUGIN_UNIQUE_PER_EXECUTION |
false |
Add timestamp for unique branch each run |
commit_message |
PLUGIN_COMMIT_MESSAGE |
harness-auto-fix created this fix |
Commit message |
| Parameter | Environment Variable | Default | Description |
|---|---|---|---|
create_pr |
PLUGIN_CREATE_PR |
true |
Whether to create PR |
pr_title |
PLUGIN_PR_TITLE |
Auto-fix by Harness AI |
PR title |
pr_description |
PLUGIN_PR_DESCRIPTION |
Auto-generated fixes |
PR description |
is_draft |
PLUGIN_IS_DRAFT |
false |
Create as draft PR |
bypass_rules |
PLUGIN_BYPASS_RULES |
false |
Bypass branch protection (Harness only) |
| Parameter | Environment Variable | Default | Description |
|---|---|---|---|
push_changes |
PLUGIN_PUSH_CHANGES |
true |
Whether to commit and push changes |
debug |
PLUGIN_DEBUG |
false |
Enable debug logging |
dry_run |
PLUGIN_DRY_RUN |
false |
Log actions without executing |
| Parameter | Environment Variable | Description |
|---|---|---|
harness_account_id |
PLUGIN_HARNESS_ACCOUNT_ID |
Harness account ID |
harness_org_id |
PLUGIN_HARNESS_ORG_ID |
Harness organization ID |
harness_project_id |
PLUGIN_HARNESS_PROJECT_ID |
Harness project ID |
harness_base_url |
PLUGIN_HARNESS_BASE_URL |
Harness base URL (default: https://app.harness.io) |
The plugin exports these variables for use in subsequent steps:
| Variable | Description |
|---|---|
FIX_BRANCH |
Branch where changes were pushed |
IS_DIFF_PRESENT |
true if changes were committed, false otherwise |
PR_NUMBER |
Pull request number (if created) |
AUTOFIX_PR_ID |
Alias for PR_NUMBER |
PR_URL |
Pull request URL (if created) |
COMMIT_SHA |
SHA of the new commit |
ORIGINAL_COMMIT_SHA |
SHA before changes |
- step:
type: Run
name: Next Step
spec:
shell: Sh
command: |-
echo "Branch: <+steps.push_and_create_pr.output.outputVariables.FIX_BRANCH>"
echo "PR: <+steps.push_and_create_pr.output.outputVariables.PR_URL>"The plugin uses smart branch naming based on your current branch:
Current: feature-login
Result: feature-login-ai-autofix
Current: HEAD (detached at abc1234)
Result: commit-abc1234-ai-autofix
Current: feature-login-ai-autofix
Result: feature-login-ai-autofix (reuses same branch)
UNIQUE_PER_EXECUTION=true
Current: feature-login
Result: feature-login-ai-autofix-1738054912 (unique each time)
- step:
type: Plugin
name: Auto-fix and Create PR
identifier: autofix_pr
spec:
connectorRef: account.harnessImage
image: himanshuagrawal/create-pr-plugin
settings:
scm_provider: harness
token: <+secrets.getValue("harness_api_key")>
harness_account_id: <+account.identifier>
harness_org_id: <+org.identifier>
harness_project_id: <+project.identifier>
repo: <+pipeline.properties.ci.codebase.repoName>
source_branch: <+codebase.branch>
# Git authentication
netrc_machine: <+codebase.gitHttpUrl>
netrc_username: <+codebase.build.spec.username>
netrc_password: <+codebase.build.spec.password>
# PR configuration
create_pr: true
pr_title: "Auto-fix by Harness AI"
pr_description: "Automated fixes for your CI checks"
bypass_rules: truekind: pipeline
type: docker
name: autofix
steps:
- name: lint-and-fix
image: node:18
commands:
- npm install
- npm run lint:fix
- name: create-pr
image: himanshuagrawal/create-pr-plugin
settings:
scm_provider: github
token:
from_secret: github_token
repo: ${DRONE_REPO}
source_branch: ${DRONE_SOURCE_BRANCH}
commit_message: "chore: automated linting fixes"
create_pr: true
pr_title: "π€ Automated linting fixes"
pr_description: |
Automated fixes from CI pipeline
- Build: ${DRONE_BUILD_NUMBER}
- Commit: ${DRONE_COMMIT_SHA}autofix:
image: himanshuagrawal/create-pr-plugin
variables:
PLUGIN_SCM_PROVIDER: gitlab
PLUGIN_TOKEN: $GITLAB_TOKEN
PLUGIN_REPO: $CI_PROJECT_PATH
PLUGIN_SOURCE_BRANCH: $CI_COMMIT_REF_NAME
PLUGIN_CREATE_PR: "true"
PLUGIN_PR_TITLE: "Automated fixes"
script:
- /app/create-pr-pluginsettings:
scm_provider: github
token:
from_secret: github_token
repo: owner/repo
source_branch: main
push_changes: true
create_pr: false # Just push, don't create PRsettings:
scm_provider: github
token:
from_secret: github_token
repo: owner/repo
source_branch: feature-branch
push_changes: false # Don't push new changes
create_pr: true # Just create PR from existing branch
pr_title: "Merge feature to main"make buildmake testmake build-docker- Create a test repository
- Make some changes
- Run with environment variables:
export PLUGIN_SCM_PROVIDER=github
export PLUGIN_TOKEN=your_token
export PLUGIN_REPO=owner/repo
export PLUGIN_SOURCE_BRANCH=main
export PLUGIN_DEBUG=true
export PLUGIN_DRY_RUN=true
./create-pr-pluginSolution: Ensure your token has the required permissions:
- GitHub:
reposcope - GitLab:
apiscope - Harness: API key with Code Repository access
Solution: This is normal! The plugin will return the existing PR. Options:
- Set
UNIQUE_PER_EXECUTION=trueto create unique branches each time - Keep default to reuse the same branch and PR (recommended for production)
Solution: This is expected when there are no changes. The plugin will exit successfully with IS_DIFF_PRESENT=false.
- README.md (this file) - Complete documentation
- LICENSE - Apache 2.0 license
Contributions are welcome! Please feel free to submit a Pull Request.
Apache 2.0 License - see LICENSE file for details.
- comment-plugin - Post comments on PRs
- go-scm - Unified SCM client library