zz-export-pull-requests 0.3.9 → 0.3.14
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 +54 -6
- 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: de96b36aca31b822e84ccecae880661cf195490d51c4c2179ec728d8cff2e29a
|
4
|
+
data.tar.gz: a80cc917dc3f7223ad2a11012e0c8438e07192a69bb7a723b1ab3b1c403020b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afa41b1d13284145982e6de17470762c997b8db2d0b392643dde5d34c57aa36bd5cf8c52fc401a1f6e892fe65ec10255abb8d075662b8fd907909180570268b4
|
7
|
+
data.tar.gz: 0c9ca291ab505c0e4a5cda68ebf1277cb6931c671abe0514ce6b7bd452a520a6896503fcc426c6118c643062b2c81bb309049222b3d9bf2f5401eaca983e1a21
|
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.14"
|
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
|
@@ -55,17 +68,45 @@ 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"
|
58
73
|
def extract_hash_from_diff(user, repo, diff_link)
|
59
74
|
str1 = diff_link.split("..")
|
60
|
-
str2 = str1[
|
61
|
-
short_hash = str2[
|
75
|
+
str2 = str1[0].split(":")
|
76
|
+
short_hash = str2[2]
|
62
77
|
long_hash = get_full_hash(user, repo, short_hash)
|
63
78
|
return long_hash
|
64
79
|
end
|
65
80
|
|
66
81
|
def get_full_hash(user, repo, short_hash)
|
67
|
-
|
68
|
-
|
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") if ENV['SHOW_LOGS']
|
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
|
+
if ENV['SHOW_LOGS']
|
105
|
+
$redisLogger.info("#{now_formatted} - Rate limit reached. Will pause for an hour and will resume at #{later_formatted}.")
|
106
|
+
end
|
107
|
+
sleep one_hour
|
108
|
+
$redis.set("bb-executed", 0)
|
109
|
+
end
|
69
110
|
end
|
70
111
|
|
71
112
|
def bitbucket(user, repo)
|
@@ -86,6 +127,7 @@ def bitbucket(user, repo)
|
|
86
127
|
|
87
128
|
loop do
|
88
129
|
page += 1
|
130
|
+
sleep_if_limit_reached
|
89
131
|
|
90
132
|
prs = $bitbucket.repos.pull_request.all(user, repo, :page => page, :state => $filter.upcase)
|
91
133
|
prs["values"].each do |pr|
|
@@ -113,6 +155,7 @@ def bitbucket(user, repo)
|
|
113
155
|
]
|
114
156
|
end
|
115
157
|
|
158
|
+
$redis.incr("bb-executed")
|
116
159
|
break unless prs["next"]
|
117
160
|
end
|
118
161
|
end
|
@@ -122,12 +165,15 @@ def bitbucket(user, repo)
|
|
122
165
|
|
123
166
|
loop do
|
124
167
|
pr_page += 1
|
168
|
+
sleep_if_limit_reached
|
125
169
|
prs = $bitbucket.repos.pull_request.all(user, repo, :page => pr_page, :state => $filter.upcase)
|
126
170
|
|
127
171
|
prs["values"].each do |pr|
|
128
172
|
comment_page = 0
|
129
173
|
loop do
|
130
174
|
comment_page += 1
|
175
|
+
sleep_if_limit_reached
|
176
|
+
|
131
177
|
comments = $bitbucket.repos.pull_request.comments(user, repo, pr.id, :page => comment_page)
|
132
178
|
comments["values"].each do |comment|
|
133
179
|
rows << [
|
@@ -149,10 +195,12 @@ def bitbucket(user, repo)
|
|
149
195
|
comment["links"].code? ? extract_hash_from_diff(user, repo, comment["links"].code.href) : ""
|
150
196
|
]
|
151
197
|
end
|
198
|
+
$redis.incr("bb-executed")
|
152
199
|
break unless comments["next"]
|
153
200
|
end
|
154
201
|
end
|
155
|
-
|
202
|
+
|
203
|
+
$redis.incr("bb-executed")
|
156
204
|
break unless prs["next"]
|
157
205
|
end
|
158
206
|
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.14
|
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.
|