Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@
"homepage": "https://github.com/all-contributors/all-contributors-cli#readme",
"dependencies": {
"@babel/runtime": "^7.7.6",
"chalk": "^5.6.2",
"inquirer": "^7.3.3",
"json-fixer": "^1.6.8",
"lodash": "^4.11.2",
"node-fetch": "^2.6.0",
"pify": "^5.0.0",
"yargs": "^18.0.0"
"yargs": "^18.0.0",
"yoctocolors": "^2.1.2"
},
"devDependencies": {
"@babel/cli": "^7.26.0",
Expand Down
6 changes: 3 additions & 3 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
// This is to support adding contributors using the AllContributors GitHub Bot (see github.com/all-contributors/all-contributors-bot
// These Node API's are intended to be network and side effect free, everything should be in memory with no io to network/disk

const chalk = require('chalk')
const YoctoColors = require('yoctocolors')

const addContributorWithDetails = require('./contributors/addWithDetails')
const generate = require('./generate')
const {addContributorsList, addBadge} = require('./init/init-content')

process.stdout.write(
chalk.yellow(
`${chalk.bold(
YoctoColors.yellow(
`${YoctoColors.bold(
'WARNING',
)} :: Using the all-contributors node-api comes with zero guarantees of stability and may contain breaking changes without warning\n`,
),
Expand Down
44 changes: 27 additions & 17 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

const path = require('path')
const yargs = require('yargs/yargs')
const YoctoColors = require('yoctocolors')
const {hideBin} = require('yargs/helpers')
const chalk = require('chalk')
const inquirer = require('inquirer')

const init = require('./init')
Expand Down Expand Up @@ -70,14 +70,11 @@ function startGeneration(argv) {
}

async function addContribution(argv) {
// ensure the config file exists
await util.configFile.readConfig(argv.config)

const username = argv._[1] === undefined ? undefined : String(argv._[1])
const contributions = argv._[2]

// Add or update contributor in the config file
const data = updateContributors(argv, username, contributions)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Primary issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also another thing i missed in that original PR. I forgot the await here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh perfect. Justin, we can merge this FIRST, and then I'll rebase my tests pr against it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats what i was thinking!

const data = await updateContributors(argv, username, contributions)

argv.contributors = data.contributors

Expand All @@ -90,22 +87,20 @@ async function addContribution(argv) {
}

async function checkContributors(argv) {
const configData = await util.configFile.readConfig(argv.config)

return repo
.getContributors(
configData.projectOwner,
configData.projectName,
configData.repoType,
configData.repoHost,
argv.projectOwner,
argv.projectName,
argv.repoType,
argv.repoHost,
)
.then(repoContributors => {
const checkKey = repo.getCheckKey(configData.repoType)
const knownContributions = configData.contributors.reduce((obj, item) => {
const checkKey = repo.getCheckKey(argv.repoType)
const knownContributions = argv.contributors.reduce((obj, item) => {
obj[item[checkKey]] = item.contributions
return obj
}, {})
const knownContributors = configData.contributors.map(
const knownContributors = argv.contributors.map(
contributor => contributor[checkKey],
)

Expand All @@ -122,14 +117,17 @@ async function checkContributors(argv) {

if (missingInConfig.length) {
process.stdout.write(
chalk.bold('Missing contributors in .all-contributorsrc:\n'),
YoctoColors.bold('Missing contributors in .all-contributorsrc:\n'),
)
process.stdout.write(` ${missingInConfig.join(', ')}\n`)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were indenting missing members, but not unknown members. It looked weird, so i removed the indent

process.stdout.write(`${missingInConfig.join(', ')}\n`)
}

if (missingFromRepo.length) {
process.stdout.write('\n')
process.stdout.write(
chalk.bold('Unknown contributors found in .all-contributorsrc:\n'),
YoctoColors.bold(
'Unknown contributors found in .all-contributorsrc:\n',
),
)
process.stdout.write(`${missingFromRepo.join(', ')}\n`)
}
Expand Down Expand Up @@ -169,6 +167,18 @@ function promptForCommand(argv) {
async function run() {
try {
const argv = getArgs()

// Load and merge config file data into argv
try {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Secondary issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tldr; Original PR removed the .config prop of the yargs method because the docs mentioned it didnt support async functions.

What i forgot to do apparently, it replace it properly, so the config wasnt loaded like it should have been. This change fixes that correctly by loading the config on execution of the cli command.

const configData = await util.configFile.readConfig(argv.config)
Object.assign(argv, configData)
} catch (error) {
if (error instanceof SyntaxError || argv.config !== defaultRCFile) {
throw error
}
// If default config file doesn't exist, that's okay
}

const command = await promptForCommand(argv)

switch (command) {
Expand Down
4 changes: 1 addition & 3 deletions src/util/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const spawn = require('child_process').spawn
const _ = require('lodash/fp')
const pify = require('pify')
const conventions = require('../init/commit-conventions')
const {readConfig} = require('./config-file')

const commitTemplate =
'<%= prefix %> <%= (newContributor ? "Add" : "Update") %> @<%= username %> as a contributor'
Expand Down Expand Up @@ -58,8 +57,7 @@ async function commit(options, data) {
const absolutePathFiles = files.map(file => {
return path.resolve(process.cwd(), file)
})
const config = await readConfig(options.config)
const commitConvention = conventions[config.commitConvention]
const commitConvention = conventions[options.commitConvention]

return spawnGitCommand(['add'].concat(absolutePathFiles)).then(() => {
let commitMessage = _.template(options.commitTemplate || commitTemplate)({
Expand Down