Reputation: 43113
So, I have a 'development blog' in a rails app I'm working on right now. I'm using Git for version control and deployment (although right now I'm the only person working on it).
Now, when I make changes in Git I put a pretty decent log entry about what I've done. I'd love to have the Git commit log automatically posted to the development blog -- or otherwise available for others to read within the deployed site.
Is there an automated way to pull the Git Commit Log into a view in a rails app?
Upvotes: 5
Views: 1506
Reputation: 13724
I added a Capistrano task to do something similar:
deploy.rb
namespace :deploy do
desc <<-DESC
Updates info.html with build and deploy info
DESC
task :timestamp do
run "cd #{current_path}; printf '<pre>\\nDeployed on: %s\\n\\n%s\\n</pre>' \"`date`\" \"`git log -n 1`\" > public/info.html"
end
end
after "deploy", "deploy:timestamp"
I just show the last commit, but you could alter the git log command to show whatever you wanted.
Upvotes: 1
Reputation: 13056
You may want to look into grit which is a ruby library that gives access to stuff in a git repo.
I'm using grit in my personal blog. I write articles in text files and commit them to a git repo, then push the git repo to my server where my rails app reads files from git repo as blog posts using grit.
For example, here's how easy it is to get the last commit message:
require 'grit'
include Grit
repo = Repo.new('<path to your .git dir>')
puts repo.commits('master',1)[0].message # latest commit message
puts repo.commits('master',1)[0].date # last commit date
Upvotes: 4
Reputation: 40961
Some Git hosts will allow you to provide a post commit hook, and this can enable you to make an HTTP call to send the relevant log statements to your app.
If you're self-hosting, check out githooks.
If you're using Github, you can use their post-commit post (more details here: http://help.github.com/post-receive-hooks/)
Upvotes: 7