Sha256: aa5dc2ffd0cc7842713b5a3de266b3a4ff50a0936227848958705909a0dc3a84
Contents?: true
Size: 1.51 KB
Versions: 20
Compression:
Stored size: 1.51 KB
Contents
# encoding: UTF-8 require "rest_client" require "json" require "open-uri" module Gjp # attempts to get java projects' scm addresses class SourceAddressGetter include Logger # returns the pom corresponding to a file or directory, if it can be found def get_source_address(file) log.info("looking for source address for: #{file}") (get_source_address_from_pom(file) or get_source_address_from_github(file)) end # returns an scm address in a pom file def get_source_address_from_pom(file) pom = Pom.new(file) result = pom.connection_address if result != nil log.info("address found in pom") result end end # returns an scm address looking for it on github def get_source_address_from_github(file) pom = Pom.new(file) result = (github_search(pom.artifact_id) or github_search(pom.artifact_id.split("-").first) or github_search(pom.group_id)) if result != nil log.info("address found on Github: #{result}") result end end # returns a Giuthub repo address based on the keyword def github_search(keyword) if keyword != "" and keyword != nil response = RestClient.get "https://api.github.com/legacy/repos/search/" + CGI::escape(keyword), :user_agent => "gjp/" + Gjp::VERSION, :language => "java", :sort => "forks" json = JSON.parse(response.to_s) (json["repositories"].map {|repository| "git:" + repository["url"]}).first end end end end
Version data entries
20 entries across 20 versions & 1 rubygems