Skip to content

Commit

Permalink
Merge branch 'master' into menu-2
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmelnikow authored Jan 9, 2019
2 parents a56782f + 7e1b112 commit 25eaf4f
Show file tree
Hide file tree
Showing 57 changed files with 585 additions and 357 deletions.
25 changes: 0 additions & 25 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ jobs:
when: always
command: npm run lint

- run:
name: Prepare test summary
when: always
command: mkdir junit

- run:
name: Server unit tests
when: always
Expand Down Expand Up @@ -103,11 +98,6 @@ jobs:
when: always
command: npm run lint

- run:
name: Prepare test summary
when: always
command: mkdir junit

- run:
name: Server unit tests
when: always
Expand Down Expand Up @@ -181,11 +171,6 @@ jobs:
name: Prepare frontend tests
command: npm run defs && npm run features

- run:
name: Prepare test summary
when: always
command: mkdir junit

- run:
name: Frontend unit tests
environment:
Expand Down Expand Up @@ -221,11 +206,6 @@ jobs:
name: Identify services tagged in the PR title
command: npm run test:services:pr:prepare

- run:
name: Prepare test summary
when: always
command: mkdir junit

- run:
name: Run tests for tagged services
environment:
Expand Down Expand Up @@ -256,11 +236,6 @@ jobs:
name: Identify services tagged in the PR title
command: npm run test:services:pr:prepare

- run:
name: Prepare test summary
when: always
command: mkdir junit

- run:
name: Run tests for tagged services
environment:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ service-definitions.yml
/config/local*.yml

# Template for the local runtime configuration.
!/config/local.template.yml
!/config/local*.template.yml
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ analytics.json
gh-badges/templates/_shields_test-template.json
gh-badges/templates/default-template.json
doc/TUTORIAL.md
supported-features.json
service-definitions.yml
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
</p>
<p align="center">
<a href="#backers" alt="Backers on Open Collective">
<img src="https://opencollective.com/shields/backers/badge.svg" /></a>
<img src="https://img.shields.io/opencollective/backers/shields.svg" /></a>
<a href="#sponsors" alt="Sponsors on Open Collective">
<img src="https://opencollective.com/shields/sponsors/badge.svg" /></a>
<img src="https://img.shields.io/opencollective/sponsors/shields.svg" /></a>
<a href="https://circleci.com/gh/badges/shields/tree/master">
<img src="https://img.shields.io/circleci/project/github/badges/shields/master.svg"
alt="build status"></a>
Expand Down Expand Up @@ -101,9 +101,8 @@ You can read a [tutorial on how to add a badge][tutorial].
Tests need to pass in Node 8 and 9.
2. Clone this repository.
3. Run `npm install` to install the dependencies.
4. Run `npm run build` to build the frontend.
5. Run `npm start` to start the server.
6. Open `http://[::]:8080/` to view the home page.
4. Run `npm start` to start the server.
5. Open `http://localhost:3000/` to view the frontend.

To generate the frontend using production cache settings &ndash; that is,
badge preview URIs with `maxAge` &ndash; run `LONG_CACHE=true npm run build`.
Expand Down
10 changes: 10 additions & 0 deletions config/local-shields-io-production.template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
private:
bintray_user: ...
bintray_apikey: ...
gh_client_id: ...
gh_client_secret: ...
sentry_dsn: ...
shields_secret: ...
sl_insight_userUuid: ...
sl_insight_apiToken: ...
wheelmap_token: ...
3 changes: 3 additions & 0 deletions dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
// `./node_modules/.bin/danger pr pr-url`
// Note that the line numbers in the runtime errors are incorrect.

// To test changes locally:
// DANGER_GITHUB_API_TOKEN=your-github-api-token npm run danger -- pr https://github.com/badges/shields/pull/2665

const { danger, fail, message, warn } = require('danger')
const chainsmoker = require('chainsmoker')
const { default: noTestShortcuts } = require('danger-plugin-no-test-shortcuts')
Expand Down
12 changes: 6 additions & 6 deletions doc/TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Tutorial on how to add a badge for a service
============================================

This tutorial should help you add a service to shields.io in form of a badge.
You will need to learn to use JavaScript, git and Github.
You will need to learn to use JavaScript, Git and GitHub.
Please [improve the tutorial](https://github.com/badges/shields/edit/master/doc/TUTORIAL.md) while you read it.

(1) Reading
Expand Down Expand Up @@ -71,11 +71,11 @@ Each service has a directory for its files:
Sometimes, code for a service can be re-used.
This might be the case when you add a badge for an API which is already used
by other badges.

Imagine a service that lives at https://img.shields.io/example/some-param-here.svg.

* For services with a single badge, the badge code will generally be stored in
`/services/example/example.service.js`.
`/services/example/example.service.js`.
If you add a badge for a new API, create a new directory.

Example: [wercker](https://github.com/badges/shields/tree/master/services/wercker)
Expand Down Expand Up @@ -218,11 +218,11 @@ Description of the code:
* [licenses.js](https://github.com/badges/shields/blob/master/lib/licenses.js)
* [text-formatters.js](https://github.com/badges/shields/blob/master/lib/text-formatters.js)
* [version.js](https://github.com/badges/shields/blob/master/lib/version.js)
4. We perform input validation by defining a schema which we expect the JSON we receive to conform to. This is done using [Joi](https://github.com/hapijs/joi). Defining a schema means we can ensure the JSON we receive meets our expectations and throw an error if we receive unexpected input without having to explicitly code validation checks. The schema also acts as a filter on the JSON object. Any properties we're going to reference need to be validated, otherwise they will be filtered out. In this case our schema declares that we expect to recieve an object which must have a property called 'status', which is a string.
4. We perform input validation by defining a schema which we expect the JSON we receive to conform to. This is done using [Joi](https://github.com/hapijs/joi). Defining a schema means we can ensure the JSON we receive meets our expectations and throw an error if we receive unexpected input without having to explicitly code validation checks. The schema also acts as a filter on the JSON object. Any properties we're going to reference need to be validated, otherwise they will be filtered out. In this case our schema declares that we expect to receive an object which must have a property called 'status', which is a string.
5. Our module exports a class which extends `BaseJsonService`
6. As with our previous badge, we need to declare a route. This time we will capture a variable called `gem`.
7. We can use `defaultBadgeData()` to set a default `color`, `logo` and/or `label`. If `handle()` doesn't return any of these keys, we'll use the default. Instead of explicitly setting the label text when we return a badge object, we'll use `defaultBadgeData()` here to define it declaratively.
8. Our bage must implement the `async handle()` function. Because our URL pattern captures a variable called `gem`, our function signature is `async handle({ gem })`. We usually separate the process of generating a badge into 2 stages or concerns: fetch and render. The `fetch()` function is responsible for calling an API endpoint to get data. The `render()` function formats the data for display. In a case where there is a lot of calculation or intermediate steps, this pattern may be thought of as fetch, transform, render and it might be necessary to define some helper functions to assist with the 'transform' step.
8. Our badge must implement the `async handle()` function. Because our URL pattern captures a variable called `gem`, our function signature is `async handle({ gem })`. We usually separate the process of generating a badge into 2 stages or concerns: fetch and render. The `fetch()` function is responsible for calling an API endpoint to get data. The `render()` function formats the data for display. In a case where there is a lot of calculation or intermediate steps, this pattern may be thought of as fetch, transform, render and it might be necessary to define some helper functions to assist with the 'transform' step.
9. The `async fetch()` method is responsible for calling an API endpoint to get data. Extending `BaseJsonService` gives us the helper function `_requestJson()`. Note here that we pass the schema we defined in step 4 as an argument. `_requestJson()` will deal with validating the response against the schema and throwing an error if necessary.
* `_requestJson()` automatically adds an Accept header, checks the status code, parses the response as JSON, and returns the parsed response.
* `_requestJson()` uses [request](https://github.com/request/request) to perform the HTTP request. Options can be passed to request, including method, query string, and headers. If headers are provided they will override the ones automatically set by `_requestJson()`. There is no need to specify json, as the JSON parsing is handled by `_requestJson()`. See the `request` docs for [supported options](https://github.com/request/request#requestoptions-callback).
Expand Down Expand Up @@ -297,7 +297,7 @@ If you update `examples`, you don't have to restart the server. Run `npm run
defs` in another terminal window and the frontend will update.

### (4.5) Write Tests <!-- Change the link below when you change the heading -->
[write tests]: #45-write-tests
[write tests]: #45-write-tests

When creating a badge for a new service or changing a badge's behavior, tests
should be included. They serve several purposes:
Expand Down
Loading

0 comments on commit 25eaf4f

Please sign in to comment.