export-pull-requests 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/epr +49 -6
  3. metadata +19 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7bcd3a99bc36a8a9c42ae375bd29113f4b1de1f7
4
- data.tar.gz: ea1fc9e512b536b7c5f6c7d553944d7b44783271
3
+ metadata.gz: 0a531cf40cb67b6e178bc75a254ee821758369d6
4
+ data.tar.gz: da773616d8a630e16bc43b68bf19a6dcddfca440
5
5
  SHA512:
6
- metadata.gz: 56a71220ae9b7492d8ed4fa41f79a40e3d2eea3e2883b5e59d8efb9d3a8bce89820eaa5fa799e11f465a2417ddfdb265f4401335ed28203060f8f9dfe83a31c8
7
- data.tar.gz: 793e9283143b22969f9663f355036c0d8c8da497181ddb520f4e445ec1a13571e16b9d0d675ab34404c986c91e407ef76c34ff15ab00cd7838e9b4dd74f92a16
6
+ metadata.gz: 859d3b348f3e95edefa52cf74de68a5a3ce253863ddd9c8695b663fa5b3488193d9672740822f51b6becf14558a9ac4d623d36f56df79fc2ddd23d365f2a3aea
7
+ data.tar.gz: 883f927bd24a27b417b085550fc4697e06ce4f631c3212ce54e53e8ce74f901df02c7b33ae9d7df99f9aa20b80cdc81288deadea57c1e0eb860f8a7f7af6ca20
data/bin/epr CHANGED
@@ -3,10 +3,14 @@
3
3
  require "csv"
4
4
  require "optparse"
5
5
  require "time"
6
+ require "logger"
7
+
6
8
  require "github_api"
7
9
  require "gitlab"
10
+ require "bitbucket_rest_api"
8
11
 
9
- VERSION = "0.1.0"
12
+ VERSION = "0.1.1"
13
+ SERVICES = %w[github gitlab bitbucket]
10
14
 
11
15
  def localtime(t)
12
16
  Time.parse(t).localtime.strftime("%x %X")
@@ -36,6 +40,39 @@ def lookup_token
36
40
  end
37
41
  end
38
42
 
43
+ def bitbucket(user, repo)
44
+ page = 0
45
+ rows = []
46
+
47
+ $bitbucket ||= BitBucket.new(:basic_auth => $token)
48
+ # TODO: make sure no need to translate any states
49
+ # https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/pullrequests
50
+
51
+ loop do
52
+ page += 1
53
+
54
+ prs = $bitbucket.repos.pull_request.all(user, repo, :page => page, :state => $filter.upcase)
55
+ prs["values"].each do |pr|
56
+ next if pr.author && skip_user?(pr.author.username)
57
+
58
+ rows << [
59
+ "#{user}/#{repo}",
60
+ pr.id,
61
+ pr.author ? pr.author.username : "-",
62
+ pr.title,
63
+ pr.state,
64
+ localtime(pr.created_on),
65
+ localtime(pr.updated_on),
66
+ pr["links"].html.href
67
+ ]
68
+ end
69
+
70
+ break unless prs["next"]
71
+ end
72
+
73
+ rows
74
+ end
75
+
39
76
  def github(user, repo)
40
77
  rows = []
41
78
 
@@ -99,12 +136,14 @@ def export_repos(repos)
99
136
  rows.concat(github(user, repo))
100
137
  when "gitlab"
101
138
  rows.concat(gitlab(user, repo))
139
+ when "bitbucket"
140
+ rows.concat(bitbucket(user, repo))
102
141
  else
103
- abort "unknown service provider: #{service}"
142
+ abort "unknown service provider: #$provider"
104
143
  end
105
144
 
106
145
  rows.each do |r|
107
- # Repository column is dropped if we only have one repo
146
+ # Drop Repository column if we only have one repo
108
147
  r.shift unless repos.size > 1
109
148
  puts r.to_csv
110
149
  end
@@ -112,10 +151,14 @@ def export_repos(repos)
112
151
  end
113
152
  end
114
153
 
154
+ # Hashie is used by Bitbucket, and it spews warnings to stdout. We stop that,
155
+ # specifically: https://github.com/bitbucket-rest-api/bitbucket/issues/87
156
+ Hashie.logger = Logger.new(File::NULL) if defined?(Hashie)
157
+
115
158
  $exclude_users = []
116
159
  $include_users = []
117
160
  $filter = "open"
118
- $provider = "github"
161
+ $provider = ENV["EPR_SERVICE"] || SERVICES[0]
119
162
  $token = lookup_token
120
163
 
121
164
  parser = OptionParser.new do |opts|
@@ -135,7 +178,7 @@ parser = OptionParser.new do |opts|
135
178
  $token = t
136
179
  end
137
180
 
138
- opts.on "-p, --provider=NAME", %w[github gitlab], "Service provider: gitlab or github; defaults to github" do |name|
181
+ opts.on "-p, --provider=NAME", SERVICES, "Service provider, one of: #{SERVICES}" do |name|
139
182
  $provider = name
140
183
  end
141
184
 
@@ -144,7 +187,7 @@ parser = OptionParser.new do |opts|
144
187
  end
145
188
 
146
189
  opts.on "-v", "--version", "epr version" do
147
- puts "v#{VERSION} (GitHub API v#{Github::VERSION}, GitLab API v#{Gitlab::VERSION})"
190
+ puts "v#{VERSION} (GitHub v#{Github::VERSION}, GitLab v#{Gitlab::VERSION}, Bitbucket v#{BitBucket::VERSION::STRING})"
148
191
  exit
149
192
  end
150
193
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: export-pull-requests
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Skye Shaw
@@ -38,22 +38,36 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bitbucket_rest_api
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: 0.9.2
61
+ version: '0.9'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: 0.9.2
55
- description: Program to export GitHub pull requests or GitLab merge requests to CSV
56
- a file.
68
+ version: '0.9'
69
+ description: Program to export GitHub, GitLab, or Bitbucket pull requests/merge requests
70
+ to CSV a file.
57
71
  email: skye.shaw@gmail.com
58
72
  executables:
59
73
  - epr