Skip to content

Instantly share code, notes, and snippets.

@ziyadbasheer
Last active August 29, 2015 14:14
Show Gist options
  • Save ziyadbasheer/71d6113c28bf0b99d137 to your computer and use it in GitHub Desktop.
Save ziyadbasheer/71d6113c28bf0b99d137 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'find'
require 'fileutils'
require 'shell'
require 'pp'
require 'ostruct'
require 'uri'
class RepoHandler
def initialize
@dirs = []
@files = []
@repo = OpenStruct.new
end
def clone_app(uri)
@repo.directory = URI(uri).path.split('/')[2]
`git clone #{uri} temp_repos/#{@repo.directory}`
end
def find_tree
Find.find("temp_repos/#{@repo.directory}") do |path|
filename = File.basename(path)
if FileTest.directory?(path)
if filename[0] == ?.
Find.prune
else
@dirs << filename
next
end
else
@files << filename unless filename == ?.
end
end
end
# Check app framework
def find_framework
puts "Now finding framework"
list = @files
if list.include?("Gemfile")
File.readlines("Gemfile").each do |line|
if line.include?('rails')
@repo.framework = "rails"
break
elsif line.include?('sinatra')
@repo.framework = "sinatra"
break
end
end
elsif list.include?("requirements.txt")
File.readlines("requirements.txt").each do |line|
if line.include?('Django')
@repo.framework = "django"
break
elsif line.include?('Flask')
@repo.framework = "flask"
break
end
end
elsif list.include?("package.json")
@repo.framework = "node.js"
else
@repo.framework = "none"
end
# "FILE LIST IS "
# puts @files
# " REPO VAR NOW CONTAINS"
# puts @repo.framework
end
def repo
return @repo
end
def files
return @files
end
end
test = RepoHandler.new
test.clone_app(ARGV[0])
test.find_tree
test.find_framework
puts "***** FRAMEWORK IS *****"
puts test.repo.framework
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment