Skip to content

Commit

Permalink
*: initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
thypon committed Nov 29, 2023
1 parent 579fc15 commit 30e6710
Show file tree
Hide file tree
Showing 7 changed files with 595 additions and 11 deletions.
11 changes: 3 additions & 8 deletions .github/workflows/loop.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
name: loop
on:
workflow_dispatch:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches: [main]
permissions:
contents: read
pull-requests: write
jobs:
loop:
name: loop
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
Expand All @@ -25,3 +19,4 @@ jobs:
with:
debug: true
github_token: ${{ secrets.GITHUB_TOKEN }}
openai_api_key: ${{ secrets.OPENAI_API_KEY }}
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
# ![pull-merge](/logo/svg/logo-no-background.svg)

puLL-Merge is a `github-action` to add LLM capabilities to pull-requests in `github` automatically

## Usage

Add an action under `.github/workflow/security-action.yml` with the following content:

```yaml
name: puLL-Merge
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches: [main]

jobs:
pull-merge:
name: security
runs-on: ubuntu-latest
steps:
- uses: brave/pull-merge@main
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
openai_key: ${{ secrets.OPENAI_KEY }}

```

## Testing LLM integrations (local)

```bash
$ ./run.js ./src/explainPatch.js --openaiKey=<OPENAI_KEY> --repo=brave/security-action --prnum=406
```
82 changes: 79 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,88 @@
name: 'puLL-Merge'
description: puLL-Merge is a github-action to add LLM capabilities to pull-requests in github automatically
description: 'puLL-Merge is a github-action to add LLM capabilities to pull-requests in github automatically'
inputs:
outputs:
github_token:
description: |
Secret token to push review comments, and
interact with the repository systematically
required: true
openai_api_key:
description: |
API key to interact with the OpenAI endpoint
debug:
description: enables debug output for this action
required: false

# outputs:
runs:
using: 'composite'
steps:
- uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0
with:
node-version: '20.x'
- id: npm
run: npm ci
shell: bash
- id: llm-and-post-message
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
if: ${{ inputs.openai_api_key != '' }}
env:
OPENAI_API_KEY: ${{ inputs.openai_api_key }}
GITHUB_TOKEN: ${{ inputs.github_token }}
with:
script: |
console.log('implement me')
const { default: explainPatch } = await import('${{ github.action_path }}/src/openaiExplainPatch.js')
const watermark = `[puLL-Merge] - ${process.env.GITHUB_REPOSITORY}@${context.issue.number}`
const patchExplained = watermark+"\n\n"+(await explainPatch({
openaiKey: process.env.OPENAI_API_KEY,
github: github,
owner: context.repo.owner,
repo: context.repo.repo,
prnum: context.issue.number }));
const query = `query($owner:String!, $name:String!, $prnumber:Int!) {
repository(owner:$owner, name:$name) {
pullRequest(number:$prnumber) {
comments(last: 100) {
nodes {
id
author { login }
body
bodyHTML
bodyText
}
}
}
}
}`;
const variables = {
owner: context.repo.owner,
name: context.repo.repo,
prnumber: context.issue.number
}
const messages = (await github.graphql(query, variables)).repository.pullRequest.comments.nodes;
const deleteQuery = `mutation DeleteIssueComment($id:ID!) {
deleteIssueComment(input:{id:$id}) {
clientMutationId
}
}`
for (var i = 0; i < messages.length; i++) {
if (messages[i].body.includes(watermark)) {
console.log(messages[i])
await github.graphql(deleteQuery, {id: messages[i].id});
}
}
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: patchExplained
});
Loading

0 comments on commit 30e6710

Please sign in to comment.