Have you heard about Goose AI Developer Agent before? I will explore what is all about as a GitHub Action, particularly. This post explores Goose as a GitHub Action. Without further ado, let’s dive in.
Goose 🦢 is a developer agent that operates from your command line to help you do the boring stuff.
The Goose AI Developer Agent offers powerful assistance by leveraging AI to automate various coding and review tasks, making it easier to manage pull requests, write tests, improve code quality, and more. By incorporating Goose AI as a GitHub Action, developers can streamline repetitive tasks and improve the overall workflow efficiency.
This post provides an overview of setting up Goose AI in your GitHub Actions workflow, explores configuration options, and offers best practices and real-world use cases for maximum productivity.
How it works
A github action to run to take on tasks in the background for you using AI. You can label an issue with goose and it will open a pull request to fix it. You can say help me @goose-ci – can you clean up the mess in a pull request comment on any pull request, and goose will try to assist and fix up your PR.
Setting up the Goose GitHub Action
To start using Goose AI, you’ll need to create a workflow file. Place this file in .github/workflows directory, such as .github/workflows/goose-ai.yml.
Installation: Copy and paste the following snippet into your .yml file.
uses: michaelneale/goose-fix-it-action@v18
Steps: Go to Goose AI Developer Agent marketplace and click on use latest version. Once you click on it, you’ll see the .yml script to add in your .workflows/goose-ai.yml for an example file.
Learn more
Configuration options
In your .github workflows, make a new workflow for goose:
# trigger when there is a labelled issue, or a comment
on:
issues:
types:
– labeled
issue_comment:
types:
– created
jobs:
ask-goose:
# this will run when an issue is labelled ‘goose’ or if a comment in a pull request asks for help from @goose-ai
if: github.event.label.name == ‘goose’ or ${{ github.event.issue.pull_request && contains(github.event.comment.body, ‘@goose-ai’) }}
runs-on: ubuntu-latest
steps:
– name: Checkout repo
uses: actions/checkout@v2
with:
fetch-depth: 0
## Install whatever you need here as per your CI setup for your project
– name: Run Goose Action
uses: michaelneale/goose-fix-it-action@main
with:
task_request: |
${{ github.event.issue.title }}
${{ github.event.issue.body }}
[Link to issue](${{ github.event.issue.html_url }})
validation: “check the vite web app installs”
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
GH_TOKEN: ${{ github.token }} # can change this to secrets.PAT if you want to trigger workflows
This example will both open pull requests IF it can come up with a validated change. It will also trigger if you mention @goose-ai in a pull request (could be one someone else opened, or goose opened), in that case, it will try to address the feedback and push the change back to the pull request. If you say @goose-ai rollback it will undo the last change it made.
The validation is what goose will use to check its changes – it can be any directions on how to verify/test . The task_request is an instruction on what to do.
Real-world automation examples
Here are some real-world scenarios where Goose AI as a GitHub Action can add significant value:
Automated Code Review on Pull Requests
Configure Goose AI to provide code review comments on pull requests. This can help identify common issues, improve code quality, and enforce coding standards without requiring a human reviewer for every PR.
Test Generation for New Features
When new files are added or existing ones are updated, Goose AI can generate test cases, ensuring the code is adequately covered. This can be particularly useful for ensuring unit tests are created consistently.
Refactoring Suggestions
Integrate Goose AI into CI/CD workflows to suggest refactorings, improving maintainability over time. This is beneficial for codebases that require continuous quality improvements.
name: Comprehensive Code Review
on:
pull_request:
types: [opened, synchronize]
jobs:
review:
runs-on: ubuntu-latest
steps:
– uses: actions/checkout@v2
– name: Goose AI Review
uses: goose-ai/goose-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
openai_api_key: ${{ secrets.OPENAI_API_KEY }}
review_comments: true
summarize: true
suggest_improvements: true
Best practices
To get the most out of Goose AI, consider these best practices:
Limit Scope to Relevant Files: Use the paths configuration to limit Goose AI to specific types of files. For instance, if you only want to review Python files, use **/*.py as the path pattern.
Store API Keys Securely: Always store sensitive data, like your GOOSE_API_KEY, in GitHub Secrets to keep your credentials safe.
Integrate with Other Linting and Testing Tools: Combine Goose AI with other GitHub Actions like linters and test runners. This creates a comprehensive CI/CD workflow that covers multiple aspects of code quality.
Use Environment-Specific Settings: If running Goose AI in multiple environments (like dev, staging, and production), configure each environment separately to avoid redundant or conflicting feedback.
Integration with workflows
Goose AI can be seamlessly integrated into complex CI/CD workflows. Here’s an example where Goose AI is integrated alongside testing and deployment jobs:
on:
push:
branches:
– main
pull_request:
paths:
– ‘**/*.js’
jobs:
lint:
runs-on: ubuntu-latest
steps:
– name: Checkout code
uses: actions/checkout@v2
– name: Run Linter
run: npm run lint
test:
runs-on: ubuntu-latest
steps:
– name: Run Tests
run: npm test
goose:
needs: test
runs-on: ubuntu-latest
steps:
– name: Checkout code
uses: actions/checkout@v2
– name: Run Goose AI Developer Agent
uses: gooseai/github-action-goose@v1
env:
GOOSE_API_KEY: ${{ secrets.GOOSE_API_KEY }}
GOOSE_TASK: “generate_tests”
FILES: “src/**/*.js”
deploy:
needs: goose
runs-on: ubuntu-latest
steps:
– name: Deploy Application
run: ./deploy.sh
In this setup:
Linting: Runs a linter on the codebase.
Testing: Runs tests to verify code correctness.
Goose AI: Once tests pass, Goose AI generates additional tests for any new code.
Deploy: The final deployment step only runs if all previous steps succeed.
Conclusion
Goose AI Developer Agent transforms the code review process by bringing AI-powered insights directly into your GitHub workflows. By following this guide and best practices, teams can leverage Goose to improve code quality, enhance developer productivity, and maintain high standards across their projects.
Remember to regularly update your Goose configuration as your team’s needs evolve and new features become available. The AI-powered insights can be invaluable for maintaining code quality and fostering better development practices across your team.
Join the Discord channel.