문제

How can you automatically import the latest github commit number from github?

The goal would be to have that number visible on your webpage footer like SO does with date.

Whats the structure:

I have a production branch which is deployed using Capistrano. I want to show the latest github commit number, with the date when it was deployed.

도움이 되었습니까?

해결책

Assuming you use gem settingslogic for app settings, put this in your initializers:

git_log = `git log -1 --pretty="format:%H %ci"`
if git_log =~ /^([\d\w]+?)\s(.+)$/
  Settings[:git_revision] = $1
  Settings[:git_update]   = $2.strip
end

You will have last git commit SHA in Settings.git_revision and commit date in Settings.git_update.

Additionally you can get last tag:

git_tag = `git describe --tags --abbrev=0`
Settings[:git_tag] = git_tag.strip if git_tag

It will be available in Settings.git_tag.

Update:

I released a small ruby gem git-revision. With it you can simply do:

"commit: #{Git::Revision.commit} date: #{Git::Revision.date}"

다른 팁

As possible solution you can to see at (universal) solution with git smudge|clean filters (read "Keyword Expansion" part)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top