zz-export-pull-requests 0.3.10 → 0.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/epr +46 -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: ec23970f15be8703f88796fd826581b0cb275913be1cbe31620659da0de5e580
|
4
|
+
data.tar.gz: 0caf623b5619c463baa10d45cdd3fedb61912058b980bbd3f77d2bf845e3f09e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88f774bc035801a5def78caaf335f0a26be167544c0b24a7147a2fa402edd5b06831c52e24e8b00a5a154e050b8cad05a1ca3302e9d1e403ba02a831b5c7d7df
|
7
|
+
data.tar.gz: 54b5aa18b655620e74642ec2607cd47047c6a81fd054262104abbc365ee72cd903cbe709bbb5835554d5445efa80c0cfafe42fe8d75d600a679bd63111ad9dd2
|
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.11"
|
13
14
|
SERVICES = %w[github gitlab bitbucket]
|
14
15
|
GIT_CONFIGS = %w[epr.token github.oauth-token]
|
15
16
|
|
@@ -22,6 +23,16 @@ 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.info("HELLO FROM REDIS LOGGER")
|
34
|
+
$redis = Redis.new(host: "localhost", db: 15)
|
35
|
+
$redis.set("bb-executed", 0) if $redis.get("bb-executed").nil?
|
25
36
|
|
26
37
|
def localtime(t)
|
27
38
|
# MM/DD/YY HH:MM:SS
|
@@ -66,8 +77,32 @@ def extract_hash_from_diff(user, repo, diff_link)
|
|
66
77
|
end
|
67
78
|
|
68
79
|
def get_full_hash(user, repo, short_hash)
|
69
|
-
|
70
|
-
|
80
|
+
sleep_if_limit_reached
|
81
|
+
|
82
|
+
begin
|
83
|
+
result = $bitbucket.repos.commit.get_one(user, repo, short_hash)
|
84
|
+
$redis.incr("bb-executed")
|
85
|
+
return result["hash"]
|
86
|
+
rescue
|
87
|
+
$redis.incr("bb-executed")
|
88
|
+
return "bb-import-commit-not-found"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def sleep_if_limit_reached
|
93
|
+
executions = $redis.get("bb-executed").to_i
|
94
|
+
$redisLogger.info("We have called the API for #{executions} times")
|
95
|
+
|
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
|
+
$redisLogger.info("#{now_formatted} - Rate limit reached. Will pause for an hour and will resume at #{later_formatted}.")
|
103
|
+
sleep one_hour
|
104
|
+
$redis.set("bb-executed", 0)
|
105
|
+
end
|
71
106
|
end
|
72
107
|
|
73
108
|
def bitbucket(user, repo)
|
@@ -88,6 +123,7 @@ def bitbucket(user, repo)
|
|
88
123
|
|
89
124
|
loop do
|
90
125
|
page += 1
|
126
|
+
sleep_if_limit_reached
|
91
127
|
|
92
128
|
prs = $bitbucket.repos.pull_request.all(user, repo, :page => page, :state => $filter.upcase)
|
93
129
|
prs["values"].each do |pr|
|
@@ -115,6 +151,7 @@ def bitbucket(user, repo)
|
|
115
151
|
]
|
116
152
|
end
|
117
153
|
|
154
|
+
$redis.incr("bb-executed")
|
118
155
|
break unless prs["next"]
|
119
156
|
end
|
120
157
|
end
|
@@ -124,12 +161,15 @@ def bitbucket(user, repo)
|
|
124
161
|
|
125
162
|
loop do
|
126
163
|
pr_page += 1
|
164
|
+
sleep_if_limit_reached
|
127
165
|
prs = $bitbucket.repos.pull_request.all(user, repo, :page => pr_page, :state => $filter.upcase)
|
128
166
|
|
129
167
|
prs["values"].each do |pr|
|
130
168
|
comment_page = 0
|
131
169
|
loop do
|
132
170
|
comment_page += 1
|
171
|
+
sleep_if_limit_reached
|
172
|
+
|
133
173
|
comments = $bitbucket.repos.pull_request.comments(user, repo, pr.id, :page => comment_page)
|
134
174
|
comments["values"].each do |comment|
|
135
175
|
rows << [
|
@@ -151,10 +191,12 @@ def bitbucket(user, repo)
|
|
151
191
|
comment["links"].code? ? extract_hash_from_diff(user, repo, comment["links"].code.href) : ""
|
152
192
|
]
|
153
193
|
end
|
194
|
+
$redis.incr("bb-executed")
|
154
195
|
break unless comments["next"]
|
155
196
|
end
|
156
197
|
end
|
157
|
-
|
198
|
+
|
199
|
+
$redis.incr("bb-executed")
|
158
200
|
break unless prs["next"]
|
159
201
|
end
|
160
202
|
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.11
|
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-26 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.
|