Last active
April 4, 2020 11:41
-
-
Save dsander/f9e9a0a4043415bc108e76157674e8de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# OCTOKIT_ACCESS_TOKEN=yourtoken ruby huginn_changelog.rb | |
require 'json' | |
require 'octokit' | |
require 'rugged' | |
AFTER_NUMBER = 2607 | |
pull_requests = unless File.exists?('pull_requests.dump') | |
Octokit.auto_paginate = true | |
pull_requests = Octokit.pull_requests('huginn/huginn', :state => 'closed', direction: 'asc') | |
File.open('pull_requests.dump', 'w').write(Marshal.dump(pull_requests)) | |
pull_requests | |
else | |
Marshal.load(File.read('pull_requests.dump')) | |
end | |
commits_from_pr = [] | |
changes = [] | |
class Change | |
attr_reader :date, :commit, :pr, :title | |
def initialize(date: nil, commit: nil, pr: nil, title: '') | |
@date = date | |
@commit = commit | |
@pr = pr | |
@title = title | |
end | |
def to_s | |
"| #{date.strftime('%b %d, %Y')} | #{title} #{link} |" | |
end | |
def link | |
if pr | |
"[#{pr}](https://github.com/huginn/huginn/pull/#{pr})" | |
else | |
"[#{commit[0..8]}](https://github.com/huginn/huginn/commit/#{commit})" | |
end | |
end | |
def <=>(other) | |
date <=> other.date | |
end | |
end | |
first_commit_date = nil | |
current_changelog = File.read('CHANGES.md') | |
pull_requests.each do |pr| | |
first_commit_date = pr[:merged_at] if pr[:number] == AFTER_NUMBER | |
next if pr[:number] <= AFTER_NUMBER | |
next if pr[:merged_at] == nil | |
next if current_changelog.include? "[#{pr[:number]}]" | |
changes << Change.new(date: pr[:merged_at], pr: pr[:number], title: pr[:title]) | |
if !File.exists?('commits_from_pr.dump') | |
commits_from_pr += Octokit.pull_request_commits('huginn/huginn', pr[:number]).map { |c| c[:sha] } | |
end | |
end | |
if File.exists?('commits_from_pr.dump') | |
commits_from_pr = Marshal.load(File.read('commits_from_pr.dump')) | |
else | |
File.open('commits_from_pr.dump', 'w').write(Marshal.dump(commits_from_pr)) | |
end | |
repo = Rugged::Repository.new(".") | |
walker = Rugged::Walker.new(repo) | |
walker = Rugged::Walker.new(repo).each do |commit| | |
next if commit.committed_date < first_commit_date | |
next if commits_from_pr.include? commit.id | |
next if commit.message.include? 'Merge pull request' | |
changes << Change.new(commit: commit.id, date: commit.committed_date, title: commit.message.split("\n").first.strip) | |
end | |
puts changes.sort.reverse.map(&:to_s).join("\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment