Skip to content

Commit

Permalink
feat: add report-path option
Browse files Browse the repository at this point in the history
  • Loading branch information
tlvince committed Nov 4, 2019
1 parent 655a7fd commit 678a2f8
Show file tree
Hide file tree
Showing 19 changed files with 3,327 additions and 2,895 deletions.
19 changes: 19 additions & 0 deletions .dependabot/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 1
update_configs:
- package_manager: javascript
directory: /
update_schedule: daily
default_labels:
- dependencies
automerged_updates:
- match:
update_type: all
dependency_type: all
allowed_updates:
- match:
update_type: all
dependency_type: direct
- match:
update_type: security
dependency_type: indirect
version_requirement_updates: increase_versions
9 changes: 9 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
parserOptions: {
ecmaVersion: 2018,
},
env: {
node: true,
},
}
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: tlvince
28 changes: 28 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''
---

**Describe the bug**

> A clear and concise description of what the bug is
**To Reproduce**

> Steps to reproduce the behaviour
**Expected behaviour**

> A clear and concise description of what you expected to happen.
**Screenshots**

> If applicable, add screenshots to help explain your problem.
**Context**

- OS:
- Version:
23 changes: 23 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''
---

**Is your feature request related to a problem? Please describe.**

> A clear and concise description of what the problem is, e.g. I'm always frustrated when [...]
**Describe the solution you'd like**

> A clear and concise description of what you want to happen
**Describe alternatives you've considered**

> A clear and concise description of any alternative solutions or features you've considered
**Additional context**

> Add any other context or screenshots about the feature request here.
31 changes: 31 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## Description

<!-- Describe your changes in detail. Add screenshots where relevant. -->

## How has this been tested?

<!-- Please describe how you tested your changes. -->

## Types of changes

<!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->

- [ ] Test change (non-breaking change which adds additional test scenarios)
- [ ] Refactor change (non-breaking change updates coding styles)
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## Checklist

<!-- Go over all the following points, and put an `x` in all the boxes that apply. -->

- [ ] I have ran `npm run lint` and everything passes
- [ ] I have ran `npm run test` and everything passes
- [ ] I have ran `npm run build` and everything built
- [ ] My code follows the code style of this project
- [ ] I have pinned all new external dependencies to an exact version
- [ ] I have updated the documentation where necessary
- [ ] I have read the [CONTRIBUTING](../CONTRIBUTING.md) document
- [ ] I have added tests to cover my changes
- [ ] All new and existing tests pass
11 changes: 11 additions & 0 deletions .github/SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Security Policy

## Supported Versions

Only the latest release of this project is currently being supported with security updates.

## Reporting a Vulnerability

Please report vulnerabilities using the issue tracker. If it's sensitive, please contact me via [Keybase][].

[keybase]: https://keybase.io/tlvince
5 changes: 5 additions & 0 deletions .github/SUPPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Support

This is an open source project that I maintain in my free time. I can only offer limited support, but will do my best to fix any bugs and implement new feature requests.

Please see the [CONTRIBUTING](../CONTRIBUTING.md) document. If in doubt, feel free to get in touch.
11 changes: 11 additions & 0 deletions .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Commitlint
on: pull_request

jobs:
lint:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v1
- uses: wagoid/[email protected]
17 changes: 17 additions & 0 deletions .github/workflows/pull-requests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Pull Requests
on: pull_request
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1

- name: Install
run: npm ci

- name: Lint
run: npm run lint

- name: Test
run: npm run test
5 changes: 5 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
semi: false,
trailingComma: 'es5',
singleQuote: true,
}
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- '10'
- '12'
cache: npm
notifications:
email: false
Expand Down
76 changes: 76 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to make participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behaviour that contributes to creating a positive environment
include:

- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members

Examples of unacceptable behaviour by participants include:

- The use of sexualised language or imagery and unwelcome sexual attention or
advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic
address, without explicit permission
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behaviour and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behaviour.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviours that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies within all project spaces, and it also applies when
an individual is representing the project or its community in public spaces.
Examples of representing a project or community include using an official
project e-mail address, posting via an official social media account, or acting
as an appointed representative at an online or offline event. Representation of
a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behaviour may be
reported by contacting the project team at [email protected]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
33 changes: 33 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Contributing

Hey! Thanks for your interest in contributing to this project.

In lieu of formal guideline for this project, please familiarise yourself with the following guides:

- [How to Contribute to Open Source][]
- [necolas/issue-guidelines][]
- Tim Pope's [Git commit message model][tpope]

Also note, this project is released with a [Contributor Code of Conduct](./CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.

In brief, for issues:

- before opening an issue, please search for existing issues
- if you're reporting a bug, please include steps to reproduce the issue and a [reduced test case][]
- for feature requests, please share the motivation for the feature and how you would implement it

For pull requests:

- please make use of the included linting and editor configuration
- add a unit test for new/changed functionality
- format commit messages according to [Conventional Commits][]

If in doubt, file an issue first.

Thanks!

[how to contribute to open source]: https://opensource.guide/how-to-contribute/
[necolas/issue-guidelines]: https://github.com/necolas/issue-guidelines/blob/master/CONTRIBUTING.md
[tpope]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
[conventional commits]: https://www.conventionalcommits.org/
[reduced test case]: https://css-tricks.com/reduced-test-cases/
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ Resulting badge will be in `./coverage/badge.svg`.

Writes the coverage badge to the given path (relative to project root). Defaults to `./coverage/badge.svg`.

### `--report-path <path>`

Path to a coverage report file. Defaults to `./coverage/coverage-summary.json`.

## Prior work

- [Coveralls][]: paid for private repos
Expand Down
34 changes: 29 additions & 5 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

const { get } = require('https')
const { readFile, writeFile } = require('fs')
const { basename } = require('path')
const mri = require('mri')

const getColour = coverage => {
if (coverage < 80) {
Expand All @@ -21,7 +23,9 @@ const getBadge = report => {
const coverage = report.total.statements.pct
const colour = getColour(coverage)

return `https://img.shields.io/badge/Coverage-${coverage}${encodeURI('%')}-${colour}.svg`
return `https://img.shields.io/badge/Coverage-${coverage}${encodeURI(
'%'
)}-${colour}.svg`
}

const download = (url, cb) => {
Expand All @@ -32,18 +36,38 @@ const download = (url, cb) => {
}).on('error', err => cb(err))
}

const [, , thirdArg, fourthArg] = process.argv
const outputPath = ((thirdArg === '--output-path' || thirdArg === '--outputPath') && fourthArg) ? fourthArg : './coverage/badge.svg'
const options = {
alias: {
h: 'help',
outputPath: 'output-path',
},
boolean: 'help',
default: {
'output-path': './coverage/badge.svg',
'report-path': './coverage/coverage-summary.json',
},
}

const [, filename, ...args] = process.argv
const { _, help, ...params } = mri(args, options) // eslint-disable-line no-unused-vars

if (help) {
console.log(
`usage: ${basename(filename)} [-h,--help] [--report-path] [--output-path]`
)
process.exit()
}

const { outputPath, 'report-path': reportPath } = params

readFile('./coverage/coverage-summary.json', 'utf8', (err, res) => {
readFile(reportPath, 'utf8', (err, res) => {
if (err) throw err
const report = JSON.parse(res)
const url = getBadge(report)
download(url, (err, res) => {
if (err) throw err
writeFile(outputPath, res, 'utf8', err => {
if (err) throw err

console.log('Wrote coverage badge to: ' + outputPath)
})
})
Expand Down
Loading

0 comments on commit 678a2f8

Please sign in to comment.