Contributing to Grape

Grape is a work of hundreds of contributors. You're encouraged to submit pull requests, propose features, and discuss issues.

Fork the Project

Fork the project on Github and check out your copy.

git clone https://github.com/contributor/grape.git
cd grape
git remote add upstream https://github.com/ruby-grape/grape.git

Create a Topic Branch

Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.

git checkout master
git pull upstream master
git checkout -b my-feature-branch

Development Environment

Using Docker

If you're familiar with Docker, you can run everything through docker-compose. This is the recommended way to set up your development environment as it handles all dependencies.

docker-compose run --rm --build grape <command_and_parameters>
  • The container displays Ruby, Rubygems, and Bundler versions on startup.
  • It keeps gems up-to-date and executes all commands under bundle exec.

Examples:

  • Run all specs: docker-compose run --rm --build grape rspec
  • Run specs for a specific file: docker-compose run --rm --build grape rspec spec/path/to/file_spec.rb
  • Run a Rake task: docker-compose run --rm --build grape rake <task_name>
  • Run RuboCop: docker-compose run --rm --build grape rubocop
  • Run specs on a specific Ruby version: RUBY_VERSION=3.0 docker-compose run --rm --build grape rspec
  • Run specs with a specific Gemfile: docker-compose run -e GEMFILE=rails_7_0 --rm --build grape rspec

Local Setup

If you prefer not to use Docker, you can set up a local environment.

Ensure that you can build the project and run tests:

bundle install
bundle exec rake

The Contribution Process

  1. Write Tests: Add a test that reproduces the problem you're fixing or describes the feature you're building. Tests are located in spec/grape.

  2. Write Code: Implement your feature or bug fix.

  3. Check Style: Ensure your code adheres to the project's style guidelines by running RuboCop.

    bundle exec rubocop

  4. Write Documentation: Document any external-facing changes in the README.md. Use YARD for code comments.

  5. Update Changelog: Add a line to CHANGELOG.md under the "Next" section, including a link to your GitHub account.

  6. Commit Changes: Write a clear and descriptive commit message.

    git add .
    git commit -m "feat: Add a new feature that does X"

  7. Push and Create a Pull Request: Push your branch to your fork and open a pull request against the ruby-grape/grape repository.

Thank you for contributing to Grape! Your efforts are greatly appreciated.