gemfury 0.10.0.rc1 → 0.12.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 624ab4a41068c6d17c63693ff3bc4de20641ee87390f68df9f7d02c29a59e16e
4
- data.tar.gz: f4657867345ca219161a3090be0fb2ba19c475cb3fb33ac637213aa0c32916c5
3
+ metadata.gz: e6949b37b97e02f4d02cc09710a8f29c7bb73bc0cf11202e973472caeb304abb
4
+ data.tar.gz: 56f2d03905bb253df4aface03aeb4b2fb197c8cfd1078e5cb049653c23d30eb3
5
5
  SHA512:
6
- metadata.gz: 569f391a1d8230204d9b1778042a57e53a72afae523ae7f1b4646971ad2db1918dc1260792f0fce000e995619d78f5c2bc3ca013945883cb01c6292463694219
7
- data.tar.gz: f3906e7e9b1e360ba75f8615f5728009b3e8c01915be185777ea2fdef9d1207990abe3c86f405a18e8275461eef334efb8c1c738ceb62eb74765d63d24fa063e
6
+ metadata.gz: b69e76e7cb6f0d3648d8f493c96e4f15c13b05d03d38a51021bbe20524e83f3eb5895cb15f049a6727d42b8908f78e62a7fd70af7b1041c5afcca0bcc49ad6f0
7
+ data.tar.gz: 3d2bbef2c9c9517db2a9b9ddc865baee2a8fa0929cedf9fb6450a945d9f6244923ef19708ba8ff0843063d099263ef63210662f7315329612b3f2f8ae33a942f
data/README.md CHANGED
@@ -4,6 +4,8 @@ Gemfury CLI
4
4
  [![Gem Version](https://badge.fury.io/rb/gemfury.svg)](http://badge.fury.io/rb/gemfury)
5
5
  [![Build Status](https://secure.travis-ci.org/gemfury/gemfury.svg?branch=master)](https://travis-ci.org/gemfury/gemfury)
6
6
  [![Code Climate](https://codeclimate.com/github/gemfury/gemfury/badges/gpa.svg)](https://codeclimate.com/github/gemfury/gemfury)
7
+ [![Documentation](https://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/gemfury)
8
+ [![Documentation completeness](https://inch-ci.org/github/gemfury/gemfury.svg?branch=master)](http://inch-ci.org/github/gemfury/gemfury)
7
9
 
8
10
  This is the Gemfury CLI used to manage your Gemfury packages from the command line. If you're
9
11
  familiar with the service and want to jump straight into command line action, please proceed to
@@ -30,6 +32,29 @@ any package to any host. It's simple, reliable, and hassle-free.
30
32
  * [Install private Composer packages](https://gemfury.com/help/php-composer-server)
31
33
  * [Private RubyGems on Heroku](https://gemfury.com/help/private-gems-on-heroku)
32
34
 
35
+
36
+ ## Using the Gemfury Client
37
+
38
+ You can also use the client directly via Ruby; you will need a "Full access token" (API token) from `https://manage.fury.io/manage/YOUR-ACCOUNT-NAME/tokens/api`
39
+
40
+ ```ruby
41
+ require 'gemfury'
42
+
43
+ client = Gemfury::Client.new(user_api_key: "YOUR API TOKEN")
44
+
45
+ all_artifacts = client.list
46
+ puts "Available artifacts:"
47
+ puts all_artifacts
48
+
49
+ one_artifact = all_artifacts[0]
50
+ puts "Versions of the #{one_artifact['language']} artifact #{one_artifact['name']}:"
51
+ artifact_versions = client.versions(one_artifact["name"])
52
+ puts artifact_versions.map { |v| v["version"] }
53
+ ```
54
+
55
+ More information about the `Gemfury::Client` API is [hosted on rubydoc.info](https://rubydoc.info/gems/gemfury/Gemfury/Client).
56
+
57
+
33
58
  ## Contribution and Improvements
34
59
 
35
60
  Please [email us](mailto:support@gemfury.com) if we've missed some key functionality or you have problems installing the CLI client. Better yet, fork the code, make the changes, and submit a pull request to speed things along.
@@ -59,4 +84,4 @@ Over time, dependencies for this gem will get stale and may interfere with your
59
84
 
60
85
  ## Questions
61
86
 
62
- Please email support@gemfury.com or file a Github Issue if you have any other questions or problems.
87
+ Please email support@gemfury.com or file a Github Issue if you have any other questions or problems.
data/bin/fury CHANGED
@@ -7,4 +7,8 @@ require 'rubygems'
7
7
  require 'gemfury'
8
8
  require 'gemfury/command'
9
9
 
10
+ if defined?(Warning) && Warning.respond_to?('[]')
11
+ Warning[:deprecated] = !!ENV['DEBUG']
12
+ end
13
+
10
14
  Gemfury::Command::App.start
@@ -5,10 +5,23 @@ module Faraday
5
5
  # @private
6
6
  class Request::MultipartWithFile < Faraday::Middleware
7
7
  def call(env)
8
+
8
9
  if env[:body].is_a?(Hash)
10
+
11
+ # Check for IO (and IO-like objects, like Zip::InputStream) in the request,
12
+ # which represent data to be uploaded. Replace these with Faraday
9
13
  env[:body].each do |key, value|
10
- if value.is_a?(File)
11
- env[:body][key] = Faraday::UploadIO.new(value, mime_type(value), value.path)
14
+
15
+ # Faraday seems to expect a few IO methods to be available, but that's all:
16
+ # https://github.com/lostisland/faraday/blob/master/lib/faraday/file_part.rb
17
+ # :length seems to be an optional one
18
+ #
19
+ # UploadIO also seems to do a duck typing check for :read, with :path optional
20
+ # https://www.rubydoc.info/gems/multipart-post/2.0.0/UploadIO:initialize
21
+ #
22
+ # We attempt to make our duck typing compatible with their duck typing
23
+ if value.respond_to?(:read) && value.respond_to?(:rewind) && value.respond_to?(:close)
24
+ env[:body][key] = Faraday::UploadIO.new(value, mime_type(value))
12
25
  end
13
26
  end
14
27
  end
@@ -19,6 +32,9 @@ module Faraday
19
32
  private
20
33
 
21
34
  def mime_type(file)
35
+ default = 'application/octet-stream'
36
+ return default unless file.respond_to?(:path)
37
+
22
38
  case file.path
23
39
  when /\.jpe?g/i
24
40
  'image/jpeg'
@@ -27,7 +43,7 @@ module Faraday
27
43
  when /\.png$/i
28
44
  'image/png'
29
45
  else
30
- 'application/octet-stream'
46
+ default
31
47
  end
32
48
  end
33
49
  end
@@ -1,5 +1,5 @@
1
1
  gem "multi_json", "~> 1.10"
2
- gem "faraday", ">= 0.9.0", "< 0.16.0.pre"
2
+ gem "faraday", ">= 0.9.0", "< 1.1.0.pre"
3
3
  gem "netrc", ">= 0.10.0", "< 0.12.0.pre"
4
4
 
5
5
  require 'time'
@@ -23,6 +23,8 @@ require 'gemfury/client'
23
23
 
24
24
  module Gemfury
25
25
  extend Configuration
26
+ VALID_OPTIONS_KEYS = Configuration::CONFIGURATION_DEFAULTS.keys.freeze
27
+
26
28
  class << self
27
29
  # Alias for Gemfury::Client.new
28
30
  #
@@ -31,6 +33,27 @@ module Gemfury
31
33
  Gemfury::Client.new(options)
32
34
  end
33
35
 
36
+ # Convenience method to allow configuration options to be set in a block
37
+ def configure
38
+ yield self
39
+ end
40
+
41
+ # Create a hash of options and their values
42
+ # @return [Hash] the options and their values
43
+ def options
44
+ VALID_OPTIONS_KEYS.inject({}) do |options, k|
45
+ options[k] = send(k)
46
+ options
47
+ end
48
+ end
49
+
50
+ # Reset all configuration options to defaults
51
+ # @return [Configuration] The default configuration
52
+ def reset
53
+ CONFIGURATION_DEFAULTS.each { |k, v| send("#{k}=", v) }
54
+ self
55
+ end
56
+
34
57
  # Delegate to Gemfury::Client
35
58
  def method_missing(method, *args, &block)
36
59
  return super unless new.respond_to?(method)
@@ -40,14 +63,20 @@ module Gemfury
40
63
  def respond_to?(method, include_private = false)
41
64
  new.respond_to?(method, include_private) || super(method, include_private)
42
65
  end
66
+
43
67
  end
44
68
  end
45
69
 
70
+ # Initialize configuration
71
+ Gemfury.reset
72
+
73
+ # Polyfill #dig for Ruby 2.2 and earlier
46
74
  class Hash
47
- # Access nested hashes as a period-separated path
48
- def path(path, separator = '.')
49
- path.split(separator).inject(self) do |hash, part|
50
- hash.is_a?(Hash) ? hash[part] : nil
75
+ unless self.instance_methods.include?(:dig)
76
+ def dig(*parts)
77
+ parts.inject(self) do |hash, part|
78
+ hash.is_a?(Hash) ? hash[part] : nil
79
+ end
51
80
  end
52
81
  end
53
82
  end
@@ -1,31 +1,37 @@
1
1
  module Gemfury
2
2
  class Client
3
3
  include Gemfury::Client::Filters
4
- attr_accessor *Configuration::VALID_OPTIONS_KEYS
4
+ include Gemfury::Configuration
5
5
 
6
6
  # Creates a new API
7
+ # @param options [Hash] values for attributes described in {Gemfury::Configuration}
7
8
  def initialize(options={})
8
9
  options = Gemfury.options.merge(options)
9
- Configuration::VALID_OPTIONS_KEYS.each do |key|
10
+ Gemfury::VALID_OPTIONS_KEYS.each do |key|
10
11
  send("#{key}=", options[key])
11
12
  end
12
13
  end
13
14
 
14
15
  # Get the information for the current account
16
+ # @return [Hash]
15
17
  def account_info
16
18
  ensure_ready!(:authorization)
17
19
  response = connection.get('users/me')
18
20
  checked_response_body(response)
19
21
  end
20
22
 
21
- # Get the information for the current account
23
+ # Get the information for the all accounts that this account has some level of access to
24
+ # @return [Array<Hash>]
22
25
  def accounts
23
26
  ensure_ready!(:authorization)
24
27
  response = connection.get('accounts')
25
28
  checked_response_body(response)
26
29
  end
27
30
 
28
- # Uploading a gem file
31
+ # Upload an artifact file
32
+ # @param file [String] the filename to upload
33
+ # @param options [Hash] Faraday client options
34
+ # @return [Hash]
29
35
  def push_gem(file, options = {})
30
36
  ensure_ready!(:authorization)
31
37
  push_api = connection(:url => self.pushpoint)
@@ -33,14 +39,19 @@ module Gemfury
33
39
  checked_response_body(response)
34
40
  end
35
41
 
36
- # List available gems
42
+ # List available artifacts
43
+ # @param options [Hash] Faraday client options
44
+ # @return [Array<Hash>]
37
45
  def list(options = {})
38
46
  ensure_ready!(:authorization)
39
47
  response = connection.get('gems', options)
40
48
  checked_response_body(response)
41
49
  end
42
50
 
43
- # List versions for a gem
51
+ # List versions for an artifact
52
+ # @param name [String] the name of the artifact
53
+ # @param options [Hash] Faraday client options
54
+ # @return [Array<Hash>]
44
55
  def versions(name, options = {})
45
56
  ensure_ready!(:authorization)
46
57
  url = "gems/#{escape(name)}/versions"
@@ -48,7 +59,11 @@ module Gemfury
48
59
  checked_response_body(response)
49
60
  end
50
61
 
51
- # Delete a gem version
62
+ # Delete an artifact version
63
+ # @param name [String] the name of the artifact
64
+ # @param version [String] the version of the artifact
65
+ # @param options [Hash] Faraday client options
66
+ # @return [Hash]
52
67
  def yank_version(name, version, options = {})
53
68
  ensure_ready!(:authorization)
54
69
  url = "gems/#{escape(name)}/versions/#{escape(version)}"
@@ -62,6 +77,10 @@ module Gemfury
62
77
  end
63
78
 
64
79
  # Get authentication info via email/password
80
+ # @param email [String] the account email address
81
+ # @param password [String] the account password
82
+ # @param opts [Hash] Faraday client options
83
+ # @return [Hash]
65
84
  def login(email, password, opts = {})
66
85
  ensure_ready!
67
86
  opts = opts.merge(:email => email, :password => password)
@@ -69,6 +88,7 @@ module Gemfury
69
88
  end
70
89
 
71
90
  # Invalidate session token
91
+ # @return [Hash]
72
92
  def logout
73
93
  ensure_ready!(:authorization)
74
94
  response = connection.post('logout')
@@ -76,6 +96,8 @@ module Gemfury
76
96
  end
77
97
 
78
98
  # List collaborators for this account
99
+ # @param options [Hash] Faraday client options
100
+ # @return [Array<Hash>]
79
101
  def list_collaborators(options = {})
80
102
  ensure_ready!(:authorization)
81
103
  response = connection.get('collaborators', options)
@@ -83,6 +105,8 @@ module Gemfury
83
105
  end
84
106
 
85
107
  # Add a collaborator to the account
108
+ # @param options [Hash] Faraday client options
109
+ # @return [Hash]
86
110
  def add_collaborator(login, options = {})
87
111
  ensure_ready!(:authorization)
88
112
  url = "collaborators/#{escape(login)}"
@@ -91,6 +115,9 @@ module Gemfury
91
115
  end
92
116
 
93
117
  # Remove a collaborator to the account
118
+ # @param login [String] the account login
119
+ # @param options [Hash] Faraday client options
120
+ # @return [Hash]
94
121
  def remove_collaborator(login, options = {})
95
122
  ensure_ready!(:authorization)
96
123
  url = "collaborators/#{escape(login)}"
@@ -99,6 +126,8 @@ module Gemfury
99
126
  end
100
127
 
101
128
  # List Git repos for this account
129
+ # @param options [Hash] Faraday client options
130
+ # @return [Hash]
102
131
  def git_repos(options = {})
103
132
  ensure_ready!(:authorization)
104
133
  response = connection.get(git_repo_path, options)
@@ -106,6 +135,9 @@ module Gemfury
106
135
  end
107
136
 
108
137
  # Update repository name and settings
138
+ # @param repo [String] the repo name
139
+ # @param options [Hash] Faraday client options
140
+ # @return [Hash]
109
141
  def git_update(repo, options = {})
110
142
  ensure_ready!(:authorization)
111
143
  response = connection.patch(git_repo_path(repo), options)
@@ -113,6 +145,9 @@ module Gemfury
113
145
  end
114
146
 
115
147
  # Reset repository to initial state
148
+ # @param repo [String] the repo name
149
+ # @param options [Hash] Faraday client options
150
+ # @return [Hash]
116
151
  def git_reset(repo, options = {})
117
152
  ensure_ready!(:authorization)
118
153
  response = connection.delete(git_repo_path(repo), options)
@@ -120,6 +155,9 @@ module Gemfury
120
155
  end
121
156
 
122
157
  # Rebuild Git repository package
158
+ # @param repo [String] the repo name
159
+ # @param options [Hash] Faraday client options
160
+ # @return [Hash]
123
161
  def git_rebuild(repo, options = {})
124
162
  ensure_ready!(:authorization)
125
163
  url = "#{git_repo_path(repo)}/builds"
@@ -127,6 +165,30 @@ module Gemfury
127
165
  checked_response_body(api.post(url, options))
128
166
  end
129
167
 
168
+ # List Git repo's build configuration
169
+ # @param repo [String] the repo name
170
+ # @param options [Hash] Faraday client options
171
+ # @return [Hash]
172
+ def git_config(repo, options = {})
173
+ ensure_ready!(:authorization)
174
+ path = "#{git_repo_path(repo)}/config-vars"
175
+ response = connection.get(path, options)
176
+ checked_response_body(response)
177
+ end
178
+
179
+ # Update Git repo's build configuration
180
+ # @param repo [String] the repo name
181
+ # @param updates [Hash] Updates to configuration
182
+ # @param options [Hash] Faraday client options
183
+ # @return [Hash]
184
+ def git_config_update(repo, updates, options = {})
185
+ ensure_ready!(:authorization)
186
+ path = "#{git_repo_path(repo)}/config-vars"
187
+ opts = options.merge(:config_vars => updates)
188
+ response = connection.patch(path, opts)
189
+ checked_response_body(response)
190
+ end
191
+
130
192
  private
131
193
  def escape(str)
132
194
  CGI.escape(str)
@@ -1,5 +1,6 @@
1
+ gem "progressbar", ">= 1.10.1", "< 2.0.0.pre"
1
2
  gem "highline", ">= 1.6.0", "< 2.1.0.pre"
2
- gem "thor", ">= 0.14.0", "< 1.0.0.pre"
3
+ gem "thor", ">= 0.14.0", "< 1.1.0.pre"
3
4
 
4
5
  require 'thor'
5
6
  require 'yaml'
@@ -1,3 +1,6 @@
1
+ require 'progressbar'
2
+ require 'delegate'
3
+
1
4
  class Gemfury::Command::App < Thor
2
5
  include Gemfury::Command::Authorization
3
6
  UserAgent = "Gemfury CLI #{Gemfury::VERSION}".freeze
@@ -7,6 +10,9 @@ class Gemfury::Command::App < Thor
7
10
  class_option :as, :desc => 'Access an account other than your own'
8
11
  class_option :api_token, :desc => 'API token to use for commands'
9
12
 
13
+ # Make sure we retain the default exit behaviour of 0 even on argument errors
14
+ def self.exit_on_failure?; false; end
15
+
10
16
  map "-v" => :version
11
17
  desc "version", "Show Gemfury version", :hide => true
12
18
  def version
@@ -15,6 +21,7 @@ class Gemfury::Command::App < Thor
15
21
 
16
22
  ### PACKAGE MANAGEMENT ###
17
23
  option :public, :type => :boolean, :desc => "Create as public package"
24
+ option :quiet, :type => :boolean, :aliases => "-q", :desc => "Do not show progress bar", :default => false
18
25
  desc "push FILE", "Upload a new version of a package"
19
26
  def push(*gems)
20
27
  with_checks_and_rescues do
@@ -31,7 +38,7 @@ class Gemfury::Command::App < Thor
31
38
  va = [ %w{ name kind version privacy } ]
32
39
  gems.each do |g|
33
40
  va << [ g['name'], g['language'],
34
- g.path('latest_version.version') || 'beta',
41
+ g.dig('latest_version', 'version') || 'beta',
35
42
  g['private'] ? 'private' : 'public ' ]
36
43
  end
37
44
 
@@ -46,10 +53,10 @@ class Gemfury::Command::App < Thor
46
53
  shell.say "\n*** #{gem_name.capitalize} Versions ***\n\n"
47
54
 
48
55
  va = []
49
- va = [ %w{ version uploaded uploaded_by } ]
56
+ va = [ %w{ version uploaded_by uploaded } ]
50
57
  versions.each do |v|
51
- uploaded = Time.parse(v['created_at']).strftime('%F %R %z')
52
- va << [ v['version'], uploaded, v['created_by']['name'] ]
58
+ uploaded = time_ago(Time.parse(v['created_at']).getlocal)
59
+ va << [ v['version'], v['created_by']['name'], uploaded ]
53
60
  end
54
61
 
55
62
  shell.print_table(va)
@@ -114,16 +121,25 @@ class Gemfury::Command::App < Thor
114
121
  desc "sharing", "List collaborators"
115
122
  def sharing
116
123
  with_checks_and_rescues do
117
- me = client.account_info['username']
124
+ account_info = client.account_info
125
+ me = account_info['username']
126
+
118
127
  collaborators = client.list_collaborators
119
128
  if collaborators.empty?
120
- shell.say "You (#{me}) are the only collaborator", :green
129
+ shell.say %Q(You (#{me}) are the only collaborator\n), :green
121
130
  else
122
131
  shell.say %Q(\n*** Collaborators for "#{me}" ***\n), :green
123
- usernames = [me] + collaborators.map { |c| c['username'] }
124
- shell.say usernames.join("\n")
132
+
133
+ va = [ %w{ username permission } ]
134
+
135
+ if account_info['type'] == 'user'
136
+ va << [ me, 'owner' ]
137
+ end
138
+
139
+ collaborators.each { |c| va << [ c['username'], c['permission'] ] }
140
+
141
+ shell.print_table(va)
125
142
  end
126
- shell.say "\n"
127
143
  end
128
144
  end
129
145
 
@@ -185,7 +201,7 @@ class Gemfury::Command::App < Thor
185
201
  end
186
202
  end
187
203
 
188
- desc "git:rename", "Rename a Git repository"
204
+ desc "git:rename REPO_NAME NEW_NAME", "Rename a Git repository"
189
205
  def git_rename(repo, new_name)
190
206
  with_checks_and_rescues do
191
207
  client.git_update(repo, :repo => { :name => new_name })
@@ -193,7 +209,7 @@ class Gemfury::Command::App < Thor
193
209
  end
194
210
  end
195
211
 
196
- desc "git:reset", "Remove a Git repository"
212
+ desc "git:reset REPO_NAME", "Remove a Git repository"
197
213
  def git_reset(repo)
198
214
  with_checks_and_rescues do
199
215
  client.git_reset(repo)
@@ -201,7 +217,7 @@ class Gemfury::Command::App < Thor
201
217
  end
202
218
  end
203
219
 
204
- desc "git:rebuild", "Rebuild a Git repository"
220
+ desc "git:rebuild REPO_NAME", "Rebuild a Git repository"
205
221
  method_options %w(revision -r) => :string
206
222
  def git_rebuild(repo)
207
223
  with_checks_and_rescues do
@@ -211,6 +227,40 @@ class Gemfury::Command::App < Thor
211
227
  end
212
228
  end
213
229
 
230
+ ### GIT REPOSITORY BUILD CONFIG ###
231
+ map 'git:config' => 'git_config'
232
+ map 'git:config:set' => 'git_config_set'
233
+ map 'git:config:unset' => 'git_config_unset'
234
+
235
+ desc "git:config REPO_NAME", "List Git repository's build environment"
236
+ def git_config(repo)
237
+ with_checks_and_rescues do
238
+ vars = client.git_config(repo)['config_vars']
239
+ shell.say "*** #{repo} build config ***\n"
240
+ shell.print_table(vars.map { |kv|
241
+ ["#{kv[0]}:", kv[1]]
242
+ })
243
+ end
244
+ end
245
+
246
+ desc "git:config:set REPO_NAME KEY=VALUE ...", "Update Git repository's build environment"
247
+ def git_config_set(repo, *vars)
248
+ with_checks_and_rescues do
249
+ updates = Hash[vars.map { |v| v.split("=", 2) }]
250
+ client.git_config_update(repo, updates)
251
+ shell.say "Updated #{repo} build config"
252
+ end
253
+ end
254
+
255
+ desc "git:config:unset REPO_NAME KEY ...", "Remove variables from Git repository's build environment"
256
+ def git_config_unset(repo, *vars)
257
+ with_checks_and_rescues do
258
+ updates = Hash[vars.map { |v| [v, nil] }]
259
+ client.git_config_update(repo, updates)
260
+ shell.say "Updated #{repo} build config"
261
+ end
262
+ end
263
+
214
264
  private
215
265
  def client
216
266
  opts = {}
@@ -248,6 +298,10 @@ private
248
298
  g.is_a?(String) ? File.new(g) : g rescue nil
249
299
  end.compact
250
300
 
301
+ if !options[:quiet] && !shell.mute? && $stdout.tty?
302
+ files = files.map { |g| ProgressIO.new(g) }
303
+ end
304
+
251
305
  if files.empty?
252
306
  die!("Problem: No valid packages found", nil, command)
253
307
  end
@@ -259,11 +313,23 @@ private
259
313
 
260
314
  error_ex = nil
261
315
 
262
- # Let's get uploading
263
316
  files.each do |file|
317
+ show_bar = file.is_a?(ProgressIO) && file.show_bar?
318
+ title = "Uploading #{File.basename(file.path)} "
319
+
264
320
  begin
265
- shell.say "Uploading #{File.basename(file.path)} "
266
- client.push_gem(file, push_options)
321
+ if show_bar
322
+ begin
323
+ client.push_gem(file, push_options)
324
+ ensure
325
+ shell.say "\e[A\e[0K", nil, false
326
+ shell.say title
327
+ end
328
+ else
329
+ shell.say title
330
+ client.push_gem(file, push_options)
331
+ end
332
+
267
333
  shell.say "- done"
268
334
  rescue Gemfury::CorruptGemFile => e
269
335
  shell.say "- problem processing this package", :red
@@ -286,10 +352,77 @@ private
286
352
  end
287
353
  end
288
354
 
355
+ C50K = 50000
356
+
357
+ class ProgressIO < SimpleDelegator
358
+ attr_reader :content_type, :original_filename, :local_path
359
+
360
+ def initialize(filename_or_io, content_type = 'application/octet-stream', fname = nil)
361
+ io = filename_or_io
362
+ local_path = ''
363
+
364
+ if io.respond_to? :read
365
+ local_path = filename_or_io.respond_to?(:path) ? filename_or_io.path : 'local.path'
366
+ else
367
+ io = File.open(filename_or_io)
368
+ local_path = filename_or_io
369
+ end
370
+
371
+ fname ||= local_path
372
+
373
+ @content_type = content_type
374
+ @original_filename = File.basename(fname)
375
+ @local_path = local_path
376
+
377
+ if io.respond_to? :size
378
+ filesize = io.size
379
+ else
380
+ filesize = io.stat.size
381
+ end
382
+
383
+ if filesize > C50K
384
+ title = 'Uploading %s ' % File.basename(fname)
385
+ @bar = ProgressBar.create(:title => title, :total => filesize)
386
+ else
387
+ @bar = nil
388
+ end
389
+
390
+ super(io)
391
+ end
392
+
393
+ def show_bar?
394
+ @bar != nil
395
+ end
396
+
397
+ def read(length)
398
+ buf = __getobj__.read(length)
399
+ unless @bar.nil? || buf.nil?
400
+ @bar.progress += buf.bytesize
401
+ end
402
+
403
+ buf
404
+ end
405
+ end
406
+
289
407
  def die!(msg, err = nil, command = nil)
290
408
  shell.say msg, :red
291
409
  help(command) if command
292
410
  shell.say %Q(#{err.class.name}: #{err}\n#{err.backtrace.join("\n")}) if err && ENV['DEBUG']
293
411
  exit(1)
294
412
  end
413
+
414
+ def time_ago(tm)
415
+ ago = tm.strftime('%F %R')
416
+
417
+ in_secs = Time.now - tm
418
+ if in_secs < 60
419
+ ago += ' (~ %ds ago)' % in_secs
420
+ elsif in_secs < 3600
421
+ ago += ' (~ %sm ago)' % (in_secs / 60).floor
422
+ elsif in_secs < (3600 * 24)
423
+ ago += ' (~ %sh ago)' % (in_secs / 3600).floor
424
+ end
425
+
426
+ ago
427
+ end
295
428
  end
@@ -1,72 +1,48 @@
1
1
  module Gemfury
2
- # Defines constants and methods related to configuration
3
2
  module Configuration
4
- # An array of valid keys in the options hash when configuring
5
- VALID_OPTIONS_KEYS = [
6
- :user_api_key,
7
- :adapter,
8
- :endpoint,
9
- :gitpoint,
10
- :pushpoint,
11
- :user_agent,
12
- :api_version,
13
- :account].freeze
14
3
 
15
- # The adapter that will be used to connect if none is set
16
- DEFAULT_ADAPTER = :net_http
17
-
18
- # The endpoint that will be used to connect if none is set
19
- DEFAULT_ENDPOINT = 'https://api.fury.io/'.freeze
4
+ CONFIGURATION_DEFAULTS = {
5
+ :user_api_key => nil,
6
+ :adapter => :net_http,
7
+ :endpoint => 'https://api.fury.io/',
8
+ :gitpoint => 'https://git.fury.io/',
9
+ :pushpoint => 'https://push.fury.io/',
10
+ :user_agent => "Gemfury RubyGem #{Gemfury::VERSION} (Ruby #{RUBY_VERSION})",
11
+ :api_version => 1,
12
+ :account => nil
13
+ }.freeze
14
+
15
+ # user API key, also known as "full access token"
16
+ # @return [String]
17
+ attr_accessor :user_api_key
18
+
19
+ # The adapter that will be used to connect
20
+ # @return [Symbol]
21
+ attr_accessor :adapter
22
+
23
+ # The endpoint that will be used to connect
24
+ # @return [String]
25
+ attr_accessor :endpoint
20
26
 
21
27
  # The HTTP endpoint for git repo (used for .netrc credentials)
22
- DEFAULT_GITPOINT = 'https://git.fury.io/'.freeze
23
-
24
- # The endpoint for the Push API if not set
25
- DEFAULT_PUSHPOINT = 'https://push.fury.io/'.freeze
26
-
27
- # The value sent in the 'User-Agent' header if none is set
28
- DEFAULT_USER_AGENT = "Gemfury RubyGem #{Gemfury::VERSION}".freeze
29
-
30
- # Default API version
31
- DEFAULT_API_VERSION = 1
32
-
33
- # Default user API key
34
- DEFAULT_API_KEY = nil
35
-
36
- # Use the current account (no impersonation)
37
- DEFAULT_ACCOUNT = nil
38
-
39
- # @private
40
- attr_accessor *VALID_OPTIONS_KEYS
28
+ # @return [String]
29
+ attr_accessor :gitpoint
41
30
 
42
- # When this module is extended, set all configuration options to their default values
43
- def self.extended(base)
44
- base.reset
45
- end
31
+ # The endpoint for the Push API
32
+ # @return [String]
33
+ attr_accessor :pushpoint
46
34
 
47
- # Convenience method to allow configuration options to be set in a block
48
- def configure
49
- yield self
50
- end
35
+ # The value sent in the 'User-Agent' header
36
+ # @return [String]
37
+ attr_accessor :user_agent
51
38
 
52
- # Create a hash of options and their values
53
- def options
54
- options = {}
55
- VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
56
- options
57
- end
39
+ # Gemfury remote API version
40
+ # @return [Integer]
41
+ attr_accessor :api_version
58
42
 
59
- # Reset all configuration options to defaults
60
- def reset
61
- self.user_api_key = DEFAULT_API_KEY
62
- self.adapter = DEFAULT_ADAPTER
63
- self.endpoint = DEFAULT_ENDPOINT
64
- self.gitpoint = DEFAULT_GITPOINT
65
- self.pushpoint = DEFAULT_PUSHPOINT
66
- self.user_agent = DEFAULT_USER_AGENT
67
- self.api_version = DEFAULT_API_VERSION
68
- self.account = DEFAULT_ACCOUNT
69
- self
70
- end
43
+ # The account to impersonate, if you have permissions for multiple accounts
44
+ # (If nil, no impersonation)
45
+ # @return [String]
46
+ attr_accessor :account
71
47
  end
72
48
  end
@@ -1,3 +1,3 @@
1
1
  module Gemfury
2
- VERSION = '0.10.0.rc1'
2
+ VERSION = '0.12.0.rc2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemfury
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0.rc1
4
+ version: 0.12.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Rykov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-21 00:00:00.000000000 Z
11
+ date: 2020-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: 0.14.0
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: 1.0.0.pre
36
+ version: 1.1.0.pre
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 0.14.0
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: 1.0.0.pre
46
+ version: 1.1.0.pre
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: netrc
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -73,7 +73,7 @@ dependencies:
73
73
  version: 0.9.0
74
74
  - - "<"
75
75
  - !ruby/object:Gem::Version
76
- version: 0.16.0.pre
76
+ version: 1.1.0.pre
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
@@ -83,7 +83,7 @@ dependencies:
83
83
  version: 0.9.0
84
84
  - - "<"
85
85
  - !ruby/object:Gem::Version
86
- version: 0.16.0.pre
86
+ version: 1.1.0.pre
87
87
  - !ruby/object:Gem::Dependency
88
88
  name: highline
89
89
  requirement: !ruby/object:Gem::Requirement
@@ -104,6 +104,26 @@ dependencies:
104
104
  - - "<"
105
105
  - !ruby/object:Gem::Version
106
106
  version: 2.1.0.pre
107
+ - !ruby/object:Gem::Dependency
108
+ name: progressbar
109
+ requirement: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: 1.10.1
114
+ - - "<"
115
+ - !ruby/object:Gem::Version
116
+ version: 2.0.0.pre
117
+ type: :runtime
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: 1.10.1
124
+ - - "<"
125
+ - !ruby/object:Gem::Version
126
+ version: 2.0.0.pre
107
127
  description: 'Hosted repo for your public and private packages at https://gemfury.com
108
128
 
109
129
  '