-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add node api for AllContributors GitHub bot (#135)
- Loading branch information
Showing
7 changed files
with
106 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
"bin": { | ||
"all-contributors": "dist/cli.js" | ||
}, | ||
"main": "dist/api.js", | ||
"files": [ | ||
"dist" | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// All Contributors Node JS API | ||
// This is not yet ready for main-stream usage, API implementation may change at any time without warning | ||
// 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 addContributorWithDetails = require('./contributors/addWithDetails') | ||
const generate = require('./generate') | ||
|
||
process.stdout.write( | ||
chalk.yellow( | ||
`${chalk.bold( | ||
'WARNING', | ||
)} :: Using the all-contributors node-api comes with zero guarantees of stability and may contain breaking changes without warning\n`, | ||
), | ||
) | ||
|
||
module.exports = { | ||
addContributorWithDetails, | ||
generate, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import addContributorWithDetails from '../addWithDetails' | ||
import fixtures from './fixtures' | ||
|
||
test('add new contributor without going to the network', async () => { | ||
const {options} = fixtures() | ||
const userDetails = { | ||
login: 'jakebolam', | ||
contributions: ['code', 'security'], | ||
name: 'Jake Bolam', | ||
avatar_url: 'my-avatar.example.com', | ||
profile: 'jakebolam.com', | ||
} | ||
|
||
const contributors = await addContributorWithDetails({ | ||
options, | ||
login: userDetails.login, | ||
contributions: userDetails.contributions, | ||
name: userDetails.name, | ||
avatar_url: userDetails.avatar_url, | ||
profile: userDetails.profile, | ||
}) | ||
|
||
expect(contributors.length).toBe(options.contributors.length + 1) | ||
expect(contributors[options.contributors.length]).toEqual(userDetails) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[ | ||
{ | ||
"login": "login1", | ||
"name": "Some name", | ||
"avatar_url": "www.avatar.url", | ||
"profile": "www.profile.url", | ||
"contributions": ["code"] | ||
}, | ||
{ | ||
"login": "login2", | ||
"name": "Some name", | ||
"avatar_url": "www.avatar.url", | ||
"profile": "www.profile.url", | ||
"contributions": [ | ||
{ | ||
"type": "blog", | ||
"url": "www.blog.url/path" | ||
}, | ||
"code" | ||
] | ||
}, | ||
{ | ||
"name": "Missing Login", | ||
"avatar_url": "www.avatar.url", | ||
"profile": "www.profile.url", | ||
"contributions": ["code"] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import contributors from './contributors.json' | ||
|
||
export default function fixtures() { | ||
const options = { | ||
contributors, | ||
} | ||
return {options} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const addContributor = require('./add') | ||
|
||
// Adds a contributor without going to the network (you supply the additional fields) | ||
module.exports = function addContributorWithDetails({ | ||
options, | ||
login, | ||
contributions, | ||
name, | ||
avatar_url, | ||
profile, | ||
}) { | ||
const infoFetcherNoNetwork = function() { | ||
return Promise.resolve({ | ||
login, | ||
name, | ||
avatar_url, | ||
profile, | ||
}) | ||
} | ||
return addContributor(options, login, contributions, infoFetcherNoNetwork) | ||
} |