This repository has been archived by the owner on Sep 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathchangelog.rake
70 lines (64 loc) · 1.98 KB
/
changelog.rake
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
60
61
62
63
64
65
66
67
68
69
70
# Used constants:
# none
namespace :changelog do
desc 'Add the empty CHANGELOG entries after a new release'
task :reset do |task|
changelog = File.read('CHANGELOG.md')
abort('A Master entry already exists') if changelog =~ /^##\s*Master$/
changelog.sub!(/^##[^#]/, "#{header}\\0")
File.write('CHANGELOG.md', changelog)
end
def header
return <<-HEADER.gsub(/^\s*\|/,'')
|## Master
|
|### Bug Fixes
|
|_None_
|
|### Breaking Changes
|
|_None_
|
|### New Features
|
|_None_
|
|### Internal Changes
|
|_None_
|
HEADER
end
desc 'Check if links to issues and PRs use matching numbers between text & link'
task :check do |task|
current_repo = File.basename(`git remote get-url origin`.chomp, '.git').freeze
slug_re = '([a-zA-Z]*/[a-zA-Z]*)'
links = %r{\[#{slug_re}?\#([0-9]+)\]\(https://github.com/#{slug_re}/(issues|pull)/([0-9]+)\)}
all_wrong_links = []
File.readlines('CHANGELOG.md').each_with_index do |line, idx|
wrong_links = line.scan(links)
.reject do |m|
(slug, num, url_slug, url_num) = [m[0] || "SwiftGen/#{current_repo}", m[1], m[2], m[4]]
(slug == url_slug) && (num == url_num)
end.map do |m|
" - Line #{idx+1}, link text is #{m[0]}##{m[1]} but links points to #{m[2]}##{m[4]}"
end
all_wrong_links.concat(wrong_links)
end
if all_wrong_links.empty?
puts "\u{2705} All links correct"
else
puts "\u{274C} Some wrong links found:\n" + all_wrong_links.join("\n")
end
end
desc "Push the CHANGELOG's top section as a GitHub release"
task :push_github_release do
require 'octokit'
client = Utils.octokit_client
tag = Utils.top_changelog_version
body = Utils.top_changelog_entry
repo_name = File.basename(`git remote get-url origin`.chomp, '.git').freeze
client.create_release("SwiftGen/#{repo_name}", tag, :body => body)
end
end