Skip to content

Commit

Permalink
Improve origin URL parsing
Browse files Browse the repository at this point in the history
Fixes #2 and fixes #5
  • Loading branch information
cookpete committed Sep 9, 2016
1 parent 74d413e commit bfdfc0a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"dependencies": {
"array.prototype.find": "^2.0.0",
"commander": "^2.9.0",
"parse-github-url": "^0.3.2",
"semver": "^5.1.0"
},
"devDependencies": {
Expand Down
12 changes: 6 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { readFile, writeFile } from 'fs'
import commander from 'commander'
import parseRepoURL from 'parse-github-url'

import { version } from '../package.json'
import { cmd } from './utils'
Expand Down Expand Up @@ -30,13 +31,12 @@ function getCommits () {
return cmd(`git log --shortstat --pretty=format:${LOG_FORMAT}`).then(parseCommits)
}

function getOrigin () {
return cmd('git remote show origin').then(origin => {
const match = origin.match(/https:\/\/github.com\/[^\/]+\/[^\.]+/)
if (!match) {
function parseOrigin () {
return cmd('git config --get remote.origin.url').then(origin => {
if (!origin) {
throw new Error('Must have a git remote called origin')
}
return match[0]
return parseRepoURL(origin)
})
}

Expand Down Expand Up @@ -74,6 +74,6 @@ function error (error) {
throw new Error(error)
}

const promises = [ getCommits(), getOrigin(), getPackageVersion() ]
const promises = [ getCommits(), parseOrigin(), getPackageVersion() ]

Promise.all(promises).then(generateLog).then(success, error)
2 changes: 1 addition & 1 deletion src/templates/Default.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class Default {
listSpacing = '\n\n';

constructor (origin) {
this.origin = origin
this.origin = `https://${origin.host}/${origin.repo}`
};

render = (releases) => {
Expand Down
5 changes: 4 additions & 1 deletion test/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import changelogDefault from './data/changelog-default'
import changelogCompact from './data/changelog-compact'
import templates from '../src/templates'

const origin = 'https://github.com/user/repo'
const origin = {
host: 'github.com',
repo: 'user/repo'
}

describe('Template', () => {
it('renders using default template', () => {
Expand Down

0 comments on commit bfdfc0a

Please sign in to comment.