Skip to content
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
170 changes: 162 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,172 @@ on: [pull_request]
jobs:
codeball_job:
runs-on: ubuntu-latest
name: Run Codeball
name: Codeball
steps:
- name: Codeball AI Actions
uses: sturdy-dev/codeball-action@v1
# with:
# do-label: "true" # Configure if the action should label approved contributions
# label-name: "codeball:approved" # Configure the label name to set if Codeball approves the contribution
# do-approve: "true" # Configure if the action should approve PRs that have been approved by Codeball
- name: Codeball
uses: sturdy-dev/codeball-action@v2
```

2. 🎉 That's it! Codeball will now run on your pull requests, and will pre-approve your PR if it's a good one!

## Customizations

Codeball Actions are built on multiple smaller building-blocks, that are heavily configurable through GitHub Actions.

### Example: "Dry-run" mode, labels all PRs with the Codeball Result

<details>
<summary>codeball-dry-run.yml</summary>

```yaml
on: [pull_request]

permissions:
contents: read
issues: write
pull-requests: write

jobs:
codeball:
runs-on: ubuntu-latest
name: Codeball
steps:

# Start a new Codeball review job
# This step is asynchronous and will return a job id
- name: Trigger Codeball
id: codeball_baller
uses: sturdy-dev/codeball-action/baller@v2


# Wait for Codeball to return the status
- name: Get Status
id: codeball_status
uses: sturdy-dev/codeball-action/status@v2
with:
codeball-job-id: ${{ steps.codeball_baller.outputs.codeball-job-id }}

# If Codeball approved the contribution, add a "codeball:approved" label
- name: Label Approved
uses: sturdy-dev/codeball-action/labeler@v2
if: ${{ steps.codeball_status.outputs.approved == 'true' }}
with:
name: "codeball:approved"
color: "86efac" # green

# If Codeball did not approve the contribution, add a "codeball:needs-review" label
- name: Label Needs Review
uses: sturdy-dev/codeball-action/labeler@v2
if: ${{ steps.codeball_status.outputs.approved == 'false' }}
with:
name: "codeball:needs-review"
color: "bfdbfe" # blue

```
</details>

### Example: Approve only (no labels)

<details>
<summary>codeball-approve.yml</summary>

```yaml
on: [pull_request]

permissions:
contents: read
issues: write
pull-requests: write

jobs:
codeball:
runs-on: ubuntu-latest
name: Codeball
steps:

# Start a new Codeball review job
# This step is asynchronous and will return a job id
- name: Trigger Codeball
id: codeball_baller
uses: sturdy-dev/codeball-action/baller@v2


# Wait for Codeball to return the status
- name: Get Status
id: codeball_status
uses: sturdy-dev/codeball-action/status@v2
with:
codeball-job-id: ${{ steps.codeball_baller.outputs.codeball-job-id }}

# If Codeball approved the contribution, approve the PR
- name: Approve PR
uses: sturdy-dev/codeball-action/approver@v2
if: ${{ steps.codeball_status.outputs.approved == 'true' }}
with:
message: "Codeball: LGTM! :+1:"
```
</details>


### Example: Filter files (run only for PRs modifying a single service)

<details>
<summary>codeball-filter-files.yml</summary>

```yaml
on:
pull_request:
# Run Codeball only if files under "/web/" has been modified (and no other files)
# See: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-including-and-excluding-paths
paths:
- '!**'
- '/web/**'

permissions:
contents: read
issues: write
pull-requests: write

jobs:
codeball:
runs-on: ubuntu-latest
name: Codeball

steps:

# Start a new Codeball review job
# This step is asynchronous and will return a job id
- name: Trigger Codeball
id: codeball_baller
uses: sturdy-dev/codeball-action/baller@v2


# Wait for Codeball to return the status
- name: Get Status
id: codeball_status
uses: sturdy-dev/codeball-action/status@v2
with:
codeball-job-id: ${{ steps.codeball_baller.outputs.codeball-job-id }}

# If Codeball approved the contribution, approve the PR
- name: Approve PR
uses: sturdy-dev/codeball-action/approver@v2
if: ${{ steps.codeball_status.outputs.approved == 'true' }}
with:
message: "Codeball: LGTM! :+1:"
```
</details>


## Building Blocks

The Codeball sub-actions are:

* [`sturdy-dev/codeball-action/baller/@v2`](./baller/README.md) – Triggers new Codeball Jobs
* [`sturdy-dev/codeball-action/status/@v2`](./status/README.md) – Waits for the the Codeball result
* [`sturdy-dev/codeball-action/approver/@v2`](./approver/README.md) – Approves PRs
* [`sturdy-dev/codeball-action/labeler/@v2`](./labeler/README.md) – Adds labels to PRs

## Troubleshooting

### Permissions
Expand All @@ -51,4 +205,4 @@ permissions:

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.

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)).
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)).
44 changes: 20 additions & 24 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,38 @@
# See https://github.com/sturdy-dev/codeball-action for more information of how to use this action
name: Codeball AI Actions
description: AI Code Review
description: AI Code Review – Codeball approves Pull Requests that a human would have approved. Wait less for review, save time and $$$.

author: Sturdy
branding:
icon: check
color: orange

inputs:
do-label:
description: 'If "true", the action will label Pull Request if Codeball AI approves the contribution'
default: "true"
required: false
label-name:
description: 'Label value to be set.'
default: 'codeball:approved'
required: false
do-approve:
description: 'If "true", the action will submit an approving Pull Request review if Codeball AI approves the contribution'
default: "true"
required: false

runs:
using: 'composite'
steps:

# Start a new Codeball review job
# This step is asynchronous and will return a job id
- name: Trigger Codeball
id: codeball_baller
uses: sturdy-dev/codeball-action/baller@v1
uses: sturdy-dev/codeball-action/baller@v2

# Wait for the codeball_baller job to complete
# Approves the Pull Request if Codeball approves it
- name: Codeball Approver
id: codeball_approver
uses: sturdy-dev/codeball-action/approver@v1
# Wait for Codeball to return the status
- name: Get Status
id: codeball_status
uses: sturdy-dev/codeball-action/status@v2
with:
codeball-job-id: ${{ steps.codeball_baller.outputs.codeball-job-id }}
do-label: ${{ inputs.do-label }}
label-name: ${{ inputs.label-name }}
do-approve: ${{ inputs.do-approve }}

# If Codeball approved the contribution, add a "codeball:approved" label
- name: Label Approved
uses: sturdy-dev/codeball-action/labeler@v2
if: ${{ steps.codeball_status.outputs.approved == 'true' }}
with:
name: "codeball:approved"
color: "86efac" # green

# If Codeball approved the contribution, approve the PR
- name: Approve PR
uses: sturdy-dev/codeball-action/approver@v2
if: ${{ steps.codeball_status.outputs.approved == 'true' }}
21 changes: 21 additions & 0 deletions approver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Codeball Approver

This action approves a Pull Request with a message.

# Inputs

## `GITHUB_TOKEN` (optional)

Default to {{ github.token }}. This is the default GitHub token available to actions and is used to run Codeball and to post the result. The default token permissions (https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#permissions) work fine.

Default: `'${{ github.token }}'`

## `message` (optional)

The message to send in the code review comment.

Default: `"Codeball: LGTM! :+1:"`

# Outputs

_This action has no outputs_
17 changes: 17 additions & 0 deletions baller/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Codeball Baller

This action starts a new asynchronous Codeball Job.

# Inputs

## `GITHUB_TOKEN` (optional)

Default to {{ github.token }}. This is the default GitHub token available to actions and is used to run Codeball and to post the result. The default token permissions (https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#permissions) work fine.

Default: `'${{ github.token }}'`

# Outputs

## `codeball-job-id`

ID of the Codeball Job
33 changes: 33 additions & 0 deletions examples/codeball-approve.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
on: [pull_request]

permissions:
contents: read
issues: write
pull-requests: write

jobs:
codeball:
runs-on: ubuntu-latest
name: Codeball
steps:

# Start a new Codeball review job
# This step is asynchronous and will return a job id
- name: Trigger Codeball
id: codeball_baller
uses: sturdy-dev/codeball-action/baller@v2


# Wait for Codeball to return the status
- name: Get Status
id: codeball_status
uses: sturdy-dev/codeball-action/status@v2
with:
codeball-job-id: ${{ steps.codeball_baller.outputs.codeball-job-id }}

# If Codeball approved the contribution, approve the PR
- name: Approve PR
uses: sturdy-dev/codeball-action/approver@v2
if: ${{ steps.codeball_status.outputs.approved == 'true' }}
with:
message: "Codeball: LGTM! :+1:"
42 changes: 42 additions & 0 deletions examples/codeball-dry-run.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
on: [pull_request]

permissions:
contents: read
issues: write
pull-requests: write

jobs:
codeball:
runs-on: ubuntu-latest
name: Codeball
steps:

# Start a new Codeball review job
# This step is asynchronous and will return a job id
- name: Trigger Codeball
id: codeball_baller
uses: sturdy-dev/codeball-action/baller@v2


# Wait for Codeball to return the status
- name: Get Status
id: codeball_status
uses: sturdy-dev/codeball-action/status@v2
with:
codeball-job-id: ${{ steps.codeball_baller.outputs.codeball-job-id }}

# If Codeball approved the contribution, add a "codeball:approved" label
- name: Label Approved
uses: sturdy-dev/codeball-action/labeler@v2
if: ${{ steps.codeball_status.outputs.approved == 'true' }}
with:
name: "codeball:approved"
color: "86efac" # green

# If Codeball did not approve the contribution, add a "codeball:needs-review" label
- name: Label Needs Review
uses: sturdy-dev/codeball-action/labeler@v2
if: ${{ steps.codeball_status.outputs.approved == 'false' }}
with:
name: "codeball:needs-review"
color: "bfdbfe" # blue
Loading