Skip to content

Commit 4920302

Browse files
author
Kiril Videlov
committed
Merge branch 'main' into v2
2 parents 59d6a8c + 41f8f2e commit 4920302

File tree

5 files changed

+90
-130
lines changed

5 files changed

+90
-130
lines changed

README.md

Lines changed: 43 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
![github_bg](https://user-images.githubusercontent.com/47952/170700847-bb0cac65-f269-4758-955a-632c48f47290.png)
1+
![Codeball](https://user-images.githubusercontent.com/47952/173048697-d3d39fc3-6238-4fc3-9baf-ccbbb3b4258c.png)
22

3-
Test :-)
43

54
# CODEBALL — AI CODE REVIEW 🔮
65

@@ -30,63 +29,42 @@ jobs:
3029
steps:
3130
- name: Codeball
3231
uses: sturdy-dev/codeball-action@v2
32+
with:
33+
approvePullRequests: "true"
34+
labelPullRequestsWhenApproved: "true"
35+
labelPullRequestsWhenReviewNeeded: "false"
36+
failJobsWhenReviewNeeded: "false"
3337
```
3438
3539
2. 🎉 That's it! Codeball will now run on new Pull Requests, and will approve the PR if it's a good one!
3640
3741
## Customizations
3842
39-
Codeball Actions are built on multiple smaller building-blocks, that are heavily configurable through GitHub Actions.
43+
Codeball Actions are built on multiple smaller building-blocks, that are heavily configurable through GitHub Actions. Here's a few examples:
44+
45+
_If you're using Codeball in another way, please let us know in an issue!_
4046
4147
### Example: "Dry-run" mode, labels all PRs with the Codeball Result
4248
4349
<details>
4450
<summary>▶️ codeball-dry-run.yml</summary>
4551
4652
```yaml
53+
name: Codeball
4754
on: [pull_request]
4855

49-
permissions:
50-
contents: read
51-
issues: write
52-
pull-requests: write
53-
5456
jobs:
55-
codeball:
57+
codeball_job:
5658
runs-on: ubuntu-latest
5759
name: Codeball
5860
steps:
59-
60-
# Start a new Codeball review job
61-
# This step is asynchronous and will return a job id
62-
- name: Trigger Codeball
63-
id: codeball_baller
64-
uses: sturdy-dev/codeball-action/baller@v2
65-
66-
67-
# Wait for Codeball to return the status
68-
- name: Get Status
69-
id: codeball_status
70-
uses: sturdy-dev/codeball-action/status@v2
71-
with:
72-
codeball-job-id: ${{ steps.codeball_baller.outputs.codeball-job-id }}
73-
74-
# If Codeball approved the contribution, add a "codeball:approved" label
75-
- name: Label Approved
76-
uses: sturdy-dev/codeball-action/labeler@v2
77-
if: ${{ steps.codeball_status.outputs.approved == 'true' }}
78-
with:
79-
name: "codeball:approved"
80-
color: "86efac" # green
81-
82-
# If Codeball did not approve the contribution, add a "codeball:needs-review" label
83-
- name: Label Needs Review
84-
uses: sturdy-dev/codeball-action/labeler@v2
85-
if: ${{ steps.codeball_status.outputs.approved == 'false' }}
61+
- name: Codeball
62+
uses: sturdy-dev/codeball-action@v2
8663
with:
87-
name: "codeball:needs-review"
88-
color: "bfdbfe" # blue
89-
64+
approvePullRequests: "false"
65+
labelPullRequestsWhenApproved: "true"
66+
labelPullRequestsWhenReviewNeeded: "true"
67+
failJobsWhenReviewNeeded: "false"
9068
```
9169
</details>
9270
@@ -96,39 +74,21 @@ jobs:
9674
<summary>▶️ codeball-approve.yml</summary>
9775
9876
```yaml
77+
name: Codeball
9978
on: [pull_request]
10079

101-
permissions:
102-
contents: read
103-
issues: write
104-
pull-requests: write
105-
10680
jobs:
107-
codeball:
81+
codeball_job:
10882
runs-on: ubuntu-latest
10983
name: Codeball
11084
steps:
111-
112-
# Start a new Codeball review job
113-
# This step is asynchronous and will return a job id
114-
- name: Trigger Codeball
115-
id: codeball_baller
116-
uses: sturdy-dev/codeball-action/baller@v2
117-
118-
119-
# Wait for Codeball to return the status
120-
- name: Get Status
121-
id: codeball_status
122-
uses: sturdy-dev/codeball-action/status@v2
123-
with:
124-
codeball-job-id: ${{ steps.codeball_baller.outputs.codeball-job-id }}
125-
126-
# If Codeball approved the contribution, approve the PR
127-
- name: Approve PR
128-
uses: sturdy-dev/codeball-action/approver@v2
129-
if: ${{ steps.codeball_status.outputs.approved == 'true' }}
85+
- name: Codeball
86+
uses: sturdy-dev/codeball-action@v2
13087
with:
131-
message: "Codeball: LGTM! :+1:"
88+
approvePullRequests: "true"
89+
labelPullRequestsWhenApproved: "false"
90+
labelPullRequestsWhenReviewNeeded: "false"
91+
failJobsWhenReviewNeeded: "false"
13292
```
13393
</details>
13494
@@ -139,6 +99,7 @@ jobs:
13999
<summary>▶️ codeball-filter-files.yml</summary>
140100
141101
```yaml
102+
name: Codeball
142103
on:
143104
pull_request:
144105
# Run Codeball only if files under "/web/" has been modified (and no other files)
@@ -147,86 +108,43 @@ on:
147108
- '!**'
148109
- '/web/**'
149110

150-
permissions:
151-
contents: read
152-
issues: write
153-
pull-requests: write
154-
155111
jobs:
156-
codeball:
112+
codeball_job:
157113
runs-on: ubuntu-latest
158114
name: Codeball
159-
160115
steps:
161-
162-
# Start a new Codeball review job
163-
# This step is asynchronous and will return a job id
164-
- name: Trigger Codeball
165-
id: codeball_baller
166-
uses: sturdy-dev/codeball-action/baller@v2
167-
168-
169-
# Wait for Codeball to return the status
170-
- name: Get Status
171-
id: codeball_status
172-
uses: sturdy-dev/codeball-action/status@v2
173-
with:
174-
codeball-job-id: ${{ steps.codeball_baller.outputs.codeball-job-id }}
175-
176-
# If Codeball approved the contribution, approve the PR
177-
- name: Approve PR
178-
uses: sturdy-dev/codeball-action/approver@v2
179-
if: ${{ steps.codeball_status.outputs.approved == 'true' }}
116+
- name: Codeball
117+
uses: sturdy-dev/codeball-action@v2
180118
with:
181-
message: "Codeball: LGTM! :+1:"
119+
approvePullRequests: "true"
120+
labelPullRequestsWhenApproved: "true"
121+
labelPullRequestsWhenReviewNeeded: "false"
122+
failJobsWhenReviewNeeded: "false"
182123
```
183124
</details>
184125
185126
186-
### Example:
127+
### Example: Fail the Codeball Action (❌) if Codeball does not approve the contribution
187128
188129
<details>
189130
<summary>▶️ codeball-fail-not-approved.yml</summary>
190131
191132
```yaml
133+
name: Codeball
192134
on: [pull_request]
193135

194-
permissions:
195-
contents: read
196-
issues: write
197-
pull-requests: write
198-
199136
jobs:
200-
codeball:
137+
codeball_job:
201138
runs-on: ubuntu-latest
202139
name: Codeball
203140
steps:
204-
# Start a new Codeball review job
205-
# This step is asynchronous and will return a job id
206-
- name: Trigger Codeball
207-
id: codeball_baller
208-
uses: sturdy-dev/codeball-action/baller@v2
209-
210-
# Wait for Codeball to return the status
211-
- name: Get Status
212-
id: codeball_status
213-
uses: sturdy-dev/codeball-action/status@v2
214-
with:
215-
codeball-job-id: ${{ steps.codeball_baller.outputs.codeball-job-id }}
216-
217-
# If Codeball approved the contribution, approve the PR
218-
- name: Approve PR
219-
uses: sturdy-dev/codeball-action/approver@v2
220-
if: ${{ steps.codeball_status.outputs.approved == 'true' }}
141+
- name: Codeball
142+
uses: sturdy-dev/codeball-action@v2
221143
with:
222-
message: 'Codeball: LGTM! :+1:'
223-
224-
# If Codeball didn't approve the contribution, fail the job.
225-
- name: Fail Job
226-
if: ${{ steps.codeball_status.outputs.approved == 'fail' }}
227-
run: |
228-
echo "Not approved"
229-
exit 1
144+
approvePullRequests: "true"
145+
labelPullRequestsWhenApproved: "true"
146+
labelPullRequestsWhenReviewNeeded: "false"
147+
failJobsWhenReviewNeeded: "true"
230148
```
231149
</details>
232150
@@ -268,6 +186,6 @@ permissions:
268186

269187
### Forks and private repositories
270188

271-
By default, only pull requests from a fork does not have "write" permissions when running in GitHub Actions, and those Pull Requests can not be approved.
189+
By default, pull requests from a fork does not have "write" permissions when running in GitHub Actions, and those Pull Requests can not be approved or labeled.
272190

273191
If you're using forks from a private repository, and want to use Codeball on Pull Requests created from a fork. Enable "Send write tokens to workflows from fork pull requests" on the repository ([docs](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository#enabling-workflows-for-private-repository-forks)).

action.yml

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ branding:
77
icon: check
88
color: orange
99

10+
inputs:
11+
approvePullRequests:
12+
description: 'If "true", the action will submit an approving review if the Codeball AI approves the contribution'
13+
default: "true"
14+
required: false
15+
labelPullRequestsWhenApproved:
16+
description: 'If "true", the action will add `codeball:approved` label to the Pull Request if Codeball AI approves the contribution'
17+
default: "true"
18+
required: false
19+
labelPullRequestsWhenReviewNeeded:
20+
description: 'If "true", the action will add `codeball:needs-review` label to the Pull Request if the Codeball AI approves the contribution'
21+
default: "false"
22+
required: false
23+
failJobsWhenReviewNeeded:
24+
description: 'If "true", the action will exit with status code 1 if the Codeball AI does not approve the contribution'
25+
default: "false"
26+
required: false
27+
1028
runs:
1129
using: 'composite'
1230
steps:
@@ -31,11 +49,27 @@ runs:
3149
with:
3250
name: "codeball:approved"
3351
color: "86efac" # green
34-
codeball-job-id: ${{ steps.codeball_baller.outputs.codeball-job-id }}
52+
codeball-job-id: ${{ steps.codeball_baller.outputs.codeball-job-id && inputs.labelPullRequestsWhenApproved == 'true' }}
53+
54+
# If Codeball did not approve the contribution, add a "codeball:needs-review" label
55+
- name: Label Needs Review
56+
uses: sturdy-dev/codeball-action/labeler@v2
57+
if: ${{ steps.codeball_status.outputs.approved == 'false' && inputs.labelPullRequestsWhenReviewNeeded == 'true' }}
58+
with:
59+
name: "codeball:needs-review"
60+
color: "bfdbfe" # blue
3561

3662
# If Codeball approved the contribution, approve the PR
3763
- name: Approve PR
3864
uses: sturdy-dev/codeball-action/approver@v2
39-
if: ${{ steps.codeball_status.outputs.approved == 'true' }}
65+
if: ${{ steps.codeball_status.outputs.approved == 'true' && inputs.approvePullRequests == 'true' }}
4066
with:
4167
codeball-job-id: ${{ steps.codeball_baller.outputs.codeball-job-id }}
68+
69+
# If Codeball didn't approve the contribution, fail the job.
70+
- name: Fail Job
71+
shell: bash
72+
if: ${{ steps.codeball_status.outputs.approved == 'false' && inputs.failJobsWhenReviewNeeded == 'true' }}
73+
run: |
74+
echo "Not approved"
75+
exit 1

hack/run-e2e-tests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ yarn build
99

1010
act pull_request -e tests/act-pull-request.json \
1111
-s GITHUB_TOKEN=${GITHUB_TOKEN} \
12-
--env CODEBALL_API_HOST=http://host.docker.internal:8080
12+
--env CODEBALL_API_HOST=http://host.docker.internal:8080 \
13+
--env GITHUB_STEP_SUMMARY=/dev/null

src/approver/main.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,18 @@ async function run(): Promise<void> {
2222
if (!repoName) throw new Error('No repo name found')
2323

2424
const githubToken = required('GITHUB_TOKEN')
25+
const message = required('message')
2526

2627
const octokit = new Octokit({auth: githubToken})
2728

29+
const dashboardLink = '[dashboard](https://codeball.ai/' + process.env.GITHUB_REPOSITORY + ')'
30+
2831
await octokit.pulls.createReview({
2932
owner: repoOwner,
3033
repo: repoName,
3134
pull_number: pullRequestNumber,
3235
commit_id: commitId,
33-
body: 'Codeball: LGTM! :+1:',
36+
body: message + ' (' + dashboardLink + ')',
3437
event: 'APPROVE'
3538
})
3639
}

src/baller/main.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ async function run(): Promise<{jobId: string}> {
2424
run()
2525
.then(async ({jobId}) => {
2626
await track({jobID: jobId, actionName: 'baller'})
27-
core.setOutput('codeball-job-id', jobId)
27+
await core.setOutput('codeball-job-id', jobId)
28+
29+
core.summary
30+
.addLink('Codeball Dashboard for ' + process.env.GITHUB_REPOSITORY, 'https://codeball.ai/' + process.env.GITHUB_REPOSITORY)
31+
.write()
2832
})
2933
.catch(async error => {
3034
await track({actionName: 'baller', error: error.message})

0 commit comments

Comments
 (0)