Skip to content

Commit

Permalink
Merge branch 'master' into feat/style-table
Browse files Browse the repository at this point in the history
  • Loading branch information
Berkmann18 authored May 21, 2019
2 parents 3fd8aa6 + 354b511 commit 3740e57
Show file tree
Hide file tree
Showing 21 changed files with 251 additions and 74 deletions.
21 changes: 20 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,28 @@
"contributions": [
"design"
]
},
{
"login": "ehmicky",
"name": "ehmicky",
"avatar_url": "https://avatars2.githubusercontent.com/u/8136211?v=4",
"profile": "https://twitter.com/ehmicky",
"contributions": [
"code"
]
},
{
"login": "jamesgeorge007",
"name": "James George",
"avatar_url": "https://avatars2.githubusercontent.com/u/25279263?v=4",
"profile": "https://ghuser.io/jamesgeorge007",
"contributions": [
"code"
]
}
],
"files": [
"README.md"
]
],
"repoHost": "https://github.com"
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ dist
# when working with contributors
package-lock.json
yarn.lock
.vscode
cache
71 changes: 29 additions & 42 deletions README.md

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,19 @@
"@babel/runtime": "^7.2.0",
"async": "^2.0.0-rc.1",
"chalk": "^2.3.0",
"didyoumean": "^1.2.1",
"inquirer": "^6.2.1",
"json-fixer": "^1.3.1-0",
"lodash": "^4.11.2",
"pify": "^4.0.1",
"request": "^2.72.0",
"yargs": "^12.0.5"
"yargs": "^13.1.0"
},
"devDependencies": {
"codecov": "^3.1.0",
"cz-conventional-changelog": "^2.1.0",
"git-cz": "^1.8.0",
"kcd-scripts": "^0.49.0",
"git-cz": "^3.0.0",
"kcd-scripts": "^1.0.0",
"nock": "^10.0.6",
"semantic-release": "^15.13.2"
},
Expand Down
14 changes: 14 additions & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const path = require('path')
const yargs = require('yargs')
const chalk = require('chalk')
const inquirer = require('inquirer')
const didYouMean = require('didyoumean')

// Setting edit length to be 60% of the input string's length
didYouMean.threshold = 0.6

const init = require('./init')
const generate = require('./generate')
Expand Down Expand Up @@ -46,6 +50,15 @@ const yargv = yargs
}
}).argv

function suggestCommands(cmd) {
const availableCommands = ['generate', 'add', 'init', 'check']
const suggestion = didYouMean(cmd, availableCommands)

if (suggestion) {
console.log(chalk.bold(`Did you mean ${suggestion}`))
}
}

function startGeneration(argv) {
return Promise.all(
argv.files.map(file => {
Expand Down Expand Up @@ -170,6 +183,7 @@ promptForCommand(yargv)
case 'check':
return checkContributors(yargv)
default:
suggestCommands(command)
throw new Error(`Unknown command ${command}`)
}
})
Expand Down
7 changes: 6 additions & 1 deletion src/contributors/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ function getQuestions(options, username, contributions) {
options.repoType,
)} username?`,
when: !username,
validate: function validate(input) {
if (!input) {
return 'Username not provided'
}
return true
},
},
{
type: 'checkbox',
Expand Down Expand Up @@ -88,7 +94,6 @@ function getValidUserContributions(options, contributions) {
`${invalidUserContributions.toString()} is/are invalid contribution type(s)`,
)
}

return validUserContributions
}

Expand Down
6 changes: 4 additions & 2 deletions src/generate/__tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Description
These people contributed to the project:
<!-- ALL-CONTRIBUTORS-LIST:START -->
<!-- prettier-ignore -->
<table cellspacing=\\"0\\" cellpadding=\\"1\\"><tr><td>Kent C. Dodds is awesome!</td><td>Divjot Singh is awesome!</td><td>Jeroen Engels is awesome!</td></tr></table>
<table><tr><td align=\\"center\\">Kent C. Dodds is awesome!</td><td align=\\"center\\">Divjot Singh is awesome!</td><td align=\\"center\\">Jeroen Engels is awesome!</td></tr></table>
<!-- ALL-CONTRIBUTORS-LIST:END -->
Thanks a lot everyone!"
Expand All @@ -24,7 +25,8 @@ Description
These people contributed to the project:
<!-- ALL-CONTRIBUTORS-LIST:START -->
<!-- prettier-ignore -->
<table cellspacing=\\"0\\" cellpadding=\\"1\\"><tr><td>Kent C. Dodds is awesome!</td><td>Kent C. Dodds is awesome!</td><td>Kent C. Dodds is awesome!</td><td>Kent C. Dodds is awesome!</td><td>Kent C. Dodds is awesome!</td></tr><tr><td>Kent C. Dodds is awesome!</td><td>Kent C. Dodds is awesome!</td></tr></table>
<table><tr><td align=\\"center\\">Kent C. Dodds is awesome!</td><td align=\\"center\\">Kent C. Dodds is awesome!</td><td align=\\"center\\">Kent C. Dodds is awesome!</td><td align=\\"center\\">Kent C. Dodds is awesome!</td><td align=\\"center\\">Kent C. Dodds is awesome!</td></tr><tr><td align=\\"center\\">Kent C. Dodds is awesome!</td><td align=\\"center\\">Kent C. Dodds is awesome!</td></tr></table>
<!-- ALL-CONTRIBUTORS-LIST:END -->
Thanks a lot everyone!"
Expand Down
10 changes: 5 additions & 5 deletions src/generate/__tests__/format-contributor.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('format a simple contributor', () => {
const {options} = fixtures()

const expected =
'<a href="http://kentcdodds.com"><img src="https://avatars1.githubusercontent.com/u/1500684" width="150px;" height="150px;" alt="Kent C. Dodds"/><br /><sub><b>Kent C. Dodds</b></sub></a><br /><a href="#review-kentcdodds" title="Reviewed Pull Requests">👀</a>'
'<a href="http://kentcdodds.com"><img src="https://avatars1.githubusercontent.com/u/1500684" width="150px;" alt="Kent C. Dodds"/><br /><sub><b>Kent C. Dodds</b></sub></a><br /><a href="#review-kentcdodds" title="Reviewed Pull Requests">👀</a>'

expect(formatContributor(options, contributor)).toBe(expected)
})
Expand All @@ -30,7 +30,7 @@ test('format contributor with complex contribution types', () => {
const {options} = fixtures()

const expected =
'<a href="http://kentcdodds.com"><img src="https://avatars1.githubusercontent.com/u/1500684" width="150px;" height="150px;" alt="Kent C. Dodds"/><br /><sub><b>Kent C. Dodds</b></sub></a><br /><a href="https://github.com/all-contributors/all-contributors-cli/commits?author=kentcdodds" title="Documentation">📖</a> <a href="#review-kentcdodds" title="Reviewed Pull Requests">👀</a> <a href="#question-kentcdodds" title="Answering Questions">💬</a>'
'<a href="http://kentcdodds.com"><img src="https://avatars1.githubusercontent.com/u/1500684" width="150px;" alt="Kent C. Dodds"/><br /><sub><b>Kent C. Dodds</b></sub></a><br /><a href="https://github.com/all-contributors/all-contributors-cli/commits?author=kentcdodds" title="Documentation">📖</a> <a href="#review-kentcdodds" title="Reviewed Pull Requests">👀</a> <a href="#question-kentcdodds" title="Answering Questions">💬</a>'

expect(formatContributor(options, contributor)).toBe(expected)
})
Expand All @@ -53,7 +53,7 @@ test('default image size to 100', () => {
delete options.imageSize

const expected =
'<a href="http://kentcdodds.com"><img src="https://avatars1.githubusercontent.com/u/1500684" width="100px;" height="100px;" alt="Kent C. Dodds"/><br /><sub><b>Kent C. Dodds</b></sub></a><br /><a href="#review-kentcdodds" title="Reviewed Pull Requests">👀</a>'
'<a href="http://kentcdodds.com"><img src="https://avatars1.githubusercontent.com/u/1500684" width="100px;" alt="Kent C. Dodds"/><br /><sub><b>Kent C. Dodds</b></sub></a><br /><a href="#review-kentcdodds" title="Reviewed Pull Requests">👀</a>'

expect(formatContributor(options, contributor)).toBe(expected)
})
Expand All @@ -63,7 +63,7 @@ test('format contributor with pipes in their name', () => {
const {options} = fixtures()

const expected =
'<a href="http://github.com/chrisinajar"><img src="https://avatars1.githubusercontent.com/u/1500684" width="150px;" height="150px;" alt="Who &#124; Needs &#124; Pipes?"/><br /><sub><b>Who &#124; Needs &#124; Pipes?</b></sub></a><br /><a href="https://github.com/all-contributors/all-contributors-cli/commits?author=pipey" title="Documentation">📖</a>'
'<a href="http://github.com/chrisinajar"><img src="https://avatars1.githubusercontent.com/u/1500684" width="150px;" alt="Who &#124; Needs &#124; Pipes?"/><br /><sub><b>Who &#124; Needs &#124; Pipes?</b></sub></a><br /><a href="https://github.com/all-contributors/all-contributors-cli/commits?author=pipey" title="Documentation">📖</a>'

expect(formatContributor(options, contributor)).toBe(expected)
})
Expand All @@ -73,7 +73,7 @@ test('format contributor with no github account', () => {
const {options} = fixtures()

const expected =
'<img src="https://avatars1.githubusercontent.com/u/1500684" width="150px;" height="150px;" alt="No Github Account"/><br /><sub><b>No Github Account</b></sub><br /><a href="#translation" title="Translation">🌍</a>'
'<img src="https://avatars1.githubusercontent.com/u/1500684" width="150px;" alt="No Github Account"/><br /><sub><b>No Github Account</b></sub><br /><a href="#translation" title="Translation">🌍</a>'

expect(formatContributor(options, contributor)).toBe(expected)
})
2 changes: 1 addition & 1 deletion src/generate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function injectListBetweenTags(newContent) {
}

function formatLine(contributors) {
return `<td align="center">${contributors.join('</td><td>')}</td>`
return `<td align="center">${contributors.join('</td><td align="center">')}</td>`
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`create contributors section if content is empty 1`] = `
"
## Contributors
## Contributors
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Expand All @@ -17,7 +17,7 @@ exports[`create contributors section if it is absent 1`] = `
"# project
Description
## Contributors
## Contributors
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Expand Down
20 changes: 20 additions & 0 deletions src/init/__tests__/add-contributors-list.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {unlink} from 'fs'
import {addContributorsList} from '../init-content'
import ensureFileExists from '../file-exist'

test('insert list under contributors section', () => {
const content = [
Expand Down Expand Up @@ -27,3 +29,21 @@ test('create contributors section if content is empty', () => {

expect(result).toMatchSnapshot()
})

test('README exists', done => {
const file = 'README.md'
ensureFileExists(file)
.then(data => expect(data).toStrictEqual(file))
.then(_ => done())
})

test("LOREM doesn't exists", done => {
const file = 'LOREM.md'
ensureFileExists(file).then(data => {
expect(data).toStrictEqual(file)
return unlink(file, err => {
if (err) throw err
done()
})
})
})
39 changes: 39 additions & 0 deletions src/init/commit-conventions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const conventions = {
angular: {
name: 'Angular',
msg: 'docs:',
lowercase: true,
transform(msg) {
return msg.replace(
/(^.*?) ([A-Z][a-z]+) \w*/,
(_, ...words) => `${words[0]} ${words[1].toLowerCase()} `,
)
},
},
atom: {
name: 'Atom',
msg: ':memo:',
},
ember: {
name: 'Ember',
msg: '[DOC canary]',
},
eslint: {
name: 'ESLint',
msg: 'Docs:',
},
jshint: {
name: 'JSHint',
msg: '[[DOCS]]',
},
none: {
name: 'None',
msg: '',
},
}

Object.keys(conventions).forEach(style => {
conventions[style].value = style
})

module.exports = conventions
11 changes: 11 additions & 0 deletions src/init/file-exist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const fs = require('fs')

module.exports = function ensureFileExists(file) {
return new Promise((resolve, reject) => {
if (fs.existsSync(file)) return resolve(file)
fs.writeFile(file, '', err => {
if (err) reject(err)
resolve(file)
})
})
}
4 changes: 4 additions & 0 deletions src/init/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const util = require('../util')
const prompt = require('./prompt')
const initContent = require('./init-content')
const ensureFileExists = require('./file-exist')

const configFile = util.configFile
const markdown = util.markdown
Expand All @@ -13,6 +14,9 @@ module.exports = function init() {
return prompt().then(result => {
return configFile
.writeConfig('.all-contributorsrc', result.config)
.then(() => {
ensureFileExists(result.contributorFile)
})
.then(() =>
injectInFile(result.contributorFile, initContent.addContributorsList),
)
Expand Down
2 changes: 1 addition & 1 deletion src/init/init-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function addContributorsList(lines) {
const insertionLine = findContributorsSection(lines)
if (insertionLine === -1) {
return lines.concat([
'## Contributors',
'## Contributors',
'',
headerContent,
'',
Expand Down
17 changes: 15 additions & 2 deletions src/init/prompt.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const _ = require('lodash/fp')
const inquirer = require('inquirer')
const git = require('../util').git
const conventions = require('./commit-conventions')

const questions = [
{
Expand Down Expand Up @@ -32,7 +33,8 @@ const questions = [
{
type: 'input',
name: 'repoHost',
message: 'Where is the repository hosted? Hit Enter if it\'s on GitHub or GitLab',
message:
"Where is the repository hosted? Hit Enter if it's on GitHub or GitLab",
default: function(answers) {
if (answers.repoType === 'github') {
return 'https://github.com'
Expand Down Expand Up @@ -77,9 +79,19 @@ const questions = [
'Do you want this badge to auto-commit when contributors are added?',
default: true,
},
{
type: 'list',
name: 'commitConvention',
message: 'What commit convention would you want it to use?',
choices: Object.values(conventions),
default: 'none',
},
]

const uniqueFiles = _.flow(_.compact, _.uniq)
const uniqueFiles = _.flow(
_.compact,
_.uniq,
)

module.exports = function prompt() {
return git
Expand All @@ -101,6 +113,7 @@ module.exports = function prompt() {
files: uniqueFiles([answers.contributorFile, answers.badgeFile]),
imageSize: answers.imageSize,
commit: answers.commit,
commitConvention: answers.commitConvention,
contributors: [],
contributorsPerLine: 7,
linkToUsage: true,
Expand Down
24 changes: 24 additions & 0 deletions src/repo/__tests__/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,30 @@ test('handle errors', async () => {
await rejects(getUserInfo('nodisplayname'))
})

test('Throw error when no username is provided', () => {
expect(getUserInfo).toThrow(
'No login when adding a contributor. Please specify a username.',
)
})

test('Throw error when non existent username is provided', async () => {
const username = 'thisusernamedoesntexist'
nock('https://api.github.com')
.get(`/users/${username}`)
.reply(404, {
message: 'Not Found',
documentation_url:
'https://developer.github.com/v3/users/#get-a-single-user',
})
try {
await getUserInfo(username)
} catch (error) {
expect(error.message).toEqual(
`Login not found when adding a contributor for username - ${username}.`,
)
}
})

test('handle github errors', async () => {
nock('https://api.github.com')
.get('/users/nodisplayname')
Expand Down
Loading

0 comments on commit 3740e57

Please sign in to comment.