Howto Display a GitHub Changelog in your application

June 27th, 2009

In this post I will show you a simple way to display a list of your GitHub changes inside your application.


github_changes_screenshot


This can be useful for so many reasons, not least helping to create a better relationship between your users and your developers. This obviously would not be applicable in all circumstances, but in many cases, having a Changelog inside your application (especially where the end users already work closely with the application developers) can enable them to see what work has been done, and what new features are available to them. This is also fantastically useful for allowing Project managers to keep track of development changes.

The code below will pull out the last 20 GitHub commit comments from your GitHub project, and display them in a table, and with a bit of CSS styling will look something like the screenshot above, or better!

<table border="0" width="100%">
<tr>
<th>When</th>
<th>Description</th>
</tr>
<% recent_website_changes = `git log -20 --abbrev-commit --pretty=format:"%H %cr - %s"` rescue ""
recent_website_changes.split(/\n/).each do |ln|
    commit_code = ln.split(/ /)[0]
    without_commit = ln.gsub("#{commit_code} ", "")
    commit_time = without_commit.split(/ - /)[0]
    message = without_commit.gsub("#{commit_time} - ", "") %>
    <tr>
    <td><%= commit_time %></td>
    <td><%= message %></td>
    <td><%= link_to('view', "https://github.com/your-github-username/your-project-name/commit/#{commit_code}") %></td>
    </tr>
<% end %>
</table>



Another advantage of displaying your commit log publicly to other non-developers is that it can incentivize your developers to think carefully about writing better commit messages, knowing they will have to be read by others.

Categories: GitHub, Rails

Tags: , , , , , Leave a comment

Like This Post?

Subscribe for more...

2 Comments

  1. Nick Quaranto

    This is a neat idea, but there’s no way a high traffic web site could handle shelling out commands every time the view is rendered, and doing complex logic like that is completely untested smells of horrible coding practices.

    Clean this up and get it in a plugin or gem, perhaps using Grit (http://github.com/mojombo/grit) and it’ll definitely be useful to many projects.

  2. admin

    Hi Nick, If this code were on a sufficiently high-traffic page then I would opt to use fragment caching. Admittedly, it does look a little untidy, maybe a re-factor will be in order in future.

Feed

http://www.mendable.com / Howto Display a GitHub Changelog in your application