class Lita::Handlers::Nexus

Public Instance Methods

cmd_artifact_info(response) click to toggle source
# File lib/lita/handlers/nexus.rb, line 99
def cmd_artifact_info(response)
  coordinate = response.matches[0][0]
  info = get_artifact_info(coordinate)
  response.reply info
end
cmd_delete_artifact(response) click to toggle source
# File lib/lita/handlers/nexus.rb, line 163
def cmd_delete_artifact(response)
  coordinate = response.matches[0][0]
  begin
    delete_artifact(coordinate)
    #response.reply "Artifact deleted successfully."
    response.reply t('msg.info_artifact_deleted')
  rescue Exception => e
    response.reply e.message
  end
end
cmd_get_artifact_versions(response) click to toggle source
# File lib/lita/handlers/nexus.rb, line 193
def cmd_get_artifact_versions(response)
  coordinate = response.matches[0][0]
  begin
    info = search_for_artifact(coordinate)
    # now parsing xml result
    dom = Nokogiri::XML(info)do |config|
      config.strict.nonet
    end

    data = dom.xpath('//artifact/version')
    versions =[]
    data.each do |version|
      versions << version.text
    end
    versions.sort! {|x,y|
      Versionomy.parse(x) <=> Versionomy.parse(y)
    }
    response.reply versions.to_s
  rescue Exception =>e
    response.reply e.message
  end

end
cmd_license_info(response) click to toggle source
# File lib/lita/handlers/nexus.rb, line 152
def cmd_license_info(response)
  info = get_license_info
  response.reply info
end
cmd_push_artifact(coordinate, file_path) click to toggle source
# File lib/lita/handlers/nexus.rb, line 189
def cmd_push_artifact(coordinate, file_path)
   push_artifact(coordinate, file_path)
end
cmd_repo_info(response) click to toggle source
# File lib/lita/handlers/nexus.rb, line 157
def cmd_repo_info(response)
  repo_name = response.matches[0][0]
  info = get_repository_info repo_name
  response.reply info
end
cmd_search_artifact(response) click to toggle source
# File lib/lita/handlers/nexus.rb, line 105
def cmd_search_artifact(response)
  coordinate = response.matches[0][0]
  limit = response.matches[0][1]
  return_limit  = nil
  if !limit.nil? && ! limit.empty?
    return_limit = Integer(limit)
  end
  begin
    info = search_for_artifact(coordinate)
    # now parsing xml result
    dom = Nokogiri::XML(info)do |config|
      config.strict.nonet
    end
    total_count = dom.xpath('//totalCount').text
    data = dom.xpath('//artifact')
    all_versions = {}
    data.each do |artifact|
      version_str= artifact.xpath('version').text
      artifact_output = StringIO.open do |s|
        s.puts "[Coordinate] #{artifact.xpath('groupId').text}:#{artifact.xpath('artifactId').text}:#{artifact.xpath('version').text}:#{artifact.xpath('packaging').text}"
        s.puts "[Download URL] #{artifact.xpath('resourceURI').text}"
        s.puts "[Repository] #{artifact.xpath('repoId').text}(#{artifact.xpath('contextId').text})"
        s.string
      end
      all_versions[version_str]= artifact_output
    end

    response.reply "Artifact found: #{all_versions.size}, showing max #{return_limit||config.search_limit} of latest version"
    out_artifacts = []
    unless all_versions.empty?
      all_versions.sort_by {|k,v|
        Versionomy.parse(k)
      }
      tmp_artifacts = all_versions.values.reverse
      out_artifacts = tmp_artifacts.first(return_limit||config.search_limit)
    end
    index = 0
    out_artifacts.each do |artifact|
      index = index +1
      response.reply "Artifact #{index}:"
      response.reply artifact
    end
  rescue Exception =>e
    response.reply e.message
  end
end
cmd_set_current_repository(response) click to toggle source
# File lib/lita/handlers/nexus.rb, line 174
def cmd_set_current_repository(response)
  repo = response.matches[0][0]
  if repo && repo.strip.length >0
    config.current_repository = repo
  end
  #response.reply "Success: current repository is changed to #{repo}."
  response.reply t('msg.info_repos_set_success', repo: repo)
end
cmd_show_current_repository(response) click to toggle source
# File lib/lita/handlers/nexus.rb, line 183
def cmd_show_current_repository(response)
  current_repo = get_current_repo
  #response.reply "Current repository is #{current_repo}"
  response.reply t('msg.info_current_repo_is', repo: current_repo)
end