-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
269 additions
and
60 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"cSpell.words": [ | ||
"asdavis", | ||
"coverallsapp", | ||
"oclif", | ||
"octokit", | ||
|
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,20 @@ | ||
class Octokit { | ||
constructor(auth) { | ||
this.token = auth; | ||
this.issues = { | ||
listForRepo: ({ owner }) => { | ||
const issues = { | ||
'stdavis': ['stdavis issues'], | ||
'asdavis': ['asdavis issues'] | ||
}; | ||
|
||
return { | ||
data: issues[owner] | ||
}; | ||
} | ||
}; | ||
} | ||
} | ||
|
||
|
||
module.exports = { Octokit }; |
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,24 @@ | ||
module.exports = (packageName) => { | ||
const packages = { | ||
dep1: { | ||
repository: { | ||
url: 'https://github.com/stdavis/a-good-module' | ||
} | ||
}, | ||
dep2: { | ||
repository: { | ||
url: 'https://github.com/asdavis/another-good-module' | ||
} | ||
}, | ||
devDep1: {}, | ||
devDep2: { | ||
repository: {} | ||
}, | ||
noRepoUrl: { | ||
repository: {} | ||
}, | ||
noRepo: {} | ||
}; | ||
|
||
return packages[packageName]; | ||
}; |
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,12 @@ | ||
module.exports = () => { | ||
return { | ||
dependencies: { | ||
dep1: '^1.0.1', | ||
dep2: '1.0.2' | ||
}, | ||
devDependencies: { | ||
devDep1: '^5.0.0', | ||
devDep2: '3.0.0' | ||
} | ||
}; | ||
}; |
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
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 |
---|---|---|
@@ -1,5 +1,31 @@ | ||
describe('sanity', () => { | ||
it('works', () => { | ||
expect(true).toBeTruthy(); | ||
const { test } = require('@oclif/test'); | ||
const getToken = require('./authentication'); | ||
const { getCurrentProjectDependencies } = require('./packages'); | ||
const { getIssues, processIssues } = require('./issues'); | ||
const cmd = require('..'); | ||
|
||
|
||
jest.mock('./authentication'); | ||
getToken.mockResolvedValue('token'); | ||
jest.mock('./packages'); | ||
getCurrentProjectDependencies.mockResolvedValue({ | ||
dep1: '^1.1.1', | ||
dep2: '^2.2.2' | ||
}); | ||
jest.mock('./issues'); | ||
getIssues.mockResolvedValue({}); | ||
|
||
describe('index', () => { | ||
beforeEach(() => { | ||
}); | ||
|
||
test | ||
.stdout() | ||
.do(() => cmd.run([])) | ||
.it('calls all functions', () => { | ||
expect(getToken).toHaveBeenCalled(); | ||
expect(getCurrentProjectDependencies).toHaveBeenCalled(); | ||
expect(getIssues).toHaveBeenCalled(); | ||
expect(processIssues).toHaveBeenCalled(); | ||
}); | ||
}); |
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,65 @@ | ||
const { Octokit } = require('@octokit/rest'); | ||
const parseGitHubUrl = require('parse-github-url'); | ||
const { getRepoUrl } = require('./packages'); | ||
|
||
const getIssues = async (dependencies, token) => { | ||
/* | ||
dependencies: { dep: <version string>, dep2: <version string> } | ||
*/ | ||
const octokit = new Octokit({ | ||
auth: token | ||
}); | ||
|
||
const issues = {}; | ||
for (const packageName in dependencies) { | ||
if (Object.prototype.hasOwnProperty.call(dependencies, packageName)) { | ||
console.log(packageName); | ||
const repoUrl = await getRepoUrl(packageName, dependencies[packageName]); | ||
|
||
if (repoUrl) { | ||
const { owner, name } = parseGitHubUrl(repoUrl); | ||
const issueList = await octokit.issues.listForRepo({ | ||
owner, | ||
repo: name, | ||
state: 'open', | ||
updated: 'updated', | ||
direction: 'desc' | ||
}); | ||
|
||
issues[packageName] = issueList.data; | ||
} else { | ||
console.log('no repository url found'); | ||
} | ||
} | ||
} | ||
|
||
return issues; | ||
}; | ||
|
||
const processIssues = (issues) => { | ||
/* | ||
issues: { dep: Issue[], dep2: Issue[] } | ||
*/ | ||
const isHelpWantedLabel = label => { | ||
return /help.wanted/.test(label.name.toLowerCase()); | ||
}; | ||
|
||
for (const packageName in issues) { | ||
if (Object.prototype.hasOwnProperty.call(issues, packageName)) { | ||
console.log(`${packageName}:`); | ||
|
||
issues[packageName].forEach(issue => { | ||
if (issue.labels.length && issue.labels.some(isHelpWantedLabel)) { | ||
console.log(`${issue.title} (${issue.labels.map(lbl => lbl.name).join(',')})`); | ||
console.log(issue.html_url); | ||
} | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
|
||
module.exports = { | ||
getIssues, | ||
processIssues | ||
}; |
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,43 @@ | ||
const { getIssues, processIssues } = require("./issues"); | ||
|
||
describe('issues', () => { | ||
describe('getIssues', () => { | ||
it('collects issues', async () => { | ||
const dependencies = { | ||
'dep1': '1.1.1', | ||
'dep2': '1.2.2' | ||
}; | ||
|
||
const result = await getIssues(dependencies, 'blah'); | ||
|
||
expect(result).toEqual({ | ||
'dep2': ['asdavis issues'], | ||
'dep1': ['stdavis issues'] | ||
}); | ||
}); | ||
}); | ||
|
||
describe('processIssues', () => { | ||
it('prints issues to the output', () => { | ||
processIssues({ | ||
dep1: [{ | ||
labels: [{ name: 'help wanted' }, { name: 'hello' }], | ||
title: 'issue title', | ||
html_url: 'https://someurl.com' | ||
}, { | ||
labels: [{ name: 'hello' }], | ||
title: 'issue title', | ||
html_url: 'https://someurl.com' | ||
}], | ||
dep2: [{ | ||
labels: [{ name: 'hello' }, { name: 'help-wanted' }], | ||
title: 'issue title two', | ||
html_url: 'https://someurl.com' | ||
}] | ||
}); | ||
|
||
// runs without exception | ||
expect(true).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
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,27 @@ | ||
const readPackage = require('read-pkg'); | ||
const packageInfo = require('package-json'); | ||
|
||
|
||
const getCurrentProjectDependencies = async () => { | ||
const packageJson = await readPackage(); | ||
|
||
return { | ||
...packageJson.dependencies, | ||
...packageJson.devDependencies | ||
}; | ||
}; | ||
|
||
const getRepoUrl = async (packageName, version) => { | ||
const info = await packageInfo(packageName, { | ||
version: version, | ||
fullMetadata: true | ||
}); | ||
|
||
return (info.repository && info.repository.url) ? info.repository.url : null; | ||
}; | ||
|
||
|
||
module.exports = { | ||
getCurrentProjectDependencies, | ||
getRepoUrl | ||
}; |
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,27 @@ | ||
const { getRepoUrl, getCurrentProjectDependencies } = require('./packages'); | ||
|
||
|
||
describe('packages', () => { | ||
describe('getRepoUrl', () => { | ||
it('returns the url', async () => { | ||
expect(await getRepoUrl('dep2', '1.1.1')).toBe('https://github.com/asdavis/another-good-module'); | ||
}); | ||
it('returns null if no repo or url', async () => { | ||
expect(await getRepoUrl('noRepo', '1.1.1')).toBeNull(); | ||
expect(await getRepoUrl('noRepoUrl', '1.1.1')).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('getCurrentProjectDependencies', () => { | ||
it('combines deps and dev deps', async () => { | ||
const expected = { | ||
dep1: '^1.0.1', | ||
dep2: '1.0.2', | ||
devDep1: '^5.0.0', | ||
devDep2: '3.0.0' | ||
}; | ||
|
||
expect(await getCurrentProjectDependencies()).toEqual(expected); | ||
}); | ||
}); | ||
}); |