Skip to content

Commit 79f37eb

Browse files
committed
Merge branch 'main' into v2
2 parents 6f6a55f + 80ad25a commit 79f37eb

File tree

8 files changed

+231
-108
lines changed

8 files changed

+231
-108
lines changed

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
[![Discord](https://img.shields.io/badge/join-Discord-blue.svg)](https://discord.gg/nE4UcQHZtV)
44

55

6-
# CODEBALL — AI CODE REVIEW 🔮
6+
# 🔮 Codeball — AI Code Review
77

8-
Codeball is a code review AI which approves Pull Requests that a human would have approved. Spend less time waiting, save time and money.
8+
Codeball is a code review AI that scores Pull Requests on a grade from 0 _(needs careful review)_ to 1 _(you should merge this!)_
99

10-
The AI identifies and approves safe contributions, so that you get to focus your energy on the tricky ones.
10+
Use Codeball to add labels to help you focus, to auto approve PRs, and more. The Codeball action is easy to use (sane defaults), and is highly customizeable to fit your workflow when needed.
1111

12-
* Identifies and **approves** safe contributions
13-
* _[beta]_ Generates **code suggestions** from comments ([read more](https://codeball.ai/suggester))
12+
🏷 Labels PRs when you should **review with caution** – Stay sharp, don't let the bugs pass through!
13+
14+
✅ Identifies and **approves** or labels safe PRs – Save time by fast-tracking PRs that are easy to review
15+
16+
🏖 **Great defaults**, fully customizable and programmable with GitHub Actions
1417

1518
## GitHub Action
1619

@@ -38,11 +41,11 @@ jobs:
3841
- name: Codeball
3942
uses: sturdy-dev/codeball-action@v2
4043
with:
44+
# For all configuration options see https://github.com/sturdy-dev/codeball-action/blob/v2/action.yml
4145
approvePullRequests: "true"
4246
labelPullRequestsWhenApproved: "true"
4347
labelPullRequestsWhenReviewNeeded: "false"
4448
failJobsWhenReviewNeeded: "false"
45-
codeSuggestionsFromComments: "false" # Beta (set to "true" to enable)
4649
```
4750
4851
2. 🎉 That's it! Codeball will now run on new Pull Requests, and will approve the PR if it's a good one!

action.yml

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,37 @@ inputs:
1212
description: 'If "true", the action will submit an approving review if the Codeball AI approves the contribution'
1313
default: "true"
1414
required: false
15+
1516
labelPullRequestsWhenApproved:
16-
description: 'If "true", the action will add `codeball:approved` label to the Pull Request if Codeball AI approves the contribution'
17+
description: 'If "true", the action will add `codeball:approved` label to the PR if the Codeball AI confidence is above the configured approve threshold'
1718
default: "true"
1819
required: false
20+
1921
labelPullRequestsWhenReviewNeeded:
20-
description: 'If "true", the action will add `codeball:needs-review` label to the Pull Request if the Codeball AI approves the contribution'
22+
description: 'If "true", the action will add `codeball:needs-review` label to the PR if the Codeball AI confidence is between the "approve" and "careful" thresholds'
2123
default: "false"
2224
required: false
25+
26+
labelPullRequestsWhenCarefulReviewNeeded:
27+
description: 'If "true", the action will add `codeball:needs-careful-review` label to the PR if the Codeball AI confidence is below the configured careful threshold'
28+
default: "true"
29+
required: false
30+
31+
approveThreshold:
32+
description: 'The threshold to use for "approving" (greater than or equal to). A number between 0 and 1. Must be specified with 3 decimals.'
33+
default: "0.935"
34+
required: false
35+
36+
carefulReviewThreshold:
37+
description: 'The threshold to use for "careful review" actions (less than). A number between 0 and 1. Must be specified with 3 decimals.'
38+
default: "0.300"
39+
required: false
40+
2341
failJobsWhenReviewNeeded:
2442
description: 'If "true", the action will exit with status code 1 if the Codeball AI does not approve the contribution'
2543
default: "false"
2644
required: false
45+
2746
codeSuggestionsFromComments:
2847
description: 'If "true", Codeball will read generate code suggestions from comments made in Pull Requests (beta)'
2948
default: "false"
@@ -46,30 +65,43 @@ runs:
4665
with:
4766
codeball-job-id: ${{ steps.codeball_baller.outputs.codeball-job-id }}
4867

49-
# If Codeball approved the contribution, add a "codeball:approved" label
68+
# If the Codeball confidence is high, add the "codeball:approved" label
5069
- name: Label Approved
5170
uses: sturdy-dev/codeball-action/labeler@v2
52-
if: ${{ steps.codeball_status.outputs.approved == 'true' && inputs.labelPullRequestsWhenApproved == 'true' && steps.codeball_status.outputs.jobType == 'contribution' }}
71+
if: ${{ steps.codeball_status.outputs.jobType == 'contribution' && inputs.labelPullRequestsWhenApproved == 'true' && steps.codeball_status.outputs.confidence >= inputs.approveThreshold }}
5372
with:
5473
name: "codeball:approved"
5574
color: "86efac" # green
56-
remove-label-names: "codeball:needs-review"
75+
remove-label-names: "codeball:needs-review,codeball:needs-careful-review"
5776
codeball-job-id: ${{ steps.codeball_baller.outputs.codeball-job-id }}
5877

59-
# If Codeball did not approve the contribution, add a "codeball:needs-review" label
78+
79+
# If the Codeball confidence is medium, add the "codeball:needs-review" label
6080
- name: Label Needs Review
6181
uses: sturdy-dev/codeball-action/labeler@v2
62-
if: ${{ steps.codeball_status.outputs.approved == 'false' && inputs.labelPullRequestsWhenReviewNeeded == 'true' && steps.codeball_status.outputs.jobType == 'contribution' }}
82+
if: ${{ steps.codeball_status.outputs.jobType == 'contribution' && inputs.labelPullRequestsWhenReviewNeeded == 'true' && steps.codeball_status.outputs.confidence >= inputs.carefulReviewThreshold && steps.codeball_status.outputs.confidence < inputs.approveThreshold }}
6383
with:
6484
name: "codeball:needs-review"
6585
color: "bfdbfe" # blue
66-
remove-label-names: "codeball:approved"
86+
remove-label-names: "codeball:approved,codeball:needs-careful-review"
6787
codeball-job-id: ${{ steps.codeball_baller.outputs.codeball-job-id }}
6888

89+
90+
# If the Codeball confidence is low, add the "codeball:needs-careful-review" label
91+
- name: Label Needs Careful Review
92+
uses: sturdy-dev/codeball-action/labeler@v2
93+
if: ${{ steps.codeball_status.outputs.jobType == 'contribution' && inputs.labelPullRequestsWhenCarefulReviewNeeded == 'true' && steps.codeball_status.outputs.confidence < inputs.carefulReviewThreshold }}
94+
with:
95+
name: "codeball:needs-careful-review"
96+
color: "fde68a" # amber
97+
remove-label-names: "codeball:approved,codeball:needs-review"
98+
codeball-job-id: ${{ steps.codeball_baller.outputs.codeball-job-id }}
99+
100+
69101
# If Codeball approved the contribution, approve the PR
70102
- name: Approve PR
71103
uses: sturdy-dev/codeball-action/approver@v2
72-
if: ${{ steps.codeball_status.outputs.approved == 'true' && inputs.approvePullRequests == 'true' && steps.codeball_status.outputs.jobType == 'contribution' }}
104+
if: ${{ steps.codeball_status.outputs.jobType == 'contribution' && inputs.approvePullRequests == 'true' && steps.codeball_status.outputs.confidence >= inputs.approveThreshold }}
73105
with:
74106
codeball-job-id: ${{ steps.codeball_baller.outputs.codeball-job-id }}
75107

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,23 @@
3131
"@actions/core": "^1.9.1",
3232
"@actions/github": "^5.0.3",
3333
"@octokit/core": "^4.0.5",
34-
"@octokit/plugin-paginate-rest": "^4.1.0",
35-
"@octokit/plugin-rest-endpoint-methods": "^6.3.0",
34+
"@octokit/plugin-paginate-rest": "^4.2.0",
35+
"@octokit/plugin-rest-endpoint-methods": "^6.4.1",
3636
"https-proxy-agent": "^5.0.1",
3737
"node-fetch": "^3.2.10"
3838
},
3939
"devDependencies": {
4040
"@types/jest": "^27.5.1",
4141
"@types/node": "^18.7.14",
42-
"@typescript-eslint/parser": "^5.36.0",
42+
"@typescript-eslint/parser": "^5.36.2",
4343
"@vercel/ncc": "^0.34.0",
44-
"eslint": "^8.16.0",
44+
"eslint": "^8.23.0",
4545
"eslint-plugin-github": "^4.3.7",
4646
"eslint-plugin-jest": "^26.4.0",
4747
"eslint-plugin-prettier": "^4.0.0",
4848
"jest": "^28.1.0",
4949
"js-yaml": "^4.1.0",
50-
"prettier": "^2.6.0",
50+
"prettier": "^2.7.1",
5151
"ts-jest": "^28.0.8",
5252
"typescript": "^4.8.2"
5353
}

src/lib/jobs/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,14 @@ export type Contribution = {
5454
created_at: string
5555
merged_at: any
5656
result: 'inconclusive' | 'approved' | 'not_approved' | null
57+
predicted_outcome?: PredictedOutcome
5758
}
5859

5960
export type Comment = {
6061
url: string
6162
suggestions: Suggestion[]
6263
}
64+
65+
export type PredictedOutcome = {
66+
file_probabilities?: number[]
67+
}

src/status/main.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {
2+
get,
3+
isCommentJob,
24
isContributionJob,
35
isFinalStatus,
4-
get,
5-
required,
66
Job,
7-
isCommentJob
7+
required
88
} from '../lib'
99
import * as core from '@actions/core'
1010
import {track} from '../lib/track'
@@ -29,9 +29,29 @@ const getJobType = (job: Job): string => {
2929
return 'unknown'
3030
}
3131

32+
const getConfidence = (job: Job): number => {
33+
if (isContributionJob(job)) {
34+
const probabilities =
35+
job.contribution?.predicted_outcome?.file_probabilities
36+
37+
if (probabilities) {
38+
return Math.min(...probabilities)
39+
}
40+
41+
return 0
42+
}
43+
44+
return 0
45+
}
46+
3247
const run = async (
3348
jobID: string
34-
): Promise<{isApproved: boolean; isSuggested: boolean; jobType: string}> => {
49+
): Promise<{
50+
isApproved: boolean
51+
isSuggested: boolean
52+
jobType: string
53+
confidence: number
54+
}> => {
3555
core.info(`Job ID: ${jobID}`)
3656

3757
let job = await get(jobID)
@@ -49,18 +69,21 @@ const run = async (
4969
return {
5070
isApproved: isApproved(job),
5171
isSuggested: isSuggested(job),
52-
jobType: getJobType(job)
72+
jobType: getJobType(job),
73+
confidence: getConfidence(job)
5374
}
5475
}
5576

5677
const jobID = required('codeball-job-id')
5778

5879
run(jobID)
59-
.then(async ({isApproved, isSuggested, jobType}) => {
80+
.then(async ({isApproved, isSuggested, jobType, confidence}) => {
6081
await track({jobID, actionName: 'status'})
6182
core.setOutput('approved', isApproved)
6283
core.setOutput('suggested', isSuggested)
6384
core.setOutput('jobType', jobType)
85+
core.setOutput('confidence', confidence.toFixed(3))
86+
core.info(`Confidence: ${confidence.toFixed(3)}`)
6487
})
6588
.catch(async error => {
6689
if (error instanceof Error) {

status/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,20 @@ The ID of the Codeball Job created by the Baller Action
1010

1111
# Outputs
1212

13+
## `jobType`
14+
15+
`"contribution"` or `"comment`
16+
1317
## `approved`
1418

1519
If the Codeball approved the contribution (true or false)
1620

1721
## `suggested`
1822

1923
If the Codeball has suggestions for the contribution (true or false)
24+
25+
## `confidence`
26+
27+
The Codeball confidence that this contribution can be approved as-is. A number between 0 and 1. A value between 0 and 0.3 normally indicates that the contribution should be thoroughly reviewed. A value above 0.93 indicates that the contribution is very likely to be approved as-is.
28+
29+
Confidence is only set for contribution jobs.

status/action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ outputs:
1717
description: 'If the Codeball approved the contribution (true or false)'
1818
suggested:
1919
description: 'If the Codeball has suggestions for the contribution (true or false)'
20+
confidence:
21+
description: 'The Codeball confidence that this contribution can be approved as-is. A number between 0 and 1. A value between 0 and 0.3 normally indicates that the contribution should be thoroughly reviewed. A value above 0.93 indicates that the contribution is very likely to be approved as-is. Confidence is only set for contribution jobs.'
2022

2123
runs:
2224
using: 'node16'

0 commit comments

Comments
 (0)