zz-export-pull-requests 0.3.10 → 0.3.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/epr +54 -4
- 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: 471d1c3557b3f0a5494f00d8077a93d21b5ed7132172fdc34e43931e35ad27b6
|
4
|
+
data.tar.gz: f5a3eb11e8bd64a6a2f9f78972dc7bb26fd1acd02810def01b9b5fb59dc29355
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b897f497835022516754f1ab46e6e006240e0f967a5ca331912076bed9edaf1d1c9fdda5ac88c9dd9eb5ffb680ae42b707057d3e2058f80a4081d47bda253f1c
|
7
|
+
data.tar.gz: 850734a2562ef96506cb397c1cd2f2fd703813a94cd57c567887d29821725ccd1b8607801576ab4a712810fa8e5abff0fc10fb255cc92f14059c10178db35de4
|
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.15"
|
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(STDERR)
|
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
|
@@ -66,8 +79,38 @@ def extract_hash_from_diff(user, repo, diff_link)
|
|
66
79
|
end
|
67
80
|
|
68
81
|
def get_full_hash(user, repo, short_hash)
|
69
|
-
|
70
|
-
|
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
|
+
if executions >= BITBUCKET_RATE_LIMIT
|
97
|
+
now = Time.now
|
98
|
+
now_formatted = now.strftime("%I:%M:%S")
|
99
|
+
one_hour = 1*60*60
|
100
|
+
later = now + one_hour
|
101
|
+
later_formatted = later.strftime("%I:%M:%S")
|
102
|
+
if ENV['SHOW_LOGS']
|
103
|
+
$redisLogger.info("#{now_formatted} - Rate limit reached. Will pause for an hour and will resume at #{later_formatted}.")
|
104
|
+
end
|
105
|
+
sleep one_hour
|
106
|
+
$redis.set("bb-executed", 0)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def check_api_rate_limit
|
111
|
+
executions = $redis.get("bb-executed").to_i
|
112
|
+
$redisLogger.info("We have called the API for #{executions} times") if ENV['SHOW_LOGS']
|
113
|
+
sleep_if_limit_reached
|
71
114
|
end
|
72
115
|
|
73
116
|
def bitbucket(user, repo)
|
@@ -88,6 +131,7 @@ def bitbucket(user, repo)
|
|
88
131
|
|
89
132
|
loop do
|
90
133
|
page += 1
|
134
|
+
check_api_rate_limit
|
91
135
|
|
92
136
|
prs = $bitbucket.repos.pull_request.all(user, repo, :page => page, :state => $filter.upcase)
|
93
137
|
prs["values"].each do |pr|
|
@@ -115,6 +159,7 @@ def bitbucket(user, repo)
|
|
115
159
|
]
|
116
160
|
end
|
117
161
|
|
162
|
+
$redis.incr("bb-executed")
|
118
163
|
break unless prs["next"]
|
119
164
|
end
|
120
165
|
end
|
@@ -124,12 +169,15 @@ def bitbucket(user, repo)
|
|
124
169
|
|
125
170
|
loop do
|
126
171
|
pr_page += 1
|
172
|
+
check_api_rate_limit
|
127
173
|
prs = $bitbucket.repos.pull_request.all(user, repo, :page => pr_page, :state => $filter.upcase)
|
128
174
|
|
129
175
|
prs["values"].each do |pr|
|
130
176
|
comment_page = 0
|
131
177
|
loop do
|
132
178
|
comment_page += 1
|
179
|
+
check_api_rate_limit
|
180
|
+
|
133
181
|
comments = $bitbucket.repos.pull_request.comments(user, repo, pr.id, :page => comment_page)
|
134
182
|
comments["values"].each do |comment|
|
135
183
|
rows << [
|
@@ -151,10 +199,12 @@ def bitbucket(user, repo)
|
|
151
199
|
comment["links"].code? ? extract_hash_from_diff(user, repo, comment["links"].code.href) : ""
|
152
200
|
]
|
153
201
|
end
|
202
|
+
$redis.incr("bb-executed")
|
154
203
|
break unless comments["next"]
|
155
204
|
end
|
156
205
|
end
|
157
|
-
|
206
|
+
|
207
|
+
$redis.incr("bb-executed")
|
158
208
|
break unless prs["next"]
|
159
209
|
end
|
160
210
|
end
|
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.15
|
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.
|