ruby 使用lolcommits生成一个gif。将gif上传到您的GitHub仓库。修改您的提交消息以包含gif的链接。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 使用lolcommits生成一个gif。将gif上传到您的GitHub仓库。修改您的提交消息以包含gif的链接。相关的知识,希望对你有一定的参考价值。

#Retrieve your most recent git commit hash and message.
#Anything inside backticks will execute as a command in your shell
#The backtick is located above the tab key on your keyboard
commit = `git log -1 --oneline`

#Isolate the hash and the message.
hash = commit.to_s.split(" ").first 
message = commit.sub("#{hash} ", "")

#Unless the commit message already has a link to a gif...
unless(message.gsub("\n","").end_with?(".gif"))

  #Create a gif with lolcommits!
  `lolcommits --capture --animate=3`
 
  #Find the path to your present working directory, the location
  #of your repo on GitHub, your present working directory name
  #and the path to which Lolcommits saves your gifs.
  repopath = `git rev-parse --show-toplevel`.gsub("\n", "")
  repourl = `git config --get remote.origin.url`.gsub("\n", "")
  reponame = "#{`basename #{repopath}`.to_s}".gsub("\n", "")
  path = "#{File.expand_path('~')}/.lolcommits/#{reponame}/"
 
  #Find the gif with a filename that begins with your latest
  #commit hash and create a directory in your repo for storing
  #lols and copy in the gif
  @filename = nil
  Dir.open(path).each do |filename|
    if filename.start_with?(hash)
      image = path + filename
      system("mkdir #{repopath}/lolcommits")
      `cp #{image} #{repopath}/lolcommits/#{filename}`
      @filename = filename
    end
  end
	
  #Grab your username and repo name, assemble the url GitHub
  #will save the gif to git add the gif and git commit with
  #an amended message
  unless @filename == nil
    githubstuff = repourl.gsub("git@github.com:","").gsub(".git","").gsub("https://github.com/","")
    github_image_url = "https://github.com/#{githubstuff}/blob/master/lolcommits/#{@filename}"
    `git add #{repopath}/lolcommits/#{@filename}`
    `git commit --amend --no-verify -m "#{message} #{github_image_url}"`
  end
  
end

以上是关于ruby 使用lolcommits生成一个gif。将gif上传到您的GitHub仓库。修改您的提交消息以包含gif的链接。的主要内容,如果未能解决你的问题,请参考以下文章

如何使用python生成gif

使用 Shrine 和 MiniMagick 将 GIF 转换为 JPEG

Python 批量处理图片,生成gif动图

前端直接生成GIF动态图实践

PIL Gif 生成未按预期工作

一键生成 Android 录屏 gif 的脚本