Skip to content

Instantly share code, notes, and snippets.

@nownabe
Last active October 24, 2016 03:25
Show Gist options
  • Save nownabe/f05d894291aa050187c5a3ecd86d5ece to your computer and use it in GitHub Desktop.
Save nownabe/f05d894291aa050187c5a3ecd86d5ece to your computer and use it in GitHub Desktop.
Change Log生成
#!/usr/bin/env ruby
$LOAD_PATH.unshift("../../lib", __FILE__)
require "./runner"
Takoyaki::Runner.new(ARGV).run
# frozen_string_literal: true
require "yaml"
require "octokit"
module Takoyaki
class Runner
TOKEN = "yourtoken"
attr_reader :to, :from
def initialize(args = [])
@args = args
# [to, from)
now = Time.now
to = now + 24 * 60 * 60
@to = Time.new(to.year, to.month, to.day)
from = to - 7 * 24 * 60 * 60
@from = Time.new(from.year, from.month, from.day)
end
def output_change_log(repo)
puts "# #{repo}"
changes = Hash.new { |h, k| h[k] = [] }
page = 0
loop do
res = client.releases(repo, per_page: 100, page: page)
res.each do |release|
next if release.prerelease
pr_num = release.name.split("-").last
published_at = release.published_at.localtime
if from <= published_at && published_at < to
changes[published_at.strftime("%Y-%m-%d")] << client.pull_request(repo, pr_num)
end
end
break if res.last.published_at < from
page += 1
end
changes.each do |date, changes|
puts "## #{date}"
changes.each do |pr|
assignees = pr.assignees ? pr.assignees : [pr.assignee]
puts "* [#{pr.title}](#{pr.html_url}) by #{assignees.map(&:login).join(", ")}"
end
puts
end
end
def run
%w(nownabe/project1 nownabe/project2).each do |repo|
output_change_log(repo)
end
end
def client
@client ||= Octokit::Client.new(access_token: TOKEN)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment