Skip to content

Instantly share code, notes, and snippets.

@briandoll
Last active March 19, 2022 01:17

Revisions

  1. Brian Doll renamed this gist Jan 23, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Brian Doll renamed this gist Jan 23, 2013. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion _README.md → a_toast_to_you.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    **To toast:**

    * Make sure you have ImageMagick installed (`brew install imagemagick`)
  3. Brian Doll created this gist Jan 23, 2013.
    5 changes: 5 additions & 0 deletions Gemfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    source "http://rubygems.org"

    gem "octokit"
    gem "awesome_print"
    gem "gifme"
    14 changes: 14 additions & 0 deletions _README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@

    **To toast:**

    * Make sure you have ImageMagick installed (`brew install imagemagick`)
    * Change line 7 of toast.rb to the repository name you're working with
    * toast!

    ```
    $ bundle install
    $ ./get_token [user] [pass]
    $ export GHUSER=[myuser]
    $ export GHTOKEN=[token]
    $ bundle exec ./toast.rb
    ```
    4 changes: 4 additions & 0 deletions get_token.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    # sh get_token.sh user pass
    curl -s -d '{"scopes":["repo"],"note":"toast script"}' -u "$1:$2" -XPOST https://api.github.com/authorizations | grep token
    echo 'export GHUSER=[youruser]'
    echo 'export GHTOKEN=[above-token]'
    47 changes: 47 additions & 0 deletions toast.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    #! /usr/bin/env ruby
    require 'octokit'
    require 'awesome_print'
    require 'open-uri'

    client = Octokit::Client.new(:login => ENV['GHUSER'], :oauth_token => ENV['GHTOKEN'])
    repo = 'username/reponame' # change to the repository you want to gifify

    Dir.mkdir('build') if !File.exists?('build')

    def build_issue(client, repo, number)
    comments = client.issue_comments(repo, number)
    num = 0
    comments.each do |comment|
    if m = comment.body.match(/\!\[(.*?)\]\((.*?)\)/)
    Dir.mkdir("build/#{number}") if !File.exists?("build/#{number}")

    uri = m[2]
    puts " getting #{uri}"
    open(uri) do |f|
    num += 1
    ext = 'png'
    ext = 'jpg' if f.content_type == 'image/jpeg'
    file = "#{num}.#{ext}"
    s = File.open("build/#{number}/#{file}", "w+")
    s.write(f.read)
    s.close
    end
    end
    end
    Dir.chdir("build/#{number}") do
    puts " building gif"
    `gifme -o toast.gif *`
    end
    file = "build/#{number}/toast.gif"
    if File.exists?(file)
    return file
    else
    return false
    end
    end

    toasts = client.list_issues(repo)
    toasts.each do |issue|
    puts "Building ##{issue.number}: '#{issue.title}'"
    build_issue(client, repo, issue.number)
    end