Skip to content

Instantly share code, notes, and snippets.

@abishekk92
Created September 28, 2012 23:25
Show Gist options
  • Save abishekk92/3802577 to your computer and use it in GitHub Desktop.
Save abishekk92/3802577 to your computer and use it in GitHub Desktop.
Devlog for Octopress. Add the gist in your Rakefile to have octopress generate devlogs from your github activity. You can set up a cron job to do this automatically.
# usage rake devlog
desc "Creates devlog #{source_dir}/#{posts_dir}"
task :devlog do |t|
raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
mkdir_p "#{source_dir}/#{posts_dir}"
title = "Devlog #{Date.today-7} to #{Date.today}"
filename = "#{source_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.#{new_post_ext}"
if File.exist?(filename)
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
end
puts "Creating devlog: #{filename}"
open(filename, 'w') do |post|
post.puts "---"
post.puts "layout: post"
post.puts "title: \"#{title.gsub(/&/,'&')}\""
post.puts "date: #{Time.now.strftime('%Y-%m-%d %H:%M')}"
post.puts "comments: true"
post.puts "categories: devlog"
post.puts "---"
require 'open-uri'
require 'json'
uri="https://api.github.com/users/#{user_name}/events/public"
events_all=JSON.parse(open(uri).read)
PUSHED= "I pushed to"
CREATE= "I started working on"
FORK = "I am planning to contribute to"
events=events_all.select{|t| ((Date.today-7)..Date.today).include?(Date.parse(t['created_at']))}
events.each do |event|
repo_name=event['repo']['name']
repo_url= 'https://github.com/#{repo_name}'
commits = event['payload']['commits']
case event['type']
when 'PushEvent'
post.puts "* #{PUSHED} [#{repo_name}](#{repo_url})"
commits.each{|commit| post.puts " - [#{commit['message']}](#{commit['url']})"}
when 'CreateEvent'
post.puts "* #{CREATE} [#{repo_name}](#{repo_url}) which #{event['payload']['description'].downcase}"
when 'ForkEvent'
post.puts "* #{FORK} [#{repo_name}](#{repo_url})"
else
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment