lita-nexus 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -2
- data/CHANGELOG.md +4 -0
- data/README.md +2 -1
- data/lib/lita/handlers/nexus.rb +78 -14
- data/lib/nexushelper/remote.rb +24 -2
- data/lita-nexus.gemspec +2 -1
- data/locales/en.yml +4 -2
- data/spec/lita/handlers/nexus_spec.rb +25 -10
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbc794f471930b728dd358f570eed7a89597af0b
|
4
|
+
data.tar.gz: 1e70eb6098a4976efd221b6979ba4483b55b68b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e599ffc8b730fd4f609f682c72ae9282ffaf88bfb52b36ab88180c0c7d878631d9e231e149fc78058bc8da5de392ece0fca8bdc2f5140e9ac0d1679434afb5a6
|
7
|
+
data.tar.gz: c62d35d0703b6624fa0f0e0b08dd7c7d9906cc747ea6c51de6b3665541208b8da12793daba8526fd6defbba5e5a4b0879d868ea819ca4be636f7283e48472477
|
data/.rspec
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
--format
|
2
|
-
|
1
|
+
--format documentation
|
2
|
+
--color
|
3
3
|
--fail-fast
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -37,8 +37,9 @@ end
|
|
37
37
|
|
38
38
|
* nexus artifact info webapps:sweetrewards:tar.gz:1.8.0
|
39
39
|
* nexus delete artifact webapps:sweetrewards:tar.gz:1.8.0
|
40
|
-
* nexus search artifact webapps:sweetrewards
|
40
|
+
* nexus search artifact webapps:sweetrewards [limit 5]# only groupId and artifacId are effective, default return 5 latest version
|
41
41
|
* nexus license info # only for pro version
|
42
42
|
* nexus repo info snapshots
|
43
43
|
* nexus show current repo
|
44
44
|
* nexus set current repo releases
|
45
|
+
* nexus get artifact versions webapps:sweetrewards # use groupId and artifactId, limit to latest 5 versions by default
|
data/lib/lita/handlers/nexus.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'nokogiri'
|
2
|
+
require 'versionomy'
|
3
|
+
|
2
4
|
|
3
5
|
module Lita
|
4
6
|
module Handlers
|
@@ -16,6 +18,7 @@ module Lita
|
|
16
18
|
config :verify_ssl, required: false, type: [TrueClass,FalseClass], default: false
|
17
19
|
config :rsa_private_key, required: true, type: String
|
18
20
|
config :current_repository, required: false, type: String
|
21
|
+
config :search_limit, required: false, type: Integer, default: 5
|
19
22
|
|
20
23
|
|
21
24
|
include ::LitaNexusHelper::Remote
|
@@ -30,7 +33,7 @@ module Lita
|
|
30
33
|
)
|
31
34
|
|
32
35
|
route(
|
33
|
-
/^nexus\s+search\s+artifact\s+(\S+)\s*$/,
|
36
|
+
/^nexus\s+search\s+artifact\s+([\S:]+)(?>\s+limit\s+)?(\d+)?\s*$/,
|
34
37
|
:cmd_search_artifact,
|
35
38
|
command: true,
|
36
39
|
help: {
|
@@ -83,28 +86,65 @@ module Lita
|
|
83
86
|
}
|
84
87
|
)
|
85
88
|
|
89
|
+
route(
|
90
|
+
/^nexus\s+get\s+artifact\s+versions\s+(\S+)\s*$/,
|
91
|
+
:cmd_get_artifact_versions,
|
92
|
+
command: true,
|
93
|
+
help: {
|
94
|
+
t('help.cmd_get_artifact_versions_key') => t('help.cmd_get_artifact_versions_value')
|
95
|
+
}
|
96
|
+
)
|
86
97
|
|
87
98
|
def cmd_artifact_info(response)
|
88
99
|
coordinate = response.matches[0][0]
|
89
|
-
puts "coordinate = #{coordinate}"
|
90
100
|
info = get_artifact_info(coordinate)
|
91
101
|
response.reply info
|
92
102
|
end
|
93
103
|
|
94
104
|
def cmd_search_artifact(response)
|
95
105
|
coordinate = response.matches[0][0]
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
config.strict.nonet
|
106
|
+
limit = response.matches[0][1]
|
107
|
+
return_limit = nil
|
108
|
+
if !limit.nil? && ! limit.empty?
|
109
|
+
return_limit = Integer(limit)
|
101
110
|
end
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
111
|
+
begin
|
112
|
+
info = search_for_artifact(coordinate)
|
113
|
+
# now parsing xml result
|
114
|
+
dom = Nokogiri::XML(info)do |config|
|
115
|
+
config.strict.nonet
|
116
|
+
end
|
117
|
+
total_count = dom.xpath('//totalCount').text
|
118
|
+
data = dom.xpath('//artifact')
|
119
|
+
all_versions = {}
|
120
|
+
data.each do |artifact|
|
121
|
+
version_str= artifact.xpath('version').text
|
122
|
+
artifact_output = StringIO.open do |s|
|
123
|
+
s.puts "[Coordinate] #{artifact.xpath('groupId').text}:#{artifact.xpath('artifactId').text}:#{artifact.xpath('version').text}:#{artifact.xpath('packaging').text}"
|
124
|
+
s.puts "[Download URL] #{artifact.xpath('resourceURI').text}"
|
125
|
+
s.puts "[Repository] #{artifact.xpath('repoId').text}(#{artifact.xpath('contextId').text})"
|
126
|
+
s.string
|
127
|
+
end
|
128
|
+
all_versions[version_str]= artifact_output
|
129
|
+
end
|
130
|
+
|
131
|
+
response.reply "Artifact found: #{all_versions.size}, showing max #{return_limit||config.search_limit} of latest version"
|
132
|
+
out_artifacts = []
|
133
|
+
unless all_versions.empty?
|
134
|
+
all_versions.sort_by {|k,v|
|
135
|
+
Versionomy.parse(k)
|
136
|
+
}
|
137
|
+
tmp_artifacts = all_versions.values.reverse
|
138
|
+
out_artifacts = tmp_artifacts.first(return_limit||config.search_limit)
|
139
|
+
end
|
140
|
+
index = 0
|
141
|
+
out_artifacts.each do |artifact|
|
142
|
+
index = index +1
|
143
|
+
response.reply "Artifact #{index}:"
|
144
|
+
response.reply artifact
|
145
|
+
end
|
146
|
+
rescue Exception =>e
|
147
|
+
response.reply e.message
|
108
148
|
end
|
109
149
|
end
|
110
150
|
|
@@ -134,7 +174,7 @@ module Lita
|
|
134
174
|
if repo && repo.strip.length >0
|
135
175
|
config.current_repository = repo
|
136
176
|
end
|
137
|
-
response.reply "
|
177
|
+
response.reply "Success: current repository is changed to #{repo}."
|
138
178
|
end
|
139
179
|
|
140
180
|
def cmd_show_current_repository(response)
|
@@ -146,6 +186,30 @@ module Lita
|
|
146
186
|
def cmd_push_artifact(coordinate, file_path)
|
147
187
|
push_artifact(coordinate, file_path)
|
148
188
|
end
|
189
|
+
|
190
|
+
def cmd_get_artifact_versions(response)
|
191
|
+
coordinate = response.matches[0][0]
|
192
|
+
begin
|
193
|
+
info = search_for_artifact(coordinate)
|
194
|
+
# now parsing xml result
|
195
|
+
dom = Nokogiri::XML(info)do |config|
|
196
|
+
config.strict.nonet
|
197
|
+
end
|
198
|
+
|
199
|
+
data = dom.xpath('//artifact/version')
|
200
|
+
versions =[]
|
201
|
+
data.each do |version|
|
202
|
+
versions << version.text
|
203
|
+
end
|
204
|
+
versions.sort! {|x,y|
|
205
|
+
Versionomy.parse(x) <=> Versionomy.parse(y)
|
206
|
+
}
|
207
|
+
response.reply versions.to_s
|
208
|
+
rescue Exception =>e
|
209
|
+
response.reply e.message
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
149
213
|
Lita.register_handler(self)
|
150
214
|
end
|
151
215
|
end
|
data/lib/nexushelper/remote.rb
CHANGED
@@ -40,8 +40,14 @@ module LitaNexusHelper
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def search_for_artifact(coordinate)
|
43
|
-
|
44
|
-
|
43
|
+
begin
|
44
|
+
remote = nexus_remote
|
45
|
+
nexus = remote.nexus
|
46
|
+
#puts nexus.inspect
|
47
|
+
info = remote.search_for_artifacts(coordinate)
|
48
|
+
rescue Exception => e
|
49
|
+
raise "Failed to search: #{e.message}"
|
50
|
+
end
|
45
51
|
end
|
46
52
|
|
47
53
|
def get_license_info
|
@@ -83,5 +89,21 @@ module LitaNexusHelper
|
|
83
89
|
raise "Failed to push artifact, #{e.message}"
|
84
90
|
end
|
85
91
|
end
|
92
|
+
|
93
|
+
def search_with_lucene(coordinate)
|
94
|
+
remote = nexus_remote
|
95
|
+
nexus = remote.nexus
|
96
|
+
artifact = NexusCli::Artifact.new(coordinate)
|
97
|
+
query = {:g => artifact.group_id, :a => artifact.artifact_id, :e => artifact.extension, :v => artifact.version, :r => get_current_repo}
|
98
|
+
query.merge!({:c => artifact.classifier}) unless artifact.classifier.nil?
|
99
|
+
response = nexus.get(remote.nexus_url("service/local/lucene/search"), query)
|
100
|
+
case response.status
|
101
|
+
when 200
|
102
|
+
return response.content
|
103
|
+
else
|
104
|
+
raise UnexpectedStatusCodeException.new(response.status)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
86
108
|
end#module Remote
|
87
109
|
end #module helper
|
data/lita-nexus.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "lita-nexus"
|
3
|
-
spec.version = "0.1.
|
3
|
+
spec.version = "0.1.6"
|
4
4
|
spec.authors = ["Wang, Dawei"]
|
5
5
|
spec.email = ["dwang@entertainment.com"]
|
6
6
|
spec.description = "Lita Nexus Operations"
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.add_runtime_dependency "rack", "~> 1.6"
|
20
20
|
spec.add_runtime_dependency "nexus_cli", "~> 4.1"
|
21
21
|
spec.add_runtime_dependency "nokogiri"
|
22
|
+
spec.add_runtime_dependency "versionomy"
|
22
23
|
|
23
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
25
|
#spec.add_development_dependency "pry-byebug"
|
data/locales/en.yml
CHANGED
@@ -7,8 +7,8 @@ en:
|
|
7
7
|
cmd_artifact_info_value: 'Show artifact info with coordinate'
|
8
8
|
cmd_license_info_key: 'nexus license info'
|
9
9
|
cmd_license_info_value: 'Show license info'
|
10
|
-
cmd_search_artifact_key: 'nexus search artifact COORDINATE'
|
11
|
-
cmd_search_artifact_value: 'Search all versions artifact with coordinate'
|
10
|
+
cmd_search_artifact_key: 'nexus search artifact COORDINATE [limit COUNT]'
|
11
|
+
cmd_search_artifact_value: 'Search all versions artifact with coordinate limit to COUNT latest versions'
|
12
12
|
cmd_repo_info_key: 'nexus repo info REPONAME'
|
13
13
|
cmd_repo_info_value: 'Show repository REPONAME info'
|
14
14
|
cmd_delete_artifact_key: 'nexus delete artifact COORDINATE'
|
@@ -17,3 +17,5 @@ en:
|
|
17
17
|
cmd_show_repo_value: 'Show current repository used'
|
18
18
|
cmd_set_repo_key: 'nexus set current repo REPO'
|
19
19
|
cmd_set_repo_value: 'Set current repository to specified REPO'
|
20
|
+
cmd_get_artifact_versions_key: 'nexus get artifact versions G:A'
|
21
|
+
cmd_get_artifact_versions_value: 'Get all versions of artifact with groupId and artifacId'
|
@@ -88,57 +88,72 @@ describe Lita::Handlers::Nexus, lita_handler: true do
|
|
88
88
|
is_expected.to route_command('nexus delete artifact webapps:sweetrewards:tar.gz:1.8.0').to(:cmd_delete_artifact)
|
89
89
|
is_expected.to route_command('nexus show current repo').to(:cmd_show_current_repository)
|
90
90
|
is_expected.to route_command('nexus set current repo releases').to(:cmd_set_current_repository)
|
91
|
+
is_expected.to route_command('nexus search artifact org.apache.maven.reporting:maven-reporting limit 5').to(:cmd_search_artifact)
|
91
92
|
end
|
92
93
|
|
93
94
|
describe '#get artifact info' do
|
94
95
|
#let(:robot) { Lita::Robot.new(registry) }
|
95
96
|
it 'fecth artifact info' do
|
96
97
|
send_command('nexus artifact info org.apache.maven.reporting:maven-reporting:jar:2.0.9')
|
97
|
-
|
98
|
+
expect(replies.last).to match(/repositoryPath/)
|
98
99
|
end
|
99
100
|
end
|
100
101
|
|
101
102
|
describe '#search artifact info' do
|
102
103
|
it 'search artifact' do
|
104
|
+
send_command('nexus search artifact org.apache.maven.reporting:maven-reporting limit 5')
|
105
|
+
expect(replies.first).to match(/Artifact found: 1/)
|
106
|
+
expect(replies.last).to match(/org.apache.maven.reporting:maven-reporting:2.0.9:jar/)
|
107
|
+
end
|
108
|
+
it 'search artifact with default limit' do
|
103
109
|
send_command('nexus search artifact org.apache.maven.reporting:maven-reporting')
|
104
|
-
|
110
|
+
expect(replies.first).to match(/Artifact found: 1/)
|
111
|
+
expect(replies.last).to match(/org.apache.maven.reporting:maven-reporting:2.0.9:jar/)
|
105
112
|
end
|
106
113
|
end
|
107
114
|
|
108
115
|
describe '#get license info' do
|
109
116
|
it 'fecth server license info' do
|
110
117
|
send_command('nexus license info')
|
111
|
-
|
118
|
+
expect(replies.last).to match(/professional version/)
|
112
119
|
end
|
113
120
|
end
|
114
121
|
|
115
122
|
describe '#get repo info' do
|
116
123
|
it 'fecth repository info' do
|
117
124
|
send_command('nexus repo info snapshots')
|
118
|
-
|
125
|
+
expect(replies.last).to match(/<id>snapshots/)
|
119
126
|
|
120
127
|
end
|
121
128
|
it 'show repository not found' do
|
122
129
|
send_command('nexus repo info notexist')
|
123
|
-
|
130
|
+
expect(replies.last).to match(/not found/)
|
124
131
|
end
|
125
132
|
end
|
126
133
|
|
127
134
|
describe '#show and set current repo' do
|
128
135
|
it 'get current repo' do
|
129
136
|
send_command('nexus show current repo')
|
130
|
-
puts
|
131
|
-
|
137
|
+
#puts replies
|
138
|
+
expect(replies.last).to match(/releases/)
|
132
139
|
end
|
133
140
|
it 'set current repo ' do
|
134
141
|
send_command('nexus set current repo snapshots')
|
135
|
-
|
136
|
-
puts replies
|
142
|
+
expect(replies.last).to match(/Success/)
|
137
143
|
end
|
138
144
|
it 'get current repo' do
|
139
145
|
send_command('nexus show current repo')
|
140
146
|
puts "Getting current repo, changed"
|
141
|
-
puts replies
|
147
|
+
#puts replies
|
148
|
+
expect(replies.last).to match(/snapshots/)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe '#get artifact versions' do
|
153
|
+
it 'get artifact versions' do
|
154
|
+
send_command('nexus get artifact versions org.apache.maven.reporting:maven-reporting')
|
155
|
+
#puts replies
|
156
|
+
expect(replies.last).to match(/[0-9.]+/)
|
142
157
|
end
|
143
158
|
end
|
144
159
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-nexus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wang, Dawei
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: versionomy
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: bundler
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|