inch_ci-worker 0.3.0.rc9 → 0.3.0.rc10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9874381709670f0694023c6388e915586b2926b1
4
- data.tar.gz: c6b310dd4e3742969c7fc0f7e9fe8138023faccb
3
+ metadata.gz: f72a4bd2a458223d6c2faa1b7ac7ba798e7e6831
4
+ data.tar.gz: d779cbb0aae588155af3c2020c50f79088b2f426
5
5
  SHA512:
6
- metadata.gz: 48d24e7beda00884940b87d2a01a3b85bfb4bb1eb3b3cda9109729d5035d19ba5391c75e5730077acf5e8d249bcf7239095066cee9cc92038d2c6d5ca2927a85
7
- data.tar.gz: 5392b0cc367aa3c1e091c7878b93172f046c22abfabdd9fce03dd0a41b406596d3efd6c2fee684e3cea347a6c5b7b8106d3c6689dc6c52b97986c43af5d5b019
6
+ metadata.gz: 9042d311469257e18c7b8cee67d7f8746aa9ecbca964622d77eed9e2a47ea77841ae485413e5191a4d2fa5d9d77b982695fd72fade73f86e76477f9b61faa5c3
7
+ data.tar.gz: 42b1b1afe829ec4de335830d6033704227f45db8a4c974f8b95c78f3ee948d605fc4f046fdbc7b37a90d1ff53416931d77874c9dac05d71faccb03821e06f279
data/bin/inch_ci-worker CHANGED
@@ -21,6 +21,12 @@ class Command
21
21
  end
22
22
  end
23
23
 
24
+ class BuildJSON
25
+ def initialize(filename)
26
+ InchCI::Worker::BuildJSON::Task.new(filename)
27
+ end
28
+ end
29
+
24
30
  class ListTags
25
31
  def initialize(url, branch_name)
26
32
  InchCI::Worker::ListTags::Task.new(url, branch_name)
@@ -35,6 +41,7 @@ class Command
35
41
 
36
42
  MAP = {
37
43
  'build' => Build,
44
+ 'build-from-json' => BuildJSON,
38
45
  'list-tags' => ListTags,
39
46
  '-v' => Version,
40
47
  }
@@ -1,4 +1,4 @@
1
- require_relative 'build/task'
1
+ require 'inch_ci/worker/build/task'
2
2
 
3
3
  module InchCI
4
4
  module Worker
@@ -0,0 +1,88 @@
1
+ require 'json'
2
+ require 'inch'
3
+ require 'inch/cli'
4
+
5
+ module InchCI
6
+ module Worker
7
+ module BuildJSON
8
+ class Task
9
+ attr_reader :json
10
+
11
+ def initialize(filename)
12
+ @json = JSON[File.read(filename)]
13
+ @work_dir = Dir.mktmpdir
14
+
15
+ started_at = Time.now
16
+ @result = build(filename)
17
+ @result.finished_at = Time.now
18
+ @result.started_at = started_at
19
+ puts Build::Report.new(@result).to_yaml
20
+ end
21
+
22
+ private
23
+
24
+ # @param info [#service_name,#user_name,#repo_name]
25
+ def badge_in_readme?(info)
26
+ Build::BadgeDetector.in_readme?(repo, info)
27
+ end
28
+
29
+ def build(filename)
30
+ language = json['language']
31
+ branch_name = json['branch_name'] || json['travis_branch']
32
+ revision = json['revision'] || json['travis_commit']
33
+ nwo = json['nwo'] || json['travis_repo_slug']
34
+ @url = json['git_repo_url']
35
+ latest_revision = true # TODO: make truthful
36
+
37
+ if retrieve_repo
38
+ if repo.change_branch(branch_name, true)
39
+ if repo.checkout_revision(revision)
40
+ if @codebase = parse_codebase(language, filename, repo.path)
41
+ result = Build::ResultSuccess.new(repo, branch_name, latest_revision, @codebase.objects)
42
+ result.badge_in_readme = badge_in_readme?(result)
43
+ result
44
+ else
45
+ Build::ResultParserFailed.new(repo, branch_name, latest_revision, nil)
46
+ end
47
+ else
48
+ Build::ResultCheckoutRevisionFailed.new(repo, branch_name, latest_revision, nil)
49
+ end
50
+ else
51
+ Build::ResultChangeBranchFailed.new(repo, branch_name, latest_revision, nil)
52
+ end
53
+ else
54
+ Build::ResultRetrieverFailed.new(repo, branch_name, latest_revision, nil)
55
+ end
56
+ end
57
+
58
+ def parse_codebase(language, filename, path)
59
+ begin
60
+ ::Inch::Codebase.parse(path, to_config(language, filename, path))
61
+ rescue Exception => e
62
+ warn e.inspect
63
+ nil
64
+ end
65
+ end
66
+
67
+ def repo
68
+ @repo ||= Repomen::Retriever.new(@url, :work_dir => @work_dir)
69
+ end
70
+
71
+ # @return [Repomen::Retriever,nil] either the retrieved repo or +nil+
72
+ def retrieve_repo
73
+ repo.retrieved? ? repo : nil
74
+ end
75
+
76
+ # Creates a Config::Codebase object and returns it
77
+ # (merges relevant values of a given +options+ object before).
78
+ #
79
+ # @return [Config::Codebase]
80
+ def to_config(language, filename, path)
81
+ config = ::Inch::Config.for(language, path).codebase
82
+ config.read_dump_file = filename
83
+ config
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,8 @@
1
+ require 'inch_ci/worker/build_json/task'
2
+
3
+ module InchCI
4
+ module Worker
5
+ module BuildJSON
6
+ end
7
+ end
8
+ end
@@ -1,7 +1,7 @@
1
1
  require 'inch'
2
2
  require 'repomen'
3
3
 
4
- require_relative 'report'
4
+ require 'inch_ci/worker/list_tags/report'
5
5
 
6
6
  module InchCI
7
7
  module Worker
@@ -1,4 +1,4 @@
1
- require_relative 'list_tags/task'
1
+ require 'inch_ci/worker/list_tags/task'
2
2
 
3
3
  module InchCI
4
4
  module Worker
@@ -1,5 +1,5 @@
1
1
  module InchCI
2
2
  module Worker
3
- VERSION = "0.3.0.rc9"
3
+ VERSION = "0.3.0.rc10"
4
4
  end
5
5
  end
@@ -12,4 +12,5 @@ module InchCI
12
12
  end
13
13
 
14
14
  require 'inch_ci/worker/build'
15
+ require 'inch_ci/worker/build_json'
15
16
  require 'inch_ci/worker/list_tags'
@@ -0,0 +1 @@
1
+ {"travis_branch":"master","travis_repo_slug":"rrrene/inch_ex","travis_commit":null,"travis_job_id":null,"travis":true,"git_repo_url":"git@github.com:rrrene/inch_ex.git","language":"elixir","args":[],"objects":[{"object_type":"ModuleObject","id":"InchEx","module":"Elixir.InchEx","moduledoc":null,"source":null,"type":null,"typespecs":[]},{"object_type":"ModuleObject","id":"InchEx.Config","module":"Elixir.InchEx.Config","moduledoc":null,"source":null,"type":null,"typespecs":[]},{"object_type":"ModuleObject","id":"InchEx.Docs.Formatter","module":"Elixir.InchEx.Docs.Formatter","moduledoc":"Provide JSON-formatted documentation\n","source":null,"type":null,"typespecs":[]},{"object_type":"ModuleObject","id":"InchEx.Docs.Retriever","module":"Elixir.InchEx.Docs.Retriever","moduledoc":"Functions to extract documentation information from modules.\n","source":null,"type":null,"typespecs":[]},{"object_type":"ModuleObject","id":"InchEx.Docs.Retriever.Error","module":"Elixir.InchEx.Docs.Retriever.Error","moduledoc":null,"source":null,"type":"exception","typespecs":[]},{"object_type":"ModuleObject","id":"InchEx.FunctionObject","module":"Elixir.InchEx.FunctionObject","moduledoc":null,"source":null,"type":null,"typespecs":[]},{"object_type":"ModuleObject","id":"InchEx.ModuleObject","module":"Elixir.InchEx.ModuleObject","moduledoc":null,"source":null,"type":null,"typespecs":[]},{"object_type":"ModuleObject","id":"InchEx.Reporter.Local","module":"Elixir.InchEx.Reporter.Local","moduledoc":null,"source":null,"type":null,"typespecs":[]},{"object_type":"ModuleObject","id":"InchEx.Reporter.Remote","module":"Elixir.InchEx.Reporter.Remote","moduledoc":null,"source":null,"type":null,"typespecs":[]},{"object_type":"ModuleObject","id":"InchEx.TypeObject","module":"Elixir.InchEx.TypeObject","moduledoc":null,"source":null,"type":null,"typespecs":[]},{"object_type":"ModuleObject","id":"Mix.Tasks.Inch","module":"Elixir.Mix.Tasks.Inch","moduledoc":null,"source":null,"type":null,"typespecs":[]},{"object_type":"ModuleObject","id":"Mix.Tasks.Inch.Report","module":"Elixir.Mix.Tasks.Inch.Report","moduledoc":null,"source":null,"type":null,"typespecs":[]},{"object_type":"FunctionObject","module_id":"InchEx","arity":4,"doc":false,"id":"generate_docs/4","name":"generate_docs","signature":[["project",[],null],["version",[],null],["args",[],null],["options",[],null]],"source":null,"specs":[],"type":"def"},{"object_type":"FunctionObject","module_id":"InchEx.Docs.Formatter","arity":3,"doc":"Generate JSON documentation for the given modules\n","id":"run/3","name":"run","signature":[["modules",[],null],["args",[],null],["config",[],null]],"source":null,"specs":[],"type":"def"},{"object_type":"FunctionObject","module_id":"InchEx.Docs.Retriever","arity":2,"doc":"Extract documentation from all modules in the specified directory\n","id":"docs_from_dir/2","name":"docs_from_dir","signature":[["dir",[],null],["config",[],null]],"source":null,"specs":[],"type":"def"},{"object_type":"FunctionObject","module_id":"InchEx.Docs.Retriever","arity":2,"doc":"Extract documentation from all modules in the specified list of files\n","id":"docs_from_files/2","name":"docs_from_files","signature":[["files",[],null],["config",[],null]],"source":null,"specs":[],"type":"def"},{"object_type":"FunctionObject","module_id":"InchEx.Docs.Retriever","arity":2,"doc":"Extract documentation from all modules in the list `modules`\n","id":"docs_from_modules/2","name":"docs_from_modules","signature":[["modules",[],null],["config",[],null]],"source":null,"specs":[],"type":"def"},{"object_type":"FunctionObject","module_id":"InchEx.Docs.Retriever.Error","arity":1,"doc":"Callback implementation of `Exception.exception/1`.","id":"exception/1","name":"exception","signature":[["args",[],null]],"source":null,"specs":[["::",{"line":19},[["exception",{"line":19},[[[".",{"line":19},["Elixir.Keyword","t"]],{"line":19},[]]]],[[".",{"line":19},["Elixir.Exception","t"]],{"line":19},[]]]]],"type":"def"},{"object_type":"FunctionObject","module_id":"InchEx.Docs.Retriever.Error","arity":1,"doc":"Callback implementation of `Exception.message/1`.","id":"message/1","name":"message","signature":[["exception",[],null]],"source":null,"specs":[["::",{"line":19},[["message",{"line":19},[[[".",{"line":19},["Elixir.Exception","t"]],{"line":19},[]]]],[[".",{"line":19},["Elixir.String","t"]],{"line":19},[]]]]],"type":"def"},{"object_type":"FunctionObject","module_id":"InchEx.Reporter.Local","arity":2,"doc":" Runs inch locally, if installed. If you want to force usage of a particular\n inch installation, set INCH_PATH environment variable:\n\n export INCH_PATH=/home/rrrene/projects/inch\n\n Otherwise, InchEx will take whatever `inch` command it finds. If it does\n not find any, it sends the data to the open API at inch-ci.org (or the\n endpoint defined in the INCH_CLI_API environment variable) to perform\n the analysis and reports the findings back.\n","id":"run/2","name":"run","signature":[["filename",[],null],["\\\\",[],[["args",[],null],[]]]],"source":null,"specs":[],"type":"def"},{"object_type":"FunctionObject","module_id":"InchEx.Reporter.Remote","arity":2,"doc":" Runs inch remotely, if already invented.\n","id":"run/2","name":"run","signature":[["filename",[],null],["",[],"Elixir"]],"source":null,"specs":[],"type":"def"},{"object_type":"FunctionObject","module_id":"Mix.Tasks.Inch","arity":4,"doc":false,"id":"run/4","name":"run","signature":[["args",[],null],["\\\\",[],[["config",[],null],[[".",{"line":10},["Elixir.Mix.Project","config"]],{"line":10},[]]]],["\\\\",[],[["generator",[],null],[[".",[],["erlang","make_fun"]],{"line":10},["Elixir.InchEx","generate_docs",4]]]],["\\\\",[],[["reporter",[],null],"Elixir.InchEx.Reporter.Local"]]],"source":null,"specs":[],"type":"def"},{"object_type":"FunctionObject","module_id":"Mix.Tasks.Inch.Report","arity":4,"doc":false,"id":"run/4","name":"run","signature":[["",[],"Elixir"],["\\\\",[],[["config",[],null],[[".",{"line":8},["Elixir.Mix.Project","config"]],{"line":8},[]]]],["\\\\",[],[["generator",[],null],[[".",[],["erlang","make_fun"]],{"line":8},["Elixir.InchEx","generate_docs",4]]]],["\\\\",[],[["reporter",[],null],"Elixir.InchEx.Reporter.Remote"]]],"source":null,"specs":[],"type":"def"}]}
@@ -0,0 +1,19 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ describe ::InchCI::Worker::BuildJSON do
4
+ let(:described_class) { ::InchCI::Worker::BuildJSON::Task }
5
+ let(:filename) { File.expand_path(File.dirname(__FILE__) + '/../fixtures/elixir/inch_ex.json') }
6
+
7
+ #
8
+ # Good scenarios
9
+ #
10
+
11
+ it 'should retrieve the repo' do
12
+ out, err = capture_io do
13
+ @task = described_class.new(filename)
14
+ end
15
+ refute out.empty?
16
+ assert_match /status: success/, out
17
+ assert err.empty?
18
+ end
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inch_ci-worker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.rc9
4
+ version: 0.3.0.rc10
5
5
  platform: ruby
6
6
  authors:
7
7
  - René Föhring
@@ -117,11 +117,15 @@ files:
117
117
  - lib/inch_ci/worker/build/report.rb
118
118
  - lib/inch_ci/worker/build/result.rb
119
119
  - lib/inch_ci/worker/build/task.rb
120
+ - lib/inch_ci/worker/build_json.rb
121
+ - lib/inch_ci/worker/build_json/task.rb
120
122
  - lib/inch_ci/worker/list_tags.rb
121
123
  - lib/inch_ci/worker/list_tags/report.rb
122
124
  - lib/inch_ci/worker/list_tags/task.rb
123
125
  - lib/inch_ci/worker/version.rb
126
+ - test/fixtures/elixir/inch_ex.json
124
127
  - test/integration/badge_detector_test.rb
128
+ - test/integration/build_json_test.rb
125
129
  - test/integration/build_test.rb
126
130
  - test/integration/inch_version_test.rb
127
131
  - test/test_helper.rb
@@ -151,7 +155,9 @@ signing_key:
151
155
  specification_version: 4
152
156
  summary: Worker for the Inch CI project
153
157
  test_files:
158
+ - test/fixtures/elixir/inch_ex.json
154
159
  - test/integration/badge_detector_test.rb
160
+ - test/integration/build_json_test.rb
155
161
  - test/integration/build_test.rb
156
162
  - test/integration/inch_version_test.rb
157
163
  - test/test_helper.rb