Embed Git Commit Log in Rails App?

So, I have a “development blog” in the rails application that I am currently working on. I use Git for version control and deployment (although now I'm the only person working on it).

Now that I make changes to Git, I put a pretty decent log entry about what I did. I would really like the Git commit log to be automatically posted to the development blog or made available to other users for reading on a deployed site.

Is there an automatic way to pull a Git Commit Log into a view in a rails application?

+4
source share
3 answers

Some Git hosts allow you to provide message commit bindings, and this may allow you to make an HTTP call to send the appropriate log statements to your application.

If you own your own hosting, check out githooks .

If you use Github, you can use post-commit post (more info here: http://help.github.com/post-receive-hooks/ )

+6
source

You can look at grit , which is a ruby ​​library that provides access to materials in the git repository.

I use grit on my personal blog. I write articles in text files and upload them to the git repository and then drag the git repository to my server, where my rails application 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 
+3
source

I added a Capistrano task to do something like this:

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 am just showing the last commit, but you can change the git log command to show everything you need.

+1
source

Source: https://habr.com/ru/post/1334294/


All Articles