rosette-core 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +26 -0
  3. data/History.txt +3 -0
  4. data/README.md +94 -0
  5. data/Rakefile +18 -0
  6. data/lib/rosette/core.rb +110 -0
  7. data/lib/rosette/core/branch_utils.rb +152 -0
  8. data/lib/rosette/core/commands.rb +139 -0
  9. data/lib/rosette/core/commands/errors.rb +17 -0
  10. data/lib/rosette/core/commands/git/commit_command.rb +65 -0
  11. data/lib/rosette/core/commands/git/diff_base_command.rb +301 -0
  12. data/lib/rosette/core/commands/git/diff_command.rb +188 -0
  13. data/lib/rosette/core/commands/git/diff_entry.rb +44 -0
  14. data/lib/rosette/core/commands/git/fetch_command.rb +27 -0
  15. data/lib/rosette/core/commands/git/repo_snapshot_command.rb +40 -0
  16. data/lib/rosette/core/commands/git/show_command.rb +70 -0
  17. data/lib/rosette/core/commands/git/snapshot_command.rb +50 -0
  18. data/lib/rosette/core/commands/git/status_command.rb +128 -0
  19. data/lib/rosette/core/commands/git/with_non_merge_ref.rb +48 -0
  20. data/lib/rosette/core/commands/git/with_ref.rb +92 -0
  21. data/lib/rosette/core/commands/git/with_refs.rb +92 -0
  22. data/lib/rosette/core/commands/git/with_repo_name.rb +50 -0
  23. data/lib/rosette/core/commands/git/with_snapshots.rb +45 -0
  24. data/lib/rosette/core/commands/queuing/enqueue_commit_command.rb +37 -0
  25. data/lib/rosette/core/commands/queuing/requeue_commit_command.rb +46 -0
  26. data/lib/rosette/core/commands/translations/export_command.rb +257 -0
  27. data/lib/rosette/core/commands/translations/translation_lookup_command.rb +66 -0
  28. data/lib/rosette/core/commands/translations/with_locale.rb +47 -0
  29. data/lib/rosette/core/configurator.rb +160 -0
  30. data/lib/rosette/core/error_reporters/buffered_error_reporter.rb +96 -0
  31. data/lib/rosette/core/error_reporters/error_reporter.rb +31 -0
  32. data/lib/rosette/core/error_reporters/nil_error_reporter.rb +25 -0
  33. data/lib/rosette/core/error_reporters/printing_error_reporter.rb +58 -0
  34. data/lib/rosette/core/error_reporters/raising_error_reporter.rb +27 -0
  35. data/lib/rosette/core/errors.rb +93 -0
  36. data/lib/rosette/core/extractor/commit_log.rb +33 -0
  37. data/lib/rosette/core/extractor/commit_log_status.rb +57 -0
  38. data/lib/rosette/core/extractor/commit_processor.rb +109 -0
  39. data/lib/rosette/core/extractor/extractor.rb +72 -0
  40. data/lib/rosette/core/extractor/extractor_config.rb +74 -0
  41. data/lib/rosette/core/extractor/locale.rb +118 -0
  42. data/lib/rosette/core/extractor/phrase.rb +76 -0
  43. data/lib/rosette/core/extractor/phrase/phrase_index_policy.rb +108 -0
  44. data/lib/rosette/core/extractor/phrase/phrase_to_hash.rb +33 -0
  45. data/lib/rosette/core/extractor/repo_config.rb +339 -0
  46. data/lib/rosette/core/extractor/serializer_config.rb +55 -0
  47. data/lib/rosette/core/extractor/static_extractor.rb +44 -0
  48. data/lib/rosette/core/extractor/translation.rb +44 -0
  49. data/lib/rosette/core/extractor/translation/translation_to_hash.rb +28 -0
  50. data/lib/rosette/core/git/diff_finder.rb +131 -0
  51. data/lib/rosette/core/git/ref.rb +116 -0
  52. data/lib/rosette/core/git/repo.rb +378 -0
  53. data/lib/rosette/core/path_matcher_factory.rb +330 -0
  54. data/lib/rosette/core/resolvers/extractor_id.rb +37 -0
  55. data/lib/rosette/core/resolvers/integration_id.rb +37 -0
  56. data/lib/rosette/core/resolvers/preprocessor_id.rb +38 -0
  57. data/lib/rosette/core/resolvers/resolver.rb +115 -0
  58. data/lib/rosette/core/resolvers/serializer_id.rb +37 -0
  59. data/lib/rosette/core/snapshots/cached_head_snapshot_factory.rb +51 -0
  60. data/lib/rosette/core/snapshots/cached_snapshot_factory.rb +67 -0
  61. data/lib/rosette/core/snapshots/head_snapshot_factory.rb +58 -0
  62. data/lib/rosette/core/snapshots/repo_config_path_filter.rb +83 -0
  63. data/lib/rosette/core/snapshots/snapshot_factory.rb +184 -0
  64. data/lib/rosette/core/string_utils.rb +23 -0
  65. data/lib/rosette/core/translation_status.rb +81 -0
  66. data/lib/rosette/core/validators.rb +18 -0
  67. data/lib/rosette/core/validators/commit_validator.rb +62 -0
  68. data/lib/rosette/core/validators/commits_validator.rb +32 -0
  69. data/lib/rosette/core/validators/encoding_validator.rb +32 -0
  70. data/lib/rosette/core/validators/locale_validator.rb +37 -0
  71. data/lib/rosette/core/validators/repo_validator.rb +33 -0
  72. data/lib/rosette/core/validators/serializer_validator.rb +37 -0
  73. data/lib/rosette/core/validators/validator.rb +31 -0
  74. data/lib/rosette/core/version.rb +8 -0
  75. data/lib/rosette/data_stores.rb +11 -0
  76. data/lib/rosette/data_stores/errors.rb +26 -0
  77. data/lib/rosette/data_stores/phrase_status.rb +59 -0
  78. data/lib/rosette/integrations.rb +12 -0
  79. data/lib/rosette/integrations/errors.rb +15 -0
  80. data/lib/rosette/integrations/integratable.rb +58 -0
  81. data/lib/rosette/integrations/integration.rb +23 -0
  82. data/lib/rosette/preprocessors.rb +11 -0
  83. data/lib/rosette/preprocessors/errors.rb +14 -0
  84. data/lib/rosette/preprocessors/preprocessor.rb +48 -0
  85. data/lib/rosette/queuing.rb +14 -0
  86. data/lib/rosette/queuing/commits.rb +19 -0
  87. data/lib/rosette/queuing/commits/commit_conductor.rb +90 -0
  88. data/lib/rosette/queuing/commits/commit_job.rb +93 -0
  89. data/lib/rosette/queuing/commits/commits_queue_configurator.rb +60 -0
  90. data/lib/rosette/queuing/commits/extract_stage.rb +46 -0
  91. data/lib/rosette/queuing/commits/fetch_stage.rb +51 -0
  92. data/lib/rosette/queuing/commits/finalize_stage.rb +76 -0
  93. data/lib/rosette/queuing/commits/phrase_storage_granularity.rb +20 -0
  94. data/lib/rosette/queuing/commits/push_stage.rb +91 -0
  95. data/lib/rosette/queuing/commits/stage.rb +96 -0
  96. data/lib/rosette/queuing/job.rb +74 -0
  97. data/lib/rosette/queuing/queue.rb +28 -0
  98. data/lib/rosette/queuing/queue_configurator.rb +76 -0
  99. data/lib/rosette/queuing/worker.rb +30 -0
  100. data/lib/rosette/serializers.rb +10 -0
  101. data/lib/rosette/serializers/serializer.rb +98 -0
  102. data/lib/rosette/tms.rb +9 -0
  103. data/lib/rosette/tms/repository.rb +95 -0
  104. data/rosette-core.gemspec +24 -0
  105. data/spec/core/branch_utils_spec.rb +110 -0
  106. data/spec/core/commands/git/commit_command_spec.rb +60 -0
  107. data/spec/core/commands/git/diff_command_spec.rb +263 -0
  108. data/spec/core/commands/git/fetch_command_spec.rb +61 -0
  109. data/spec/core/commands/git/repo_snapshot_command_spec.rb +72 -0
  110. data/spec/core/commands/git/show_command_spec.rb +128 -0
  111. data/spec/core/commands/git/snapshot_command_spec.rb +86 -0
  112. data/spec/core/commands/git/status_command_spec.rb +154 -0
  113. data/spec/core/commands/queuing/enqueue_commit_command_spec.rb +34 -0
  114. data/spec/core/commands/queuing/requeue_commit_command_spec.rb +46 -0
  115. data/spec/core/commands/translations/export_command_spec.rb +113 -0
  116. data/spec/core/commands/translations/translation_lookup_command_spec.rb +58 -0
  117. data/spec/core/configurator_spec.rb +47 -0
  118. data/spec/core/error_reporters/buffered_error_reporter_spec.rb +61 -0
  119. data/spec/core/error_reporters/nil_error_reporter_spec.rb +16 -0
  120. data/spec/core/error_reporters/printing_error_reporter_spec.rb +60 -0
  121. data/spec/core/extractor/commit_log_status_spec.rb +216 -0
  122. data/spec/core/extractor/commit_processor_spec.rb +68 -0
  123. data/spec/core/extractor/extractor_config_spec.rb +47 -0
  124. data/spec/core/extractor/extractor_spec.rb +26 -0
  125. data/spec/core/extractor/locale_spec.rb +92 -0
  126. data/spec/core/extractor/phrase/phrase_index_policy_spec.rb +116 -0
  127. data/spec/core/extractor/phrase/phrase_to_hash_spec.rb +18 -0
  128. data/spec/core/extractor/repo_config_spec.rb +147 -0
  129. data/spec/core/extractor/translation/translation_to_hash_spec.rb +25 -0
  130. data/spec/core/git/diff_finder_spec.rb +74 -0
  131. data/spec/core/git/ref_spec.rb +118 -0
  132. data/spec/core/git/repo_spec.rb +216 -0
  133. data/spec/core/path_matcher_factory_spec.rb +139 -0
  134. data/spec/core/resolvers/extractor_id_spec.rb +47 -0
  135. data/spec/core/resolvers/integration_id_spec.rb +47 -0
  136. data/spec/core/resolvers/preprocessor_id_spec.rb +47 -0
  137. data/spec/core/resolvers/serializer_id_spec.rb +47 -0
  138. data/spec/core/snapshots/snapshot_factory_spec.rb +145 -0
  139. data/spec/core/string_utils_spec.rb +19 -0
  140. data/spec/core/translation_status_spec.rb +91 -0
  141. data/spec/core/validators/commit_validator_spec.rb +40 -0
  142. data/spec/core/validators/encoding_validator_spec.rb +30 -0
  143. data/spec/core/validators/locale_validator_spec.rb +31 -0
  144. data/spec/core/validators/repo_validator_spec.rb +30 -0
  145. data/spec/core/validators/serializer_validator_spec.rb +31 -0
  146. data/spec/integrations/integratable_spec.rb +58 -0
  147. data/spec/queuing/commits/commit_conductor_spec.rb +71 -0
  148. data/spec/queuing/commits/commit_job_spec.rb +87 -0
  149. data/spec/queuing/commits/extract_stage_spec.rb +68 -0
  150. data/spec/queuing/commits/fetch_stage_spec.rb +101 -0
  151. data/spec/queuing/commits/finalize_stage_spec.rb +88 -0
  152. data/spec/queuing/commits/push_stage_spec.rb +145 -0
  153. data/spec/queuing/commits/stage_spec.rb +80 -0
  154. data/spec/queuing/job_spec.rb +33 -0
  155. data/spec/queuing/queue_configurator_spec.rb +44 -0
  156. data/spec/spec_helper.rb +90 -0
  157. data/spec/test_helpers/fake_commit_stage.rb +17 -0
  158. metadata +257 -0
@@ -0,0 +1,59 @@
1
+ # encoding: UTF-8
2
+
3
+ module Rosette
4
+ module DataStores
5
+
6
+ # Contains several constants indicating the translation status of a set
7
+ # of phrases. Generally attached to commit logs.
8
+ module PhraseStatus
9
+ # The commit has not even been seen yet, i.e. this is the first time
10
+ # Rosette has ever encountered it.
11
+ NOT_SEEN = 'NOT_SEEN'
12
+
13
+ # The repository that contains this commit has been fetched in preparation
14
+ # for processing it.
15
+ FETCHED = 'FETCHED'
16
+
17
+ # Indicates the phrases have been extracted from the commit.
18
+ EXTRACTED = 'EXTRACTED'
19
+
20
+ # The extracted phrases have been submitted for translation.
21
+ PUSHED = 'PUSHED'
22
+
23
+ # The commit has been completely processed.
24
+ FINALIZED = 'FINALIZED'
25
+
26
+ # Indicates that the commit no longer exists, i.e. the associated branch
27
+ # was deleted or was force-pushed over.
28
+ MISSING = 'MISSING'
29
+
30
+ # Indicates one or all of the commits have not been processed.
31
+ NOT_FOUND = 'NOT_FOUND'
32
+
33
+ def self.all
34
+ @all ||= [
35
+ NOT_SEEN, FETCHED, EXTRACTED, PUSHED, FINALIZED, MISSING, NOT_FOUND
36
+ ]
37
+ end
38
+
39
+ def self.statuses
40
+ @statuses ||= [
41
+ NOT_SEEN, FETCHED, EXTRACTED, PUSHED, FINALIZED
42
+ ]
43
+ end
44
+
45
+ def self.incomplete
46
+ @incomplete ||= [
47
+ NOT_SEEN, FETCHED, EXTRACTED, PUSHED, NOT_FOUND
48
+ ]
49
+ end
50
+
51
+ def self.index(status)
52
+ (@status_index ||= {}).fetch(status) do
53
+ statuses.index(status)
54
+ end
55
+ end
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: UTF-8
2
+
3
+ module Rosette
4
+
5
+ # Base classes and other scaffolding for Rosette's integrations.
6
+ module Integrations
7
+ autoload :Errors, 'rosette/integrations/errors'
8
+ autoload :Integration, 'rosette/integrations/integration'
9
+ autoload :Integratable, 'rosette/integrations/integratable'
10
+ end
11
+
12
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: UTF-8
2
+
3
+ module Rosette
4
+ module Integrations
5
+
6
+ # Errors that can be raised during integration operations.
7
+ module Errors
8
+ # Raised whenever an integration is deemed impossible. Impossible
9
+ # integrations happen when Rosette can't determine how an integration
10
+ # should be applied to the system.
11
+ class ImpossibleIntegrationError < StandardError; end
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,58 @@
1
+ # encoding: UTF-8
2
+
3
+ module Rosette
4
+ module Integrations
5
+
6
+ # Intended to be mixed in to classes that can be integrated with. Provides
7
+ # methods to add and retrieve integration configs as well as apply
8
+ # configured integrations to the parent.
9
+ module Integratable
10
+ # Returns the current list of integration configs.
11
+ #
12
+ # @return [Array]
13
+ def integrations
14
+ @integrations ||= []
15
+ end
16
+
17
+ # Add an integration. Yields an instance of the integration's
18
+ # configurator object to the given block.
19
+ #
20
+ # @param [String] integration_id The id of the integration to add.
21
+ # @yield [config]
22
+ # @yieldparam config The integration's configurator.
23
+ # @return [void]
24
+ def add_integration(integration_id, &block)
25
+ klass = Rosette::Core::IntegrationId.resolve(integration_id)
26
+ integrations << klass.configure(&block)
27
+ end
28
+
29
+ # Retrieve the integration config by id.
30
+ #
31
+ # @param [String] integration_id The integration id.
32
+ # @return [nil, Object] The integration's configurator.
33
+ def get_integration(integration_id)
34
+ klass = Rosette::Core::IntegrationId.resolve(integration_id)
35
+
36
+ if klass
37
+ integrations.find do |integration|
38
+ integration.is_a?(klass)
39
+ end
40
+ end
41
+ rescue ArgumentError
42
+ end
43
+
44
+ # Applies the integrations to the given object.
45
+ #
46
+ # @param [Object] obj The object to apply the integrations to.
47
+ # @return [void]
48
+ def apply_integrations(obj)
49
+ integrations.each do |integration|
50
+ if integration.integrates_with?(obj)
51
+ integration.integrate(obj)
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: UTF-8
2
+
3
+ module Rosette
4
+ module Integrations
5
+
6
+ # The base class for all integrations.
7
+ #
8
+ # @!attribute [r] configuration
9
+ # @return [Configurator] the Rosette config.
10
+ class Integration
11
+ attr_reader :configuration
12
+
13
+ # Creates a new integration instance.
14
+ #
15
+ # @param [Object] configuration an instance of this integration's
16
+ # configurator.
17
+ def initialize(configuration)
18
+ @configuration = configuration
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ # encoding: UTF-8
2
+
3
+ module Rosette
4
+
5
+ # Namespace for all of Rosette's pre-processors.
6
+ module Preprocessors
7
+ autoload :Errors, 'rosette/preprocessors/errors'
8
+ autoload :Preprocessor, 'rosette/preprocessors/preprocessor'
9
+ end
10
+
11
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: UTF-8
2
+
3
+ module Rosette
4
+ module Preprocessors
5
+
6
+ # Errors that can be raised during pre-processing.
7
+ module Errors
8
+ # Raised if a preprocessor doesn't know how to process the object given
9
+ # to it.
10
+ class UnsupportedObjectError < StandardError; end
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,48 @@
1
+ # encoding: UTF-8
2
+
3
+ module Rosette
4
+ module Preprocessors
5
+
6
+ # Base class for all of Rosette's pre-processors.
7
+ #
8
+ # @!attribute [r] configuration
9
+ # @return [Object] an instance of this pre-processor's configurator.
10
+ class Preprocessor
11
+ attr_reader :configuration
12
+
13
+ # Creates a new pre-processor.
14
+ #
15
+ # @param [Object] configuration An instance of this pre-processor's
16
+ # configurator.
17
+ def initialize(configuration)
18
+ @configuration = configuration
19
+ end
20
+
21
+ # Processes the given object.
22
+ #
23
+ # @param [Object] object The object to process.
24
+ # @return [Object] A copy of +object+, modified as per this
25
+ # pre-processor's functionality. If the object can be processed
26
+ # but doesn't need to be, the original object is returned without
27
+ # modifications.
28
+ # @raise [UnsupportedObjectError] Raised if the object is not
29
+ # processable.
30
+ def process(object)
31
+ should_process = !configuration.applies_to_proc ||
32
+ configuration.applies_to_proc.call(object)
33
+
34
+ if should_process
35
+ if method = method_for(object)
36
+ send(method, object)
37
+ else
38
+ raise Rosette::Preprocessors::Errors::UnsupportedObjectError,
39
+ "don't know how to preprocess a(n) #{object.class.name}"
40
+ end
41
+ else
42
+ object
43
+ end
44
+ end
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: UTF-8
2
+
3
+ module Rosette
4
+ module Queuing
5
+
6
+ autoload :QueueConfigurator, 'rosette/queuing/queue_configurator'
7
+ autoload :Job, 'rosette/queuing/job'
8
+ autoload :Queue, 'rosette/queuing/queue'
9
+ autoload :Worker, 'rosette/queuing/worker'
10
+
11
+ autoload :Commits, 'rosette/queuing/commits'
12
+
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: UTF-8
2
+
3
+ module Rosette
4
+ module Queuing
5
+ module Commits
6
+
7
+ autoload :CommitJob, 'rosette/queuing/commits/commit_job'
8
+ autoload :CommitConductor, 'rosette/queuing/commits/commit_conductor'
9
+ autoload :CommitsQueueConfigurator, 'rosette/queuing/commits/commits_queue_configurator'
10
+ autoload :ExtractStage, 'rosette/queuing/commits/extract_stage'
11
+ autoload :FetchStage, 'rosette/queuing/commits/fetch_stage'
12
+ autoload :FinalizeStage, 'rosette/queuing/commits/finalize_stage'
13
+ autoload :PhraseStorageGranularity, 'rosette/queuing/commits/phrase_storage_granularity'
14
+ autoload :PushStage, 'rosette/queuing/commits/push_stage'
15
+ autoload :Stage, 'rosette/queuing/commits/stage'
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,90 @@
1
+ # encoding: UTF-8
2
+
3
+ module Rosette
4
+ module Queuing
5
+ module Commits
6
+
7
+ # Coordinates moving a commit through a number of processing stages.
8
+ #
9
+ # @!attribute [r] rosette_config
10
+ # @return [Configurator] the Rosette config to use.
11
+ # @!attribute [r] repo_name
12
+ # @return [String] the name of the repo to process commits for.
13
+ # @!attribute [r] logger
14
+ # @return [Logger] the logger to use.
15
+ # @return [void]
16
+ class CommitConductor
17
+ # The status that indicates a commit is completely processed, i.e. has
18
+ # no more stages to pass through.
19
+ FINISHED_STATUS = Rosette::DataStores::PhraseStatus::FINALIZED
20
+
21
+ attr_reader :rosette_config, :repo_name, :logger
22
+
23
+ def self.stage_classes
24
+ # grab all classes that inherit from Stage
25
+ @stage_classes ||= begin
26
+ namespace = Rosette::Queuing::Commits
27
+ namespace.constants
28
+ .map { |const_sym| namespace.const_get(const_sym) }
29
+ .select { |const| const < namespace::Stage }
30
+ end
31
+ end
32
+
33
+ # Creates a new instance of +CommitConductor
34
+ # @param [Configurator] rosette_config The Rosette config to use.
35
+ # @param [String] repo_name The name of the repo to process commits for.
36
+ # @param [Logger] logger The logger to use.
37
+ # @return [CommitConductor]
38
+ def initialize(rosette_config, repo_name, logger)
39
+ @rosette_config = rosette_config
40
+ @repo_name = repo_name
41
+ @logger = logger
42
+ end
43
+
44
+ # Creates a new job for the commit and enqueues it on the configured
45
+ # Rosette queue.
46
+ #
47
+ # @param [String] commit_id The commit to enqueue.
48
+ # @return [void]
49
+ def enqueue(commit_id)
50
+ job = CommitJob.new(repo_name, commit_id)
51
+ enqueue_job(job)
52
+ end
53
+
54
+ # Executes the current stage of the commit log and advances it to the
55
+ # next. Also updates the commit log's status.
56
+ #
57
+ # @param [CommitLog] commit_log The commit log to advance.
58
+ # @return [void]
59
+ def advance(commit_log)
60
+ create_stage_instance(commit_log).tap do |stage|
61
+ return unless stage
62
+ stage.execute!
63
+ return if finished?(stage)
64
+ enqueue_job(stage.to_job)
65
+ end
66
+ end
67
+
68
+ protected
69
+
70
+ def finished?(stage)
71
+ stage.commit_log.status == FINISHED_STATUS
72
+ end
73
+
74
+ def enqueue_job(job)
75
+ rosette_config.queue.enqueue(job)
76
+ end
77
+
78
+ def create_stage_instance(commit_log)
79
+ self.class.stage_classes.each do |stage_class|
80
+ if stage = stage_class.for_commit_log(commit_log, rosette_config, logger)
81
+ return stage
82
+ end
83
+ end
84
+ nil
85
+ end
86
+ end
87
+
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,93 @@
1
+ # encoding: UTF-8
2
+
3
+ module Rosette
4
+ module Queuing
5
+ module Commits
6
+
7
+ # Encapsulates processing a commit at a specific stage in the process.
8
+ #
9
+ # @!attribute [r] repo_name
10
+ # @return [String] the name of the repo the commit belongs to.
11
+ # @!attribute [r] commit_id
12
+ # @return [String] the commit id to process.
13
+ # @!attribute [r] status
14
+ # @return [String] the current status of the commit (mostly for display
15
+ # and tracking purposes).
16
+ class CommitJob < Job
17
+ attr_reader :repo_name, :commit_id, :status
18
+
19
+ set_queue_name 'commits'
20
+
21
+ # Creates a new [CommitJob] object from a [Stage].
22
+ #
23
+ # @param [Stage] stage The stage to get parameters from.
24
+ # @return [CommitJob]
25
+ def self.from_stage(stage)
26
+ new(
27
+ stage.repo_config.name,
28
+ stage.commit_log.commit_id,
29
+ stage.commit_log.status
30
+ )
31
+ end
32
+
33
+ # Creates a new instance of [CommitJob].
34
+ #
35
+ # @param [String] repo_name The name of the repo the commit belongs to.
36
+ # @param [String] commit_id The commit id to process.
37
+ # @param [String] status The current status of the commit (mostly for
38
+ # display and tracking purposes).
39
+ # @return [CommitJob]
40
+ def initialize(repo_name, commit_id, status = nil)
41
+ @repo_name = repo_name
42
+ @commit_id = commit_id
43
+ @status = status
44
+ end
45
+
46
+ # Converts this job into a list of arguments that should be able to be
47
+ # easily serialized for placement into a queue. These should be the
48
+ # same values the constructor accepts, since +CommitJob+s will be
49
+ # re-instantiated with these arguments when executed.
50
+ #
51
+ # @return [Array]
52
+ def to_args
53
+ [repo_name, commit_id, status]
54
+ end
55
+
56
+ # Fetches the commit log, instantiates a new [CommitConductor] and
57
+ # advances the commit to the next stage. If the commit log does not
58
+ # exist in the database, one will be created.
59
+ #
60
+ # @param [Configurator] rosette_config
61
+ # @param [Logger] logger
62
+ # @return [void]
63
+ def work(rosette_config, logger)
64
+ commit_log = find_or_create_commit_log(rosette_config)
65
+ conductor = CommitConductor.new(rosette_config, repo_name, logger)
66
+ conductor.advance(commit_log)
67
+ end
68
+
69
+ protected
70
+
71
+ def find_or_create_commit_log(rosette_config)
72
+ # god this is cumbersome... the datastore could really use a refactor
73
+ if commit_log = lookup_commit_log(rosette_config)
74
+ commit_log
75
+ else
76
+ rosette_config.datastore.add_or_update_commit_log(
77
+ repo_name, commit_id, nil, Rosette::DataStores::PhraseStatus::NOT_SEEN
78
+ )
79
+
80
+ lookup_commit_log(rosette_config)
81
+ end
82
+ end
83
+
84
+ def lookup_commit_log(rosette_config)
85
+ rosette_config.datastore.lookup_commit_log(
86
+ repo_name, commit_id
87
+ )
88
+ end
89
+ end
90
+
91
+ end
92
+ end
93
+ end