Star on GitHub

Using PRSense as a GitHub Action

This repository includes a GitHub Action for Repository Memory and automatic duplicate PR detection.

Quick Setup

  1. Add the workflow file to your repository at .github/workflows/prsense.yml:
name: PRSense Repository Memory

on:
pull_request:
types: [opened, synchronize, reopened]

jobs:
check-duplicates:
runs-on: ubuntu-latest
name: Check for Duplicate PRs

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Run PRSense
uses: prsense-labs/prsense@v2.0.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
duplicate-threshold: '0.90'
possible-threshold: '0.82'
post-comment: 'true'
  1. Add your OpenAI API key to repository secrets:
  • Go to Settings → Secrets and variables → Actions
  • Click “New repository secret”
  • Name: OPENAI_API_KEY
  • Value: Your OpenAI API key
  1. That’s it! PRSense will now automatically check every PR for duplicates.

Inputs

InputDescriptionRequiredDefault
github-tokenGitHub token for API accessYes-
openai-api-keyOpenAI API key for embeddingsYes-
duplicate-thresholdScore threshold for duplicates (0.0-1.0)No0.90
possible-thresholdScore threshold for possible duplicates (0.0-1.0)No0.82
post-commentWhether to post comments on PRsNotrue
embedding-providerEmbedding provider: openai or onnxNoopenai

Tip: Set embedding-provider: onnx to use free local embeddings (no API key needed).

Outputs

OutputDescription
resultDetection result: DUPLICATE, POSSIBLE, or NONE
duplicates-foundBoolean indicating if duplicates were found
duplicate-countNumber of duplicate PRs found
similar-prPR number of the most similar PR (if any)

Example: Fail CI on Duplicates

name: PRSense with Duplicate Prevention

on:
pull_request:
types: [opened, synchronize, reopened]

jobs:
check-duplicates:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Check for duplicates
id: prsense
uses: prsense-labs/prsense@v2.0.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
openai-api-key: ${{ secrets.OPENAI_API_KEY }}

- name: Fail if duplicate
if: steps.prsense.outputs.result == 'DUPLICATE'
run: |
echo "::error::This PR is a duplicate of #${{ steps.prsense.outputs.similar-pr }}"
exit 1

How It Works

  1. Action triggers when a PR is opened/updated
  2. Fetches PR details (title, description, files)
  3. Compares against all open PRs using AI embeddings
  4. Posts a comment if duplicates are found
  5. Sets outputs for use in subsequent workflow steps

Comment Examples

Duplicate Detected

PRSense: Duplicate Detected

This pull request appears to be a duplicate of PR #123.

Similarity Score: 0.945 (threshold: 0.90)

Breakdown:
- Text Similarity: 92.3%
- Diff Similarity: 88.1%
- File Overlap: 85.0%

Possible Duplicate

PRSense: Possible Duplicate

This pull request may be similar to PR #456.

Similarity Score: 0.867 (threshold: 0.82)

Breakdown:
- Text Similarity: 78.5%
- Diff Similarity: 82.3%
- File Overlap: 90.5%

Cost Estimation

PRSense uses OpenAI’s embedding API. Typical costs:

  • Small PR (~100 lines): ~$0.0001
  • Medium PR (~500 lines): ~$0.0005
  • Large PR (~2000 lines): ~$0.002

For a repository with 50 PRs/month, expect ~$0.10/month in API costs.

Free Alternative: Use embedding-provider: onnx to avoid API costs entirely. See Features for details.

Troubleshooting

Action fails with “This action only works on pull_request events”

  • Ensure the workflow is triggered by pull_request events

No comments posted

  • Check that post-comment is set to 'true'
  • Verify GITHUB_TOKEN has write permissions

Rate limiting

  • OpenAI API has generous rate limits
  • GitHub API rate limit is 1000 requests/hour for GITHUB_TOKEN

Development

To use this action in your own repository:

- uses: prsense-labs/prsense@v2.0.0

To use a local copy (for development):

- uses: ./