Class: PackageCloud::CLI::Entry

Inherits:
Base
  • Object
show all
Defined in:
lib/package_cloud/cli/entry.rb

Instance Method Summary collapse

Instance Method Details

#promote(source_repo_desc, package_name, dest_repo_desc) ⇒ Object


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/package_cloud/cli/entry.rb', line 28

def promote(source_repo_desc, package_name, dest_repo_desc)
  repo_name = source_repo_desc.split("/")[0..1].join("/")
  dist = expand_dist_shortcut(source_repo_desc.split("/")[2..3].join("/"))

  dest_repo_name = expand_dist_shortcut(dest_repo_desc.split("/")[0..1].join("/"))

  if dist == "" && package_name =~ /\.gem$/
    dist = "gems"
  end

  print "Looking for source repository at #{repo_name}... "
  src_repo = client.repository(source_repo_desc)
  print "success!\n"

  print "Looking for destination repository at #{dest_repo_name}... "
  repo = client.repository(dest_repo_desc)
  print "success!\n"

  if package_name.include?('@')
    scope, unscoped_package_name = package_scope(package_name)

    print "Attempting to promote scoped package #{scope}/#{unscoped_package_name} from #{repo_name}/#{dist} to #{dest_repo_name}..."
    packages = src_repo.promote(dist, unscoped_package_name, dest_repo_name, scope)
  else
    print "Attempting to promote #{repo_name}/#{dist}/#{package_name} to #{dest_repo_name}..."
    packages = src_repo.promote(dist, package_name, dest_repo_name)
  end
  puts "done!".color(:green)

  if dist == "node/1"
    puts "WARNING: This Node.js package will NOT be downloadable by clients until a dist tag is created. Read more: https://packagecloud.io/docs/#node_promote".color(:yellow)
  end
end

#push(repo, package_file, *package_files) ⇒ Object


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/package_cloud/cli/entry.rb', line 109

def push(repo, package_file, *package_files)
  total_time = Benchmark.measure do
    ARGV.clear # otherwise gets explodes
    package_files << package_file

    exts = package_files.map { |f| f.split(".").last }.uniq

    if package_files.length > 1 && exts.length > 1
      abort("You can't push multiple packages of different types at the same time.\nFor example, use *.deb to push all your debs at once.".color(:red))
    end

    invalid_packages = package_files.select do |f|
      !SUPPORTED_EXTS.include?(f.split(".").last.downcase)
    end

    if JAVA_EXTS.include?(exts.first.downcase) && options.has_key?("coordinates")
      puts "Using coordinates #{options["coordinates"].color(:yellow)}"
    end

    if !options.has_key?("skip-file-ext-validation") && invalid_packages.any?
      message = "I don't know how to push these packages:\n\n".color(:red)
      invalid_packages.each do |p|
        message << "  #{p}\n"
      end
      message << "\npackage_cloud only supports node.js, deb, gem, java, python, "\
                 "rpm, alpine, helm, anyfile (.zip, .asc) packages".color(:red)
      abort(message)
    end

    if !options.has_key?("yes") && exts.first == "gem" && package_files.length > 1
      answer = get_valid("Are you sure you want to push #{package_files.length} packages? (y/n)") do |s|
        s == "y" || s == "n"
      end

      if answer != "y"
        abort("Aborting...".color(:red))
      end
    end

    validator = Validator.new(client)
    if PY_EXTS.include?(exts.first.downcase)
      dist_id   = validator.distribution_id(repo, package_files, 'py')
    elsif ANYFILE_EXTS.include?(exts.first.downcase)
      dist_id   = validator.distribution_id(repo, package_files, 'anyfile')
    elsif NODE_EXTS.include?(exts.first.downcase)
      dist_id   = validator.distribution_id(repo, package_files, 'node')
    elsif JAVA_EXTS.include?(exts.first.downcase)
      abort_if_snapshot!(package_files)
      dist_id   = validator.distribution_id(repo, package_files, 'jar')
    elsif AMBIGUOUS_EXTS.include?(exts.first.downcase)
      dist_id   = validator.distribution_id_from_repo_url(repo, package_files)
    else
      dist_id   = validator.distribution_id(repo, package_files, exts.first)
    end

    # strip os/dist
    split_repo = repo.split("/")[0..1].join("/")

    print "Looking for repository at #{split_repo}... "
    client_repo = nil
    measurement = Benchmark.measure do
      client_repo = client.repository(split_repo)
    end
    print "success!\n"
    $logger.debug("repository lookup request timing: #{measurement}")

    package_files.each do |f|
      files = nil
      ext = f.split(".").last

      if ext == "dsc"
        print "Checking source package #{f}... "
        files = parse_and_verify_dsc(client_repo, f, dist_id)
      end

      print "Pushing #{f}... "
      measurement = Benchmark.measure do
        if options.has_key?("skip-errors")
          create_package_skip_errors(client_repo, f, dist_id, files, ext, options["coordinates"])
        else
          create_package(client_repo, f, dist_id, files, ext, options["coordinates"])
        end
      end
      $logger.debug("create package request timing: #{measurement}")
    end
  end
  $logger.debug("push command total timing: #{total_time}")
end

#versionObject


200
201
202
# File 'lib/package_cloud/cli/entry.rb', line 200

def version
  puts "package_cloud CLI #{VERSION}\nSee https://packagecloud.io/docs#cli for more details."
end

#yank(repo_desc, package_name) ⇒ Object


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/package_cloud/cli/entry.rb', line 64

def yank(repo_desc, package_name)
  ARGV.clear # otherwise gets explodes

  # strip os/dist
  repo_name = repo_desc.split("/")[0..1].join("/")
  dist = expand_dist_shortcut(repo_desc.split("/")[2..3].join("/"))

  if dist == "" && package_name =~ /\.gem$/
    dist = "gems"
  end

  print "Looking for repository at #{repo_name}... "
  repo = client.repository(repo_desc)
  print "success!\n"

  if package_name.include?('@')
    scope, unscoped_package_name = package_scope(package_name)
    print "Attempting to yank scoped package at #{repo_name}/#{dist} #{package_name}..."
    repo.yank(dist, unscoped_package_name, scope)
  else
    print "Attempting to yank package at #{repo_name}/#{dist}/#{package_name}..."
    repo.yank(dist, package_name)
  end
  puts "done!".color(:green)

  if dist == "node/1"
    puts "WARNING: Deleting Node.js packages can have unexpected side effects with dist tags. Read more: https://packagecloud.io/docs/#node_delete".color(:yellow)
  end
end