zz-export-pull-requests 0.3.7 → 0.3.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/epr +66 -8
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad7da2494c7c8ad182157844df4558d731231afc7c3c8453b4cd0cf128e56be5
|
4
|
+
data.tar.gz: 9b990c531f0a9beb4c93c8d188459c15381c6f36762a373a34e00d305e7e3cb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 644f2764fe9702db374e77e78f382fc8da73a246a5762702ea6586a4353585db6d1e56a8c474b970e7be2594d8f556fd6dceff66793fa20803b8bac5f82427dd
|
7
|
+
data.tar.gz: 0bd92c548197b23b1298a7c9b09755efc8656228104970b94d8237425dcddc88ffedea58e6e5007e030e3d80e1312617eb03657efb7a1831c713331fdcaef714
|
data/bin/epr
CHANGED
@@ -4,12 +4,13 @@ require "csv"
|
|
4
4
|
require "optparse"
|
5
5
|
require "time"
|
6
6
|
require "logger"
|
7
|
+
require 'redis'
|
7
8
|
|
8
9
|
require "github_api"
|
9
10
|
require "gitlab"
|
10
11
|
require "bitbucket_rest_api"
|
11
12
|
|
12
|
-
VERSION = "0.3.
|
13
|
+
VERSION = "0.3.12"
|
13
14
|
SERVICES = %w[github gitlab bitbucket]
|
14
15
|
GIT_CONFIGS = %w[epr.token github.oauth-token]
|
15
16
|
|
@@ -22,6 +23,18 @@ EXPORT_PRS = "pr"
|
|
22
23
|
EXPORT_PR_COMMENTS = "pr_comments"
|
23
24
|
|
24
25
|
DEFAULT_BODY_LENGTH = 2 ** 32 - 1
|
26
|
+
BITBUCKET_RATE_LIMIT = 950 # actually, it's 1000 - we play safe here
|
27
|
+
|
28
|
+
# To store rate limit information for fast read & write.
|
29
|
+
# Data will persist in Redis DB/server until we shut it down.
|
30
|
+
# Docs: https://www.rubydoc.info/github/redis/redis-rb/master/frames
|
31
|
+
# Read: https://www.mikeperham.com/2015/09/24/storing-data-with-redis/#databases
|
32
|
+
$redisLogger = Logger.new(STDOUT)
|
33
|
+
$redisLogger.formatter = proc {|severity, datetime, progname, msg|
|
34
|
+
"[#{datetime.strftime('%d/%m/%Y %H:%M:%S')}] EPR-#{severity} - #{msg}\n"
|
35
|
+
}
|
36
|
+
$redis = Redis.new(host: "localhost", db: 15)
|
37
|
+
$redis.set("bb-executed", 0) if $redis.get("bb-executed").nil?
|
25
38
|
|
26
39
|
def localtime(t)
|
27
40
|
# MM/DD/YY HH:MM:SS
|
@@ -55,9 +68,43 @@ def lookup_token
|
|
55
68
|
end
|
56
69
|
end
|
57
70
|
|
71
|
+
# extract "a3351540a2da" from
|
72
|
+
# given "https://api.bitbucket.org/2.0/repositories/hellogold/walletfactory/diff/hellogold/walletfactory:a3351540a2da..05675a5ae8ed?path=go%2Fwalletfactory%2F.gitignore"
|
73
|
+
def extract_hash_from_diff(user, repo, diff_link)
|
74
|
+
str1 = diff_link.split("..")
|
75
|
+
str2 = str1[0].split(":")
|
76
|
+
short_hash = str2[2]
|
77
|
+
long_hash = get_full_hash(user, repo, short_hash)
|
78
|
+
return long_hash
|
79
|
+
end
|
80
|
+
|
58
81
|
def get_full_hash(user, repo, short_hash)
|
59
|
-
|
60
|
-
|
82
|
+
sleep_if_limit_reached
|
83
|
+
|
84
|
+
begin
|
85
|
+
result = $bitbucket.repos.commit.get_one(user, repo, short_hash)
|
86
|
+
$redis.incr("bb-executed")
|
87
|
+
return result["hash"]
|
88
|
+
rescue
|
89
|
+
$redis.incr("bb-executed")
|
90
|
+
return "bb-import-commit-not-found"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def sleep_if_limit_reached
|
95
|
+
executions = $redis.get("bb-executed").to_i
|
96
|
+
$redisLogger.info("We have called the API for #{executions} times")
|
97
|
+
|
98
|
+
if executions >= BITBUCKET_RATE_LIMIT
|
99
|
+
now = Time.now
|
100
|
+
now_formatted = now.strftime("%I:%M:%S")
|
101
|
+
one_hour = 1*60*60
|
102
|
+
later = now + one_hour
|
103
|
+
later_formatted = later.strftime("%I:%M:%S")
|
104
|
+
$redisLogger.info("#{now_formatted} - Rate limit reached. Will pause for an hour and will resume at #{later_formatted}.")
|
105
|
+
sleep one_hour
|
106
|
+
$redis.set("bb-executed", 0)
|
107
|
+
end
|
61
108
|
end
|
62
109
|
|
63
110
|
def bitbucket(user, repo)
|
@@ -78,6 +125,7 @@ def bitbucket(user, repo)
|
|
78
125
|
|
79
126
|
loop do
|
80
127
|
page += 1
|
128
|
+
sleep_if_limit_reached
|
81
129
|
|
82
130
|
prs = $bitbucket.repos.pull_request.all(user, repo, :page => page, :state => $filter.upcase)
|
83
131
|
prs["values"].each do |pr|
|
@@ -100,10 +148,12 @@ def bitbucket(user, repo)
|
|
100
148
|
!pr.source.branch.nil? ? pr.source.branch.name : "",
|
101
149
|
!pr.destination.branch.nil? ? pr.destination.branch.name : "",
|
102
150
|
!pr.reason.nil? ? pr.reason : "",
|
103
|
-
!pr.merge_commit.nil? ? pr.merge_commit["hash"] : ""
|
151
|
+
!pr.merge_commit.nil? ? pr.merge_commit["hash"] : "",
|
152
|
+
!pr.closed_by.nil? ? pr.closed_by.display_name : ""
|
104
153
|
]
|
105
154
|
end
|
106
155
|
|
156
|
+
$redis.incr("bb-executed")
|
107
157
|
break unless prs["next"]
|
108
158
|
end
|
109
159
|
end
|
@@ -113,12 +163,15 @@ def bitbucket(user, repo)
|
|
113
163
|
|
114
164
|
loop do
|
115
165
|
pr_page += 1
|
166
|
+
sleep_if_limit_reached
|
116
167
|
prs = $bitbucket.repos.pull_request.all(user, repo, :page => pr_page, :state => $filter.upcase)
|
117
168
|
|
118
169
|
prs["values"].each do |pr|
|
119
170
|
comment_page = 0
|
120
171
|
loop do
|
121
172
|
comment_page += 1
|
173
|
+
sleep_if_limit_reached
|
174
|
+
|
122
175
|
comments = $bitbucket.repos.pull_request.comments(user, repo, pr.id, :page => comment_page)
|
123
176
|
comments["values"].each do |comment|
|
124
177
|
rows << [
|
@@ -127,6 +180,7 @@ def bitbucket(user, repo)
|
|
127
180
|
comment.pullrequest.id,
|
128
181
|
comment.user? ? comment.user.display_name : no_user,
|
129
182
|
comment.inline? ? "inline" : "normal",
|
183
|
+
comment.id,
|
130
184
|
comment.content.raw,
|
131
185
|
comment.content.html,
|
132
186
|
localtime(comment.updated_on),
|
@@ -134,13 +188,17 @@ def bitbucket(user, repo)
|
|
134
188
|
comment.inline? ? comment.inline.to : "",
|
135
189
|
comment.inline? ? comment.inline.from : "",
|
136
190
|
comment.inline? ? comment.inline.path : "",
|
137
|
-
comment["links"].code? ? comment["links"].code.href : ""
|
191
|
+
comment["links"].code? ? comment["links"].code.href : "",
|
192
|
+
comment.parent? ? comment.parent.id : "",
|
193
|
+
comment["links"].code? ? extract_hash_from_diff(user, repo, comment["links"].code.href) : ""
|
138
194
|
]
|
139
195
|
end
|
196
|
+
$redis.incr("bb-executed")
|
140
197
|
break unless comments["next"]
|
141
198
|
end
|
142
199
|
end
|
143
|
-
|
200
|
+
|
201
|
+
$redis.incr("bb-executed")
|
144
202
|
break unless prs["next"]
|
145
203
|
end
|
146
204
|
end
|
@@ -286,9 +344,9 @@ def export_repos(argv)
|
|
286
344
|
rows = []
|
287
345
|
|
288
346
|
if $export == EXPORT_PR_COMMENTS
|
289
|
-
rows << %w[Repository Type PRNumber User CommentType BodyRaw BodyHTML CreatedAt IsDeleted ToLine FromLine FilePath Diff]
|
347
|
+
rows << %w[Repository Type PRNumber User CommentType CommentID BodyRaw BodyHTML CreatedAt IsDeleted ToLine FromLine FilePath Diff ParentID CommitHash]
|
290
348
|
else
|
291
|
-
rows << %w[Repository Type # User Title State CreatedAt UpdatedAt URL BodyRaw BodyHTML SourceCommit DestinationCommit SourceBranch DestinationBranch DeclineReason MergeCommit]
|
349
|
+
rows << %w[Repository Type # User Title State CreatedAt UpdatedAt URL BodyRaw BodyHTML SourceCommit DestinationCommit SourceBranch DestinationBranch DeclineReason MergeCommit ClosedBy]
|
292
350
|
end
|
293
351
|
|
294
352
|
rows[-1].insert(4, "Body") if $body
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zz-export-pull-requests
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zulhilmi Zainudin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: github_api
|
@@ -66,6 +66,26 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: redis
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4.1'
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 4.1.3
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - "~>"
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '4.1'
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 4.1.3
|
69
89
|
description: Program to export GitHub, GitLab, or Bitbucket pull requests/merge requests
|
70
90
|
and issues to CSV a file. This is forked version of https://github.com/sshaw/export-pull-requests
|
71
91
|
project.
|