zz-export-pull-requests 0.3.6 → 0.3.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/epr +69 -8
- metadata +24 -4
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
|
@@ -55,6 +66,45 @@ def lookup_token
|
|
55
66
|
end
|
56
67
|
end
|
57
68
|
|
69
|
+
# extract "a3351540a2da" from
|
70
|
+
# given "https://api.bitbucket.org/2.0/repositories/hellogold/walletfactory/diff/hellogold/walletfactory:a3351540a2da..05675a5ae8ed?path=go%2Fwalletfactory%2F.gitignore"
|
71
|
+
def extract_hash_from_diff(user, repo, diff_link)
|
72
|
+
str1 = diff_link.split("..")
|
73
|
+
str2 = str1[0].split(":")
|
74
|
+
short_hash = str2[2]
|
75
|
+
long_hash = get_full_hash(user, repo, short_hash)
|
76
|
+
return long_hash
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_full_hash(user, repo, short_hash)
|
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
|
106
|
+
end
|
107
|
+
|
58
108
|
def bitbucket(user, repo)
|
59
109
|
# TODO: make sure no need to translate any states
|
60
110
|
# https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/pullrequests
|
@@ -73,6 +123,7 @@ def bitbucket(user, repo)
|
|
73
123
|
|
74
124
|
loop do
|
75
125
|
page += 1
|
126
|
+
sleep_if_limit_reached
|
76
127
|
|
77
128
|
prs = $bitbucket.repos.pull_request.all(user, repo, :page => page, :state => $filter.upcase)
|
78
129
|
prs["values"].each do |pr|
|
@@ -90,15 +141,17 @@ def bitbucket(user, repo)
|
|
90
141
|
pr["links"].html.href,
|
91
142
|
pr.summary.raw,
|
92
143
|
pr.summary.html,
|
93
|
-
!pr.source.commit.nil? ? pr.source.commit["hash"] : "",
|
94
|
-
!pr.destination.commit.nil? ? pr.destination.commit["hash"] : "",
|
144
|
+
!pr.source.commit.nil? ? get_full_hash(user, repo, pr.source.commit["hash"]) : "",
|
145
|
+
!pr.destination.commit.nil? ? get_full_hash(user, repo, pr.destination.commit["hash"]) : "",
|
95
146
|
!pr.source.branch.nil? ? pr.source.branch.name : "",
|
96
147
|
!pr.destination.branch.nil? ? pr.destination.branch.name : "",
|
97
148
|
!pr.reason.nil? ? pr.reason : "",
|
98
|
-
!pr.merge_commit.nil? ? pr.merge_commit["hash"] : ""
|
149
|
+
!pr.merge_commit.nil? ? pr.merge_commit["hash"] : "",
|
150
|
+
!pr.closed_by.nil? ? pr.closed_by.display_name : ""
|
99
151
|
]
|
100
152
|
end
|
101
153
|
|
154
|
+
$redis.incr("bb-executed")
|
102
155
|
break unless prs["next"]
|
103
156
|
end
|
104
157
|
end
|
@@ -108,12 +161,15 @@ def bitbucket(user, repo)
|
|
108
161
|
|
109
162
|
loop do
|
110
163
|
pr_page += 1
|
164
|
+
sleep_if_limit_reached
|
111
165
|
prs = $bitbucket.repos.pull_request.all(user, repo, :page => pr_page, :state => $filter.upcase)
|
112
166
|
|
113
167
|
prs["values"].each do |pr|
|
114
168
|
comment_page = 0
|
115
169
|
loop do
|
116
170
|
comment_page += 1
|
171
|
+
sleep_if_limit_reached
|
172
|
+
|
117
173
|
comments = $bitbucket.repos.pull_request.comments(user, repo, pr.id, :page => comment_page)
|
118
174
|
comments["values"].each do |comment|
|
119
175
|
rows << [
|
@@ -122,6 +178,7 @@ def bitbucket(user, repo)
|
|
122
178
|
comment.pullrequest.id,
|
123
179
|
comment.user? ? comment.user.display_name : no_user,
|
124
180
|
comment.inline? ? "inline" : "normal",
|
181
|
+
comment.id,
|
125
182
|
comment.content.raw,
|
126
183
|
comment.content.html,
|
127
184
|
localtime(comment.updated_on),
|
@@ -129,13 +186,17 @@ def bitbucket(user, repo)
|
|
129
186
|
comment.inline? ? comment.inline.to : "",
|
130
187
|
comment.inline? ? comment.inline.from : "",
|
131
188
|
comment.inline? ? comment.inline.path : "",
|
132
|
-
comment["links"].code? ? comment["links"].code.href : ""
|
189
|
+
comment["links"].code? ? comment["links"].code.href : "",
|
190
|
+
comment.parent? ? comment.parent.id : "",
|
191
|
+
comment["links"].code? ? extract_hash_from_diff(user, repo, comment["links"].code.href) : ""
|
133
192
|
]
|
134
193
|
end
|
194
|
+
$redis.incr("bb-executed")
|
135
195
|
break unless comments["next"]
|
136
196
|
end
|
137
197
|
end
|
138
|
-
|
198
|
+
|
199
|
+
$redis.incr("bb-executed")
|
139
200
|
break unless prs["next"]
|
140
201
|
end
|
141
202
|
end
|
@@ -281,9 +342,9 @@ def export_repos(argv)
|
|
281
342
|
rows = []
|
282
343
|
|
283
344
|
if $export == EXPORT_PR_COMMENTS
|
284
|
-
rows << %w[Repository Type PRNumber User CommentType BodyRaw BodyHTML CreatedAt IsDeleted ToLine FromLine FilePath Diff]
|
345
|
+
rows << %w[Repository Type PRNumber User CommentType CommentID BodyRaw BodyHTML CreatedAt IsDeleted ToLine FromLine FilePath Diff ParentID CommitHash]
|
285
346
|
else
|
286
|
-
rows << %w[Repository Type # User Title State CreatedAt UpdatedAt URL BodyRaw BodyHTML SourceCommit DestinationCommit SourceBranch DestinationBranch DeclineReason MergeCommit]
|
347
|
+
rows << %w[Repository Type # User Title State CreatedAt UpdatedAt URL BodyRaw BodyHTML SourceCommit DestinationCommit SourceBranch DestinationBranch DeclineReason MergeCommit ClosedBy]
|
287
348
|
end
|
288
349
|
|
289
350
|
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.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
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.1.
|
47
|
+
version: 0.1.11
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.1.
|
54
|
+
version: 0.1.11
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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.
|