Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Staging Repositories #70

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
script: "bundle exec thor spec:unit"
language: ruby
rvm:
- 1.9.2
- 1.9.3
1 change: 1 addition & 0 deletions features/nexus_oss.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Feature: Use the Nexus CLI
"""
And the exit status should be 0

@wip
@push
Scenario: Push an Artifact
When I push an artifact with the GAV of "com.test:mytest:tgz:1.0.0"
Expand Down
11 changes: 11 additions & 0 deletions features/pro/nexus_staging.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Feature: Use the Nexus CLI to execute commands that interact with the Nexus Pro Staging Suite
As a Pro CLI user
I need commands to start, close, and release Nexus Staging Repositories

Scenario: Start a Staging Repository
When I call the nexus "start_staging" command
Then the output should contain:
"""
rcs-005
"""
And the exit status should be 0
3 changes: 2 additions & 1 deletion features/step_definitions/cli_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
end

When /^I push an artifact with the GAV of "(.*)"$/ do |gav|
groupId, artifact_id, version, extension = gav.split(":")
groupId, artifact_id, extension, version = gav.split(":")
file = File.new(File.join(temp_dir, "#{artifact_id}-#{version}.#{extension}"), 'w')
file.puts "some data"
file.close
puts "nexus-cli push #{gav} #{file.path} --overrides=#{get_overrides_string}"
step "I run `nexus-cli push #{gav} #{file.path} --overrides=#{get_overrides_string}`"
end

Expand Down
1 change: 1 addition & 0 deletions lib/nexus_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module NexusCli
autoload :LoggingActions, 'nexus_cli/mixins/logging_actions'
autoload :CustomMetadataActions, 'nexus_cli/mixins/pro/custom_metadata_actions'
autoload :SmartProxyActions, 'nexus_cli/mixins/pro/smart_proxy_actions'
autoload :StagingActions, 'nexus_cli/mixins/pro/staging_actions'

class << self
def root
Expand Down
3 changes: 3 additions & 0 deletions lib/nexus_cli/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def validate!(config)
m = m.is_a?(String) ? m.gsub(' ', '_').downcase : m
}

attribute :default_profile_id,
type: String

attribute :username,
type: String,
required: true
Expand Down
68 changes: 68 additions & 0 deletions lib/nexus_cli/mixins/pro/staging_actions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
module NexusCli
module StagingActions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should these actions have staging in the name somewhere, or are you OK there won't be conflicts?


# Starts a new staging repository with the ruleset defined
# by the given staging_profile_id
#
# @param staging_profile_id [String]
#
# @return [String] the repository id of the new staging repository
def start(staging_profile_id = configuration['default_profile_id'], description = "Starting Repository")
response = nexus.post(nexus_url("service/local/staging/profiles/#{staging_profile_id}/start"), :body => create_promote_request(description), :header => DEFAULT_CONTENT_TYPE_HEADER)
case response.status
when 201
JSON.parse(response.body)["data"]["stagedRepositoryId"]
else
raise UnexpectedStatusCodeException.new(response.status)
end
end

# Closes the given staging repository
#
# @param repository_id [String]
# @param description = "Closing Repository" [String]
#
# @return [Boolean]
def close(repository_id, description = "Closing Repository")
response = nexus.post(nexus_url("service/local/staging/bulk/close"), :body => staging_lifecycle_payload(repository_id, description), :header => DEFAULT_CONTENT_TYPE_HEADER)
case response.status
when 201
true
else
raise UnexpectedStatusCodeException.new(response.status)
end
end

# Releases the given staging repository
#
#
# @return [Bolean]
def release
response = nexus.post(nexus_url("service/local/staging/bulk/promote"), :body => staging_lifecycle_payload(repository_id, description), :header => DEFAULT_CONTENT_TYPE_HEADER)
case response.status
when 201
true
else
raise UnexpectedStatusCodeException.new(response.status)
end
end

def profiles
response = nexus.get(nexus_url("service/local/staging/profiles"))
response.body
end

private

def create_promote_request(description)
json_payload = { "data" => { "description" => description } }
JSON.dump(json_payload)
end

def staging_lifecycle_payload(repository_id, promotion_id = nil, description)
json_payload = { "data" => { "stagedRepositoryIds" => Array(repository_id), "description" => description}}
json_payload["stagingProfileGroup"] = promotion_id unless promotion_id.nil?
JSON.dump(json_payload)
end
end
end
1 change: 1 addition & 0 deletions lib/nexus_cli/remote/pro_remote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ProRemote < BaseRemote
include RepositoryActions
include SmartProxyActions
include UserActions
include StagingActions

def get_license_info
response = nexus.get(nexus_url("service/local/licensing"), :header => DEFAULT_ACCEPT_HEADER)
Expand Down
12 changes: 12 additions & 0 deletions lib/nexus_cli/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ def self.included(base)
:default => true,
:desc => "Set to false to disable SSL Verification."

desc "start_staging", "Starts a new staging repository"
def start_staging
say nexus_remote.start
end

desc "close_staging repository_id", "Closes the provided staging repository"
def close_staging(repository_id)
if nexus_remote.close(repository_id)
say "Staging repository #{repository_id} has been closed."
end
end

method_option :destination,
:type => :string,
:default => nil,
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/nexus_cli/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
described_class.new(url: nil, repository: "something", username: "someone", password: "somepass")
end

context "when the object is invalide" do
context "when the object is invalid" do
it "raises an error" do
expect { validate! }.to raise_error(NexusCli::InvalidSettingsException)
end
Expand Down