aboutsummaryrefslogtreecommitdiffstats
path: root/tool/gen-github-release.rb
blob: 4d8c2910f4932c2cd8d5b66a3f4805d4c0cdb197 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env ruby

if ARGV.size < 2
  puts "Usage: #{$0} <from version tag> <to version tag> [--no-dry-run]"
  puts "     : if --no-dry-run is specified, it will create a release on GitHub"
  exit 1
end

require "bundler/inline"

gemfile do
  source "https://rubygems.org"
  gem "octokit"
  gem "faraday-retry"
  gem "nokogiri"
end

require "open-uri"

Octokit.configure do |c|
  c.access_token = ENV['GITHUB_TOKEN']
  c.auto_paginate = true
  c.per_page = 100
end

client = Octokit::Client.new

note =  "## What's Changed\n\n"

diff = client.compare("ruby/ruby", ARGV[0], ARGV[1])
diff[:commits].each do |c|
  if c[:commit][:message] =~ /\[Backport #(\d*)\]/
    url = "https://bugs.ruby-lang.org/issues/#{$1}"
    title = Nokogiri::HTML(URI.open(url)).title
    title.gsub!(/ - Ruby master - Ruby Issue Tracking System/, "")
  elsif c[:commit][:message] =~ /\(#(\d*)\)/
    url = "https://github.com/ruby/ruby/pull/#{$1}"
    title = Nokogiri::HTML(URI.open(url)).title
    title.gsub!(/ · ruby\/ruby · GitHub/, "")
  else
    next
  end
  note << "* [#{title}](#{url})\n"
rescue OpenURI::HTTPError
  puts "Error: #{url}"
end

note << "\n"
note << "Note: This list is automatically generated by tool/gen-github-release.rb. Because of this, some commits may be missing.\n\n"
note << "## Full Changelog\n\n"
note << "https://github.com/ruby/ruby/compare/#{ARGV[0]}...#{ARGV[1]}\n\n"

if ARGV[2] == "--no-dry-run"
  name = ARGV[1].gsub(/v/, "").gsub(/_/, ".")
  client.create_release("ruby/ruby", ARGV[1], name: name, body: note)
  puts "Created a release: https://github.com/ruby/ruby/releases/tag/#{ARGV[1]}"
else
  puts note
end