Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/rationalize tests #119

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: loop
name: loop anthropic
on:
pull_request:
permissions:
Expand All @@ -23,8 +23,6 @@ jobs:
with:
debug: true
github_token: ${{ secrets.GITHUB_TOKEN }}
openai_api_key: ${{ secrets.OPENAI_API_KEY }}
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
bedrock_aws_iam_role_arn: ${{ secrets.SECURITY_BEDROCK_AWS_IAM_ROLE_ARN }}
region: us-west-2
amplification: 0 # always trigger the action
28 changes: 28 additions & 0 deletions .github/workflows/loop-bedrock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: loop bedrock
on:
pull_request:
permissions:
contents: read
id-token: write
pull-requests: write
jobs:
loop:
name: loop
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
fetch-depth: 0
- run: |
pwd
tree -a
shell: bash
- uses: ./
with:
debug: true
github_token: ${{ secrets.GITHUB_TOKEN }}
bedrock_aws_iam_role_arn: ${{ secrets.TEST_SECURITY_BEDROCK_AWS_IAM_ROLE_ARN }}
region: us-west-2
amplification: 0 # always trigger the action
28 changes: 28 additions & 0 deletions .github/workflows/loop-openai.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: loop openai
on:
pull_request:
permissions:
contents: read
id-token: write
pull-requests: write
jobs:
loop:
name: loop
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
fetch-depth: 0
- run: |
pwd
tree -a
shell: bash
- uses: ./
with:
debug: true
github_token: ${{ secrets.GITHUB_TOKEN }}
openai_api_key: ${{ secrets.OPENAI_API_KEY }}
region: us-west-2
amplification: 0 # always trigger the action
60 changes: 25 additions & 35 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ runs:
with:
script: |
const { default: filterdiff } = await import('${{ github.action_path }}/src/filterdiff.js')
const { default: getPatch } = await import('${{ github.action_path }}/src/getPatch.js')
const { default: getRenovatePatch } = await import('${{ github.action_path }}/src/getRenovatePatch.js')
const { default: getDependabotPatch } = await import('${{ github.action_path }}/src/getDependabotPatch.js')
const { default: getConfig } = await import('${{ github.action_path }}/src/getConfig.js')
const { default: getProperties } = await import('${{ github.action_path }}/src/getProperties.js')

Expand Down Expand Up @@ -136,6 +133,12 @@ runs:
? await import('${{ github.action_path }}/src/subtleSubmitReview.js')
: await import('${{ github.action_path }}/src/submitReview.js')

const { default: getPatch } = (context.payload.pull_request && context.payload.pull_request.user.login === 'renovate[bot]') || context.actor === 'renovate[bot]'
? await import('${{ github.action_path }}/src/getRenovatePatch.js')
: (context.payload.pull_request && context.payload.pull_request.user.login === 'dependabot[bot]') || context.actor === 'dependabot[bot]'
? await import('${{ github.action_path }}/src/getDependabotPatch.js')
: await import('${{ github.action_path }}/src/getPatch.js')

options.key = options.anthropic_api_key || options.openai_api_key
options.models = options.bedrock_aws_iam_role_arn
? options.bedrock_models
Expand All @@ -152,38 +155,15 @@ runs:
console.log(`Using inputs: ${JSON.stringify(inputs)}`)
}

let patch = null

try {
// if the PR is a renovate PR, we need to get the patch from the renovate API
// check if the PR actor is renovate[bot]

if ((context.payload.pull_request && context.payload.pull_request.user.login === 'renovate[bot]') || context.actor === 'renovate[bot]') {
patch = await getRenovatePatch({
owner: options.owner,
repo: options.repo,
prnum: options.prnum,
debug,
github
})
} else if ((context.payload.pull_request && context.payload.pull_request.user.login === 'dependabot[bot]') || context.actor === 'dependabot[bot]') {
patch = await getDependabotPatch({
owner: options.owner,
repo: options.repo,
prnum: options.prnum,
debug,
github
})
} else {
patch = await getPatch({
owner: options.owner,
repo: options.repo,
prnum: options.prnum,
debug,
runIfPrivate: options.run_if_private,
github
})
}
const patch = await getPatch({
owner: options.owner,
repo: options.repo,
prnum: options.prnum,
debug,
runIfPrivate: options.run_if_private,
github
})

const filteredPatch = await filterdiff({
content: patch.body,
Expand All @@ -203,11 +183,21 @@ runs:
region: options.region
})

let watermark = patch.watermark

if (debug) {
watermark = options.bedrock_aws_iam_role_arn
? `bedrock debug - ${watermark}`
: options.anthropic_api_key
diracdeltas marked this conversation as resolved.
Show resolved Hide resolved
? `anthropic debug - ${watermark}`
: `openai debug - ${watermark}`
}

await submitReview({
owner: options.owner,
repo: options.repo,
prnum: options.prnum,
watermark: patch.watermark,
watermark,
explainPatch: explainPatchCb,
debounceTime: options.debounce_time,
debug,
Expand Down
1 change: 1 addition & 0 deletions src/getDependabotPatch.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// runIfPrivate always ignored since renovate patches are always public
export default async function getDependabotPatch ({
owner, repo, prnum,
githubToken = null,
Expand Down
1 change: 1 addition & 0 deletions src/getRenovatePatch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { markdownToTxt } from 'markdown-to-txt'

// runIfPrivate always ignored since renovate patches are always public
export default async function getRenovatePatch ({
owner, repo, prnum,
githubToken = null,
Expand Down