This repository has been archived by the owner on May 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
import_confluence
executable file
·115 lines (91 loc) · 2.74 KB
/
import_confluence
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#! /usr/bin/env ruby
require 'bundler/setup'
require 'reverse_markdown'
require 'active_support/core_ext/string/inflections'
require 'active_support/core_ext/hash/except'
require 'active_support/core_ext/object/blank'
require_relative 'confluence_object'
require_relative 'converters'
require_relative 'git'
require_relative 'github'
require_relative 'parser'
require_relative 'rfc'
if __FILE__ == $0
parser = Parser.new
Git.init
readme = RFC.new([], parser).markdown(parser.by_id(23855388))
Git.add(new_name: 'README.md', contents: readme, message: 'Initial commit')
Git.checkout 'dummy'
Git.add(new_name: '.dummy', contents: '', message: 'Dummy commit')
Git.checkout 'master'
Git.add_remote
Git.push_all
pages = parser.by_type('Page')
documents = pages.group_by(&:originalVersionId)
rfcs = documents.map do |originalVersionId, grouped_pages|
next if originalVersionId.to_i == 0
next if ARGV[0] && originalVersionId.to_i != ARGV[0].to_i
grouped_pages << parser.by_id(originalVersionId)
grouped_pages.uniq!
rfc = RFC.new(grouped_pages, parser)
rfc if rfc.number
end.compact.sort_by(&:number)
rfcs.each do |rfc|
Git.checkout "master"
Git.checkout rfc.branch
rfc.pages_to_add.each do |page|
Git.add(page.except(:data))
end
end
Git.push_all
rfcs.each do |rfc|
while Github.next_available_pr_number < rfc.number
Github.create_empty_pr
end
puts "Creating PR for RFC #{rfc.number}"
begin
pr_number = Github.create_pr(rfc.branch, rfc.title)
rescue Octokit::UnprocessableEntity
pr_number = Github.pr_number(rfc.branch)
end
sha = Github.pr_sha(pr_number)
if rfc.comments.any?
puts "Posting #{rfc.comments.count} comments"
end
rfc.comments.each do |comment|
Github.add_comment(pr_number, comment)
end
if rfc.inline_comments.any?
puts "Posting #{rfc.inline_comments.count} inline comments"
end
rfc.inline_comments.each do |comment|
comment_id = Github.create_pr_comment(
pr_number,
sha,
rfc.filename,
comment[:line],
comment[:comment],
)
comment[:replies].each do |reply|
Github.create_pr_comment_reply(pr_number, comment_id, reply)
end
end
next if rfc.number == 54
case rfc.status_action
when :close
puts "Closing PR"
if rfc.notes
Github.add_comment(pr_number, "Closed with note: #{rfc.notes}")
end
Github.close_pr(pr_number)
Github.delete_branch(rfc.branch)
when :merge
puts "Merging PR"
if rfc.notes
Github.add_comment(pr_number, "Merged with note: #{rfc.notes}")
end
Github.merge_pr(pr_number)
Github.delete_branch(rfc.branch)
end
end
end