Skip to content

Instantly share code, notes, and snippets.

@brandonsheppard
Last active December 28, 2017 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandonsheppard/548a4cff7bc1a63e69397cb82269405b to your computer and use it in GitHub Desktop.
Save brandonsheppard/548a4cff7bc1a63e69397cb82269405b to your computer and use it in GitHub Desktop.
Format release notes MD from JSON.

formatNotes()

Pass commit data into this function to format a markdown commit note. Data structure is based on what Github's compare endpoint returns.

This is useful for generating a changelog for release notes based on git activity.

Example data:

Based on response from Github's compareCommits endpoint.

var dataExample = [{
	author: {
		login: 'brandonsheppard',
		html_url: 'https://github.com/brandonsheppard'
	},
	commit: {
		message: 'Etiam porta sem malesuada magna mollis euismod.'
	},
	sha: '685eb53d517a335d0d7a654472c9553679161ec8',
	html_url: 'https://github.com/my_repository/685eb53d517a335d0d7a654472c9553679161ec8'
},{
	author: {
		login: 'philconnah',
		html_url: 'https://github.com/philconnah'
	},
	commit: {
		message: 'Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.'
	},
	sha: 'e34784dcbc43873c6900803db2e29c3555830e59',
	html_url: 'https://github.com/my_repository/e34784dcbc43873c6900803db2e29c3555830e59'
}]

formatNotes(dataExample)

Example output:

- [brandonsheppard](https://github.com/brandonsheppard) Etiam porta sem malesuada magna mollis euismod. [685eb53d517a335d0d7a654472c9553679161ec8](https://github.com/my_repository/685eb53d517a335d0d7a654472c9553679161ec8)
- [philconnah](https://github.com/philconnah) Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. [e34784dcbc43873c6900803db2e29c3555830e59](https://github.com/my_repository/e34784dcbc43873c6900803db2e29c3555830e59)

Source

function formatNotes(data){
	return data.map(commit => `- [${commit.author.login}](${commit.author.html_url}) ${commit.commit.message} [${commit.sha}](${commit.html_url})`).join('\n')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment