Skip to content

Commit

Permalink
Fix(tests): renamed repo broke tests.
Browse files Browse the repository at this point in the history
Also added a test for our regexp parser.
  • Loading branch information
tgetgood committed Nov 2, 2017
1 parent d924d75 commit b59a656
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
1 change: 0 additions & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ const handleOut = console.log

const handleError = e => {
console.error(e.stack)

}

const callWithDefaults = (f, opts) => {
Expand Down
1 change: 0 additions & 1 deletion src/graphql.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const https = require('https')
const fs = require('fs')

/** Escape strings to prevent injection attacks. Other types aren't an issue. */
const escapeArgValue = val => {
Expand Down
21 changes: 12 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ const shellOut = command =>

const gitConfigCommand = 'git config --get remote.origin.url'

const parseGitURL = new RegExp('.*github\\.com[:/]([^/]+)\\/(.+)$')
const parseGitURLRE = new RegExp('.*github\\.com[:/]([^/]+)\\/(.+)$')

const parseGitURL = url => {
const parse = parseGitURLRE.exec(url.trim())
if (parse[2].endsWith('.git')) {
parse[2] = parse[2].substr(0, parse[2].length - 4)
}
return parse
}

const getCurrentRepoInfo = () => shellOut(gitConfigCommand)
.then(x => parseGitURL.exec(x.trim()))
.then(x => {
let repo = x[2]
if (repo.endsWith('.git')) {
repo = repo.substr(0, repo.length - 4)
}
return {user: x[1], repo}
})
.then(parseGitURL)
.then(x => {return {user: x[1], repo: x[2]}})

//
// CSV Output
Expand Down Expand Up @@ -115,6 +117,7 @@ const currentUser = token =>

module.exports = {
toCSV,
parseGitURL,
getCurrentRepoInfo,
currentUser,
repoContributors,
Expand Down
27 changes: 18 additions & 9 deletions test/integration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const contribPre = {
test('No contributions in a single second', t => {
return main.repoContributors({
token: token,
user: 'RichardLitt',
user: 'mntnr',
repo: 'name-your-contributors',
after: new Date('2016-01-01T15:21:08.104Z'),
before: new Date('2016-01-02T15:21:08.104Z')
Expand Down Expand Up @@ -63,7 +63,7 @@ const compareKeys = (x, k) =>
test('Contributors before a fixed date remain static', t => {
return main.repoContributors({
token: token,
user: 'RichardLitt',
user: 'mntnr',
repo: 'name-your-contributors',
before: new Date('2017-09-21'),
after: new Date(0)
Expand All @@ -77,17 +77,26 @@ test('Contributors before a fixed date remain static', t => {

test('Queries without tokens get rejected', t => {
return main.repoContributors({
user: 'RichardLitt',
user: 'mntnr',
repo: 'name-your-contributors',
before: new Date(),
after: new Date(0)
}).catch(error => t.is(error.message, 'Unauthorized'))
})

test('user repo names come back', async t => {
const repos = await main.userRepoNames({token, login: 'tgetgood'})

console.log(repos)

t.pass()
test('All sorts of valid GitHub URLS', async t => {
/* eslint-disable */
// Need to test tabs...
const urls = [
'git@github.com:RichardLitt/name-your-contributors.git',
'git@github.com:RichardLitt/name-your-contributors\n',
' https://github.com/RichardLitt/name-your-contributors ',
'https://github.com/RichardLitt/name-your-contributors '
]
/* eslint-enable */
for (let x of urls) {
let parse = main.parseGitURL(x)
t.is(parse[1], 'RichardLitt')
t.is(parse[2], 'name-your-contributors')
}
})

0 comments on commit b59a656

Please sign in to comment.