foy_runner 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 32db90a6b4ae9cf3584a6420632912cefd107191
4
+ data.tar.gz: fc2b11571002c095095c318d78a7ebc8f3966c67
5
+ SHA512:
6
+ metadata.gz: b14f58d4e11f3a7d6f70361935692eab453f2809071b2e6521abe4bb94c4faae34d3d267a5f56689144440b166e03b5269f0fd7714da125774190b6e4bed3a03
7
+ data.tar.gz: 86d04367c9a932cdefddb63a784bd8cd85fd1ba90936e855f03321ed3279758761d91fa187f75f6a8422cc724af2e8dbcd2cf7231ef3e029c890a606d10588f6
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ foy-runner
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p353
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Roberto Soares
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Foy::Runner
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'foy-runner'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install foy-runner
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/foy-runner/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/foy-runner ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'foy_api_client'
5
+ require_relative '../lib/foy_runner'
6
+
7
+ client = Foy::API::Client::Base.new ARGV[0]
8
+ runner = Foy::Runner::Base.new client
9
+
10
+ runner.collect_project_packages
11
+ runner.update_packages
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'foy_runner/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "foy_runner"
8
+ spec.version = Foy::Runner::VERSION
9
+ spec.authors = ["Roberto Soares"]
10
+ spec.email = ["contact@robertosoares.me"]
11
+ spec.summary = %q{Foy Runner}
12
+ spec.description = %q{Foy Runner}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", ">= 2.14.1"
24
+ spec.add_development_dependency "byebug"
25
+
26
+ spec.add_dependency "foy_api_client", "~> 0.1.0"
27
+ spec.add_dependency "foy_ruby_handler", "~> 0.1.0"
28
+ end
@@ -0,0 +1,20 @@
1
+ module Foy
2
+ module Runner
3
+ class GitFetcher
4
+ def initialize(url)
5
+ @url = url
6
+ end
7
+
8
+ def get(file)
9
+ @dir = Dir.mktmpdir
10
+ `git clone -n #{@url} #{@dir} --depth 1`
11
+ `cd #{@dir}; git checkout HEAD #{file}`
12
+ File.join(@dir, file)
13
+ end
14
+
15
+ def clean_up
16
+ FileUtils.remove_entry_secure @dir if @dir
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ module Foy
2
+ module Runner
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
data/lib/foy_runner.rb ADDED
@@ -0,0 +1,42 @@
1
+ require_relative "foy_runner/git_fetcher"
2
+ require "foy_api_client"
3
+ require "foy_ruby_handler"
4
+
5
+ module Foy
6
+ module Runner
7
+ class Base
8
+ def initialize(client)
9
+ @client = client
10
+ end
11
+
12
+ def collect_project_packages
13
+ projects = @client.get_projects
14
+ projects.each do |project|
15
+ git_fetcher = Foy::Runner::GitFetcher.new(project.repository)
16
+ begin
17
+ file = git_fetcher.get("Gemfile.lock")
18
+ packages = Foy::RubyHandler.parse(file)
19
+ @client.put_project_packages(system: 'rubygems', project_id: project.id, packages: packages)
20
+ #rescue
21
+ #TODO error handling
22
+ ensure
23
+ git_fetcher.clean_up
24
+ end
25
+ end
26
+ end
27
+
28
+ def update_packages
29
+ packages = @client.get_packages(system: 'rubygems')
30
+
31
+ updated_packages = packages.collect do |package|
32
+ {
33
+ name: package.name,
34
+ version: Foy::RubyHandler.latest_version_for(package.name)
35
+ }
36
+ end
37
+
38
+ @client.put_packages(system: 'rubygems', packages: updated_packages)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Foy::Runner::GitFetcher do
4
+ let(:url) { "git://github.com/fountain-of-youth/foy-web.git" }
5
+ let(:fetcher) { Foy::Runner::GitFetcher.new(url) }
6
+
7
+ describe "#get" do
8
+ it "uses a tmp dir" do
9
+ Dir.should_receive(:mktmpdir).and_call_original
10
+ fetcher.get("Gemfile.lock")
11
+ end
12
+ end
13
+
14
+ describe "#clean_up" do
15
+ context "called after temp dir has been created" do
16
+ before do
17
+ fetcher.get("any")
18
+ end
19
+
20
+ it "removes folder securely" do
21
+ FileUtils.should_receive(:remove_entry_secure)
22
+ fetcher.clean_up
23
+ end
24
+ end
25
+
26
+ context "called before temp dir has been created" do
27
+ it "does nothing" do
28
+ FileUtils.should_not_receive(:remove_entry_secure)
29
+ fetcher.clean_up
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,93 @@
1
+ require 'spec_helper'
2
+
3
+ describe Foy::Runner::Base do
4
+ subject do
5
+ Foy::Runner::Base.new(client)
6
+ end
7
+
8
+ let(:client) do
9
+ double(:client)
10
+ end
11
+
12
+ describe ".collect_project_packages" do
13
+ let(:projects) do
14
+ [
15
+ OpenStruct.new(id: '1', repository: 'https://repo/example1.git'),
16
+ OpenStruct.new(id: '2', repository: 'https://repo/example2.git')
17
+ ]
18
+ end
19
+
20
+ let(:packages1) do
21
+ double(:packages1)
22
+ end
23
+
24
+ let(:packages2) do
25
+ double(:packages2)
26
+ end
27
+
28
+ let(:file) do
29
+ double(:file)
30
+ end
31
+
32
+ let(:fetcher) do
33
+ double(:fetcher, get: file, clean_up: nil)
34
+ end
35
+
36
+ before do
37
+ client.stub(:get_projects).and_return(projects)
38
+ client.stub(:put_project_packages)
39
+ Foy::Runner::GitFetcher.stub(:new).and_return(fetcher)
40
+ Foy::RubyHandler.stub(:parse)
41
+ end
42
+
43
+ context "successful collecting" do
44
+ it "parses Gemfile.lock for each project" do
45
+ fetcher.should_receive(:get).with("Gemfile.lock").twice
46
+ subject.collect_project_packages
47
+ end
48
+
49
+ it "sends packages to foy-api for each project" do
50
+ Foy::RubyHandler.stub(:parse).
51
+ and_return(packages1, packages2)
52
+
53
+ client.should_receive(:put_project_packages).
54
+ with(system: 'rubygems', project_id: '1', packages: packages1).
55
+ ordered
56
+
57
+ client.should_receive(:put_project_packages).
58
+ with(system: 'rubygems', project_id: '2', packages: packages2).
59
+ ordered
60
+
61
+ subject.collect_project_packages
62
+ end
63
+
64
+ it "cleans the git fetcher" do
65
+ fetcher.should_receive(:clean_up).twice
66
+ subject.collect_project_packages
67
+ end
68
+ end
69
+ end
70
+
71
+ describe ".update_packages" do
72
+ let(:packages) do
73
+ [OpenStruct.new(name: 'rspec', version: '1.0.0')]
74
+ end
75
+
76
+ before do
77
+ client.stub(:get_packages).and_return(packages)
78
+ client.stub(:put_packages)
79
+ Foy::RubyHandler.stub(:latest_version_for).and_return('2.0.0')
80
+ end
81
+
82
+ it "uses RubyHandler to get the last version" do
83
+ Foy::RubyHandler.should_receive(:latest_version_for).once
84
+ subject.update_packages
85
+ end
86
+
87
+ it "sends updated packages" do
88
+ client.should_receive(:put_packages).
89
+ with(system: 'rubygems', packages: [{name: 'rspec', version: '2.0.0'}])
90
+ subject.update_packages
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,9 @@
1
+ RSpec.configure do |config|
2
+ config.treat_symbols_as_metadata_keys_with_true_values = true
3
+ config.run_all_when_everything_filtered = true
4
+ config.filter_run :focus
5
+
6
+ config.order = 'random'
7
+ end
8
+
9
+ require 'foy_runner'
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: foy_runner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Roberto Soares
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 2.14.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 2.14.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: foy_api_client
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 0.1.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.1.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: foy_ruby_handler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 0.1.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 0.1.0
97
+ description: Foy Runner
98
+ email:
99
+ - contact@robertosoares.me
100
+ executables:
101
+ - foy-runner
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - .gitignore
106
+ - .ruby-gemset
107
+ - .ruby-version
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/foy-runner
113
+ - foy-runner.gemspec
114
+ - lib/foy_runner.rb
115
+ - lib/foy_runner/git_fetcher.rb
116
+ - lib/foy_runner/version.rb
117
+ - spec/foy_runner_git_fetcher_spec.rb
118
+ - spec/foy_runner_spec.rb
119
+ - spec/spec_helper.rb
120
+ homepage: ''
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.2.1
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Foy Runner
144
+ test_files:
145
+ - spec/foy_runner_git_fetcher_spec.rb
146
+ - spec/foy_runner_spec.rb
147
+ - spec/spec_helper.rb