Skip to content

Commit e320911

Browse files
committed
Improve README, API, contributing, and usage docs
1 parent 5bb2e12 commit e320911

4 files changed

Lines changed: 355 additions & 12 deletions

File tree

CONTRIBUTING.md

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
# Contributing
2+
3+
Thanks for thinking about helping! How would you like to help?
4+
5+
- [I want to build a new feature.](#how-to-tackle-a-new-feature)
6+
- [I want to improve the documentation.](#what-kind-of-documentation-are-you-writing)
7+
- [I want to fix a bug.](#how-to-fix-a-bug)
8+
- [I want to refactor some code.](#how-to-refactor-code)
9+
- [I don't know how to help.](#what-if-i-dont-know-how-to-help)
10+
11+
## Before you get started
12+
13+
1. [Fork the repo](https://help.github.com/articles/fork-a-repo/).
14+
15+
2. Read and work through [the installation guide](docs/INSTALLING.md).
16+
17+
3. Run the tests. We only take pull requests with passing tests, and it's great to know that you have a clean slate: `docker-compose run mix test`
18+
19+
Okay, you're ready to go!
20+
21+
## How to tackle a new feature
22+
23+
If there's already an issue for the feature you want to tackle, how complete is the description? Do you know what to do next? Are you confident you know what "done" looks like?
24+
25+
If there's not an issue yet, write one.
26+
27+
Whether you're writing a new issue or improving on an existing issue, be sure to clarify exactly how you expect the finished change to look and work.
28+
29+
One of the best ways to write a feature is in user story format:
30+
31+
> As an [actor], I want to do [action], so that [benefit].
32+
33+
For example, let's say we wanted to write some Slack integration for new comments posted to a Code Corps project. That user story might look something like:
34+
35+
> As a project maintainer, I want to see new comments on my project post in my Slack channel so that everyone can see and react to some of the latest changes in the project.
36+
37+
You may want to go deeper into detail. Posting screenshots of designs or expected test cases and scenarios are even more helpful. Place yourself in the shoes of the person who's going to accomplish the task – even if that person is you. What steps should I be taking next to finish this task?
38+
39+
Once you've created the issue, you can [make your changes and push them up](#how-to-write-new-code).
40+
41+
## What kind of documentation are you writing?
42+
43+
- [I want to improve the documentation of the API endpoints.](#improving-the-api-endpoint-docs)
44+
- [I want to document some of the internals of the Elixir app](#improving-elixir-docs).
45+
- [I want to improve the docs on GitHub.](#improving-the-readme)
46+
47+
## Improving the API endpoint docs
48+
49+
We're using [API Blueprint](https://apiblueprint.org/) for writing our docs, and you can use the Apiary CLI tool to preview them.
50+
51+
#### Learning how to write API Blueprint documentation
52+
53+
API Blueprint has a [quick tutorial you can read](https://apiblueprint.org/documentation/tutorial.html) that walks through writing your first docs in the API Blueprint language.
54+
55+
You can [read more examples here](https://github.com/apiaryio/api-blueprint/tree/master/examples) or check our own blueprint for examples.
56+
57+
#### Where do I make changes?
58+
59+
You will be working with the `blueprint/api.apib` document. You'll likely be adding any number of:
60+
61+
- Resource Groups
62+
- Resources
63+
- Actions
64+
- URI Templates
65+
- URI Parameters
66+
- Data Structures
67+
68+
Data Structures often serve as your base objects for assembling the higher-level endpoint documentation. These objects are composeable – like Lego blocks – in new and often interesting ways.
69+
70+
The `/users/:id` endpoint documented in the `User` resource group, for example, may contain a `User Response` for its `200` response. This `User Response` data structure is itself composed of a `User` data structure (which collects the attributes for that user like `email` and `username`) and a `User Relationships Base` data structure, which includes yet more data structures like the `User Skills Relationship`.
71+
72+
By creating small, modular pieces, we can assemble complex data structures that describe our API.
73+
74+
#### Previewing your changes
75+
76+
You can preview your changes by [walking through our guide on how to generate API documentation locally](docs/API.md).
77+
78+
[Done with your changes?](#i-finished-my-changes)
79+
80+
## Improving Elixir docs
81+
82+
You can see how much code is documented on [Inch CI](http://inch-ci.org/github/code-corps/code-corps-api).
83+
84+
You can learn about how to write documentation for Elixir apps from these places:
85+
86+
- [Elixir School has a great guide](https://elixirschool.com/lessons/basics/documentation/)
87+
- [Elixir itself also has a great guide](http://elixir-lang.org/docs/stable/elixir/writing-documentation.html)
88+
- And Elixir has [a deeper guide for Module documentation specifically](http://elixir-lang.org/docs/stable/elixir/Module.html)
89+
90+
[Done with your changes?](#i-finished-my-changes)
91+
92+
## Improving the README
93+
94+
If you're just looking to improve the README, there's a couple things you should know:
95+
96+
- Open an issue first. It's better if we discuss your proposed changes.
97+
- We try to keep the main `README.md` lightweight and use it as a jumping point to other docs.
98+
- Most other docs can be placed in `/docs`.
99+
- Try to make it easy for people to jump around in your doc.
100+
101+
[Done with your changes?](#i-finished-my-changes)
102+
103+
## How to fix a bug
104+
105+
If you're fixing a bug that's already been added to the issues, ask yourself whether the bug description is clear? Do you know what circumstances led to the bug? Does it seem easy to reproduce?
106+
107+
If you've spotted a bug yourself, open an issue and try to answer those questions.
108+
109+
Then start writing some code:
110+
111+
1. Make the tests fail.
112+
113+
Identify what's happening in the bug with a test. This way the bug is reproducible for everyone else in the project, and we won't regress into making the bug ever again (hopefully!).
114+
115+
2. Make the tests pass again.
116+
117+
Write your code that fixes the bug and makes it pass.
118+
119+
[Done with your changes?](#i-finished-my-changes)
120+
121+
## How to refactor some code
122+
123+
Refactoring code shouldn't require any new tests, but you should [make sure the tests still pass](#running-tests).
124+
125+
[Done with your refactoring?](#i-finished-my-changes)
126+
127+
## How to write new code
128+
129+
When you're ready to write some new code, you should do the following:
130+
131+
1. Write some documentation for your change.
132+
133+
Why do this first? Well, if you know the behavior you want to see, then it's easier to validate if it works as expected. Think of this as documentation-driven development.
134+
135+
[What kind of documentation are you writing?](#what-kind-of-documentation-are-you-writing)
136+
137+
2. Add a test for your change. [Here's how to run tests.](#running-tests)
138+
139+
3. Make the test pass.
140+
141+
Try to keep your changes to a max of around 200 lines of code whenever possible. Why do this? Apparently the more changes incurred in a pull request, the likelier it is that people who review your code will just gloss over the details. Smaller pull requests get more comments and feedback than larger ones. Crazy, right?
142+
143+
[Done with your changes and ready for a review?](#i-finished-my-changes)
144+
145+
## What if I don't know how to help?
146+
147+
Not a problem! You can try looking around for issues that say `good for new contributors`. Documentation really is a good place to start. If you're still not sure, just [join our Slack](http://slack.codecorps.org) and flag someone down. Someone can help point you in the right direction.
148+
149+
## I finished my changes
150+
151+
Now you just need to push your finished code to your fork and submit a pull request.
152+
153+
Your pull request will be run through a continuous integration server to test your changes, [as described here](#continuous-integration).
154+
155+
At this point you're waiting on us. We like to at least comment on, if not
156+
accept, pull requests within a week's time. We may suggest some changes or improvements or alternatives.
157+
158+
Some things that will increase the chance that your pull request is accepted:
159+
160+
* Use Elixir idioms
161+
* Include tests that fail without your code, and pass with it
162+
* Update the documentation, the surrounding one, examples elsewhere, guides,
163+
whatever is affected by your contribution
164+
165+
Has your code been reviewed? [Here's what we need before we can merge.](#before-we-can-merge)
166+
167+
## Continuous Integration
168+
169+
We use [CircleCI](https://circleci.com/) to test your branches and continuously deploy branches merged into `develop` to our staging API and branches merged into `master` to our production API.
170+
171+
If your test fails on Circle, you should re-check your tests. Sometimes this indicates a mismatch between your environment and our expected environment.
172+
173+
The `circle.yml` file specifies what happens in the builds. You can [read more about that in Circle's documentation](https://circleci.com/docs/configuration/).
174+
175+
The CircleCI builds also rely on some environment variables for reporting, deployments, and other requirements.
176+
177+
## Before We Can Merge
178+
179+
If you've had a pull request reviewed and accepted, congratulations! Before we can merge your changes, we'll need you to rebase off `origin/develop` and squash your commits into one. This will give us a cleaner git history.
180+
181+
Never done this before? No problem. [We'll walk you through it in our guide](docs/SQUASHING.md), and you can read [a deeper guide about rewriting history to understand more](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History).
182+
183+
## Running Tests
184+
185+
We use `ExUnit`, Elixir's built-in test framework for unit tests.
186+
187+
Here's [a guide on Elixir School for writing tests](https://elixirschool.com/lessons/basics/testing/).
188+
189+
### Testing helpers
190+
191+
We've written some convenience helper modules and functions to help with API testing. The helpers are found in `test/support` as:
192+
193+
- `CodeCorps.ApiCase` - used to simplify testing JSON API endpoints
194+
- `CodeCorps.AuthenticationTestHelpers` - provides authentication helpers for authenticating a `conn`
195+
- `CodeCorps.Factories` - provides factories using [`ex_machina`](https://github.com/thoughtbot/ex_machina), which makes it easy to create test data and associations with Ecto
196+
197+
### Tagged tests
198+
199+
Some tests are tagged like so:
200+
201+
```elixir
202+
@tag :requires_env
203+
```
204+
205+
These tests do not run by default when running `mix test` because you do not have access to the environment variables listed in `.env.example` by default.
206+
207+
To read more about the environment variables, see the "Environment" section of our [usage docs](docs/USAGE.md#environment).

README.md

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,68 @@
1-
# Code Corps Phoenix API
1+
# Code Corps Elixir API
22

33
![Code Corps Phoenix Logo](https://d3pgew4wbk2vb1.cloudfront.net/images/github/code-corps-api.png)
44

55
[![CircleCI](https://circleci.com/gh/code-corps/code-corps-api.svg?style=svg)](https://circleci.com/gh/code-corps/code-corps-api) [![Inline docs](http://inch-ci.org/github/code-corps/code-corps-api.svg?branch=develop)](http://inch-ci.org/github/code-corps/code-corps-api) [![Coverage Status](https://coveralls.io/repos/github/code-corps/code-corps-api/badge.svg?branch=develop)](https://coveralls.io/github/code-corps/code-corps-api?branch=develop) [![Deps Status](https://beta.hexfaktor.org/badge/all/github/code-corps/code-corps-api.svg)](https://beta.hexfaktor.org/github/code-corps/code-corps-api) [![Slack Status](http://slack.codecorps.org/badge.svg)](http://slack.codecorps.org)
66

7+
This is the [Elixir](http://elixir-lang.org/) and [Phoenix](http://www.phoenixframework.org/) backend API for [codecorps.org](https://www.codecorps.org).
8+
9+
Code Corps is an open source platform for building and funding public software with massive social impact.
10+
11+
Our goals:
12+
13+
- **Connect people** - Match developers and designers, project managers and marketers – any and every talent – to ambitious projects that need their help.
14+
- **Provide support** - Educate and train, develop and encourage people who build public software. Help projects be successful and people to do their best work.
15+
- **Fund projects** - Crowdfund ongoing work and keep funders engaged in projects and connected to the teams they're supporting.
16+
- **Develop new tools** - Help people collaborate on, organize, and even distribute their work. Listen closely to hear what needs built, and then build it.
17+
18+
## How can I help?
19+
20+
We'd love to have you contribute to Code Corps directly!
21+
22+
- First, read the guidelines in our [`CONTRIBUTING.md`](CONTRIBUTING.md).
23+
- Then check out some GitHub issues to see where you can help out.
24+
25+
You can also always come :wave: hello [in our Slack](http://slack.codecorps.org), where there are always a ton of us around to help you learn, debug, or just shoot the breeze.
26+
27+
We highlight everyone who's contributed to [the Code Corps team page](https://www.codecorps.org/team). If we've missed you for some reason, please [open an issue in the Ember app](https://github.com/code-corps/code-corps-ember/issues/new)!
28+
729
## Installing with Docker
830

931
To make your life easier, you can just clone this repository and use our Docker container. [Follow this guide to get started.](docs/INSTALLING.md)
1032

11-
## Continuous Integration
33+
## Usage
34+
35+
Have everything installed and ready to work? Read [our usage guides](docs/USAGE.md) to learn how to:
1236

13-
We use [CircleCI](https://circleci.com/) to test your branches and continuously deploy branches merged into `develop` to our staging API and branches merged into `master` to our production API.
37+
- [Run normal `mix` commands through Docker](docs/USAGE.md#interacting-with-the-app)
38+
- [Stop and start the server](docs/USAGE.md#stopping-and-starting-the-server)
39+
- [Run tests](docs/USAGE.md#running-tests)
40+
- [Rebuild Docker containers](docs/USAGE.md#rebuilding-docker-containers)
41+
- [Work with the Ember front-end](docs/USAGE.md#serving-ember)
42+
- [Set up environment variables](docs/USAGE.md#environment)
43+
- [Push changes to GitHub](docs/USAGE.md#pushing-changes)
1444

15-
If your test fails on Circle, you should re-check your tests. Sometimes this indicates a mismatch between your environment and our expected environment.
45+
## Documentation
1646

17-
The `circle.yml` file specifies what happens in the builds. You can [read more about that in Circle's documentation](https://circleci.com/docs/configuration/).
47+
We have several types of docs:
1848

19-
The CircleCI builds also rely on some environment variables for reporting, deployments, and other requirements.
49+
- Project documentation (README, CONTRIBUTING, etc.)
50+
- [API documentation](http://docs.codecorpsapi.apiary.io/) written in [API Blueprint](https://apiblueprint.org/) format in [`blueprint/api.apib`](blueprint/api.apib) and published to the web when merging into `develop`
51+
- [Inline documentation](https://code-corps.github.io/code-corps-api-github-pages) for the Elixir app generated by [`ex_doc`](https://github.com/elixir-lang/ex_doc) and published to GitHub pages when merging into `develop`
2052

21-
## Usage
53+
Want to improve the documentation? [Get started here.](CONTRIBUTING.md#what-kind-of-documentation-are-you-writing)
54+
55+
## Things we care about
56+
57+
Our values for this project reflect the Code Corps values as a whole, though with some minor differences.
58+
59+
We care about:
60+
61+
- Each other :raised_hands:
62+
- Social impact :earth_africa:
63+
- Good documentation :memo:
64+
- Testing :microscope:
65+
- Welcoming and teaching new contributors :wave:
66+
- Writing small, clear, and achievable issues :dart:
2267

23-
To learn about how to run the application, run tests, configure your environment, and more [in the usage guides](docs/USAGE.md).
68+
We also track quantifiable metrics like inline documentation coverage, testing coverage, and so on. You can see some of these metrics in the icons at the top of this page.

docs/API.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# How to generate API documentation locally
2+
3+
You can generate documentation a few ways:
4+
5+
- [Apiary CLI](#apiary-cli) (recommended)
6+
- [`aglio`](#aglio)
7+
- [Atom](#atom)
8+
9+
### Apiary CLI
10+
11+
[Apiary CLI](https://help.apiary.io/tools/apiary-cli/) comes preloaded when you run `docker-compose up` like normal.
12+
13+
Once Docker is running your containers, `apiary` runs an Apiary CLI server on port `8081`. You can visit the documentation by visiting `localhost:8081` in your browser. Just refresh the page any time you make changes to the documentation file at `/blueprint/api.apib`.
14+
15+
### aglio
16+
17+
Navigate into the `/blueprint` directory.
18+
19+
If installing for the first time, run:
20+
21+
```shell
22+
docker-compose build
23+
```
24+
25+
Then start the `aglio` service with:
26+
27+
```shell
28+
docker-compose up
29+
```
30+
31+
Now you can generate the docs with our shell script:
32+
33+
```bash
34+
./generate
35+
```
36+
37+
You should be able to view the docs by opening the newly generated `index.html` in your browser.
38+
39+
### Atom
40+
41+
If you're developing with [Atom](https://atom.io/), you can also use the [API Blueprint Preview](https://atom.io/packages/api-blueprint-preview) package to preview your blueprint changes in realtime.

0 commit comments

Comments
 (0)