mumukit-sync 0.4.1 → 1.0.0

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
  SHA256:
3
- metadata.gz: e0bdc140990239269aee542470c932aeabba4dc74da7fddb574fefd51e3a58c1
4
- data.tar.gz: 75befb01b2eae5d5e75cf96175e7b67041b35ae87f22cc38838574f8800ba1bd
3
+ metadata.gz: dd82342ee5883d4acd712b66caa8bf5326cf5b5052df3b805f851410bed1cc00
4
+ data.tar.gz: 429feabd158b03a03bb8df9cb96f3656cc90f4facfe0b2a0893c97c2e2d8bd66
5
5
  SHA512:
6
- metadata.gz: b7c3176f4f3b6bc05515c788da77463aea89ae7779939357821d5de0cdb0f6b4efebf0c0345a29f48cdbb793b0d8c175ee3209d1995803f816a29e30b613d7d7
7
- data.tar.gz: 40f5ff3a7e9ed53fd9c8eedcdfb0bce89b103f52f17b174a81c09513e80f9c1d742ab6a640957eed42f7bf1d638f4b0c91f390e0c504352dbe428a5f4f89c909
6
+ metadata.gz: e111220b0c5f7d796c4ff3b09ddee8d22ff2659b8efc5b9714f864671d3e2e9e3f5341d913f23a218216d89c04eefc22a0dfcb2b19cee20bb038dd31a74dd155
7
+ data.tar.gz: 9e437aa0be1d83805a830c0e612f10dfe5bf4d651862da7c8e365bb38252a28a9c8203979ba61b12842e0e0882e5491a27be2e40f2e60112fa565a053bb2d93e
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.3
data/.travis.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3.1
3
+ - 2.6.3
4
4
  before_install: gem install bundler -v 1.10.6
5
5
  deploy:
6
6
  provider: rubygems
@@ -53,6 +53,8 @@ class Mumukit::Sync::Store::Github
53
53
  def create!(slug, private)
54
54
  octokit.create_repository(slug.repository, organization: slug.organization)
55
55
  try_set_private!(slug) if private
56
+ rescue Octokit::Forbidden => e
57
+ raise raise Mumukit::Sync::SyncError, "Mumuki is not allowed to create repositories in organization #{slug.organization}"
56
58
  end
57
59
 
58
60
  def try_set_private!(slug)
@@ -1,5 +1,7 @@
1
1
  class Mumukit::Sync::Store::Github
2
2
  class ExerciseBuilder < OpenStruct
3
+ include Mumukit::Sync::Store::Github::WithSchema
4
+
3
5
  def locale
4
6
  meta['locale']
5
7
  end
@@ -9,11 +11,11 @@ class Mumukit::Sync::Store::Github
9
11
  end
10
12
 
11
13
  def build_simple_fields
12
- Mumukit::Sync::Store::Github::Schema::Exercise.simple_fields.map { |field| [field.reverse_name, self.send(field.reverse_name)] }.to_h
14
+ build_fields_h(exercise_schema.simple_fields) { |field| self.send(field.reverse_name) }
13
15
  end
14
16
 
15
17
  def build_metadata
16
- Mumukit::Sync::Store::Github::Schema::Exercise.metadata_fields.map { |field| [field.reverse_name, meta[field.name.to_s]] }.to_h
18
+ build_fields_h(exercise_schema.metadata_fields) { |field| meta[field.name.to_s] }
17
19
  end
18
20
  end
19
21
  end
@@ -1,5 +1,7 @@
1
1
  class Mumukit::Sync::Store::Github
2
2
  class GuideBuilder < OpenStruct
3
+ include Mumukit::Sync::Store::Github::WithSchema
4
+
3
5
  attr_writer :exercises
4
6
 
5
7
  def initialize(slug)
@@ -19,27 +21,24 @@ class Mumukit::Sync::Store::Github
19
21
  self.exercises << exercise
20
22
  end
21
23
 
24
+ def locale
25
+ meta['locale']
26
+ end
27
+
28
+ def language
29
+ meta['language']
30
+ end
31
+
22
32
  private
23
33
 
24
34
  def build_json
25
- raise Mumukit::Sync::SyncError, "Missing guide language" if language[:name].blank?
26
-
27
- {name: name,
28
- description: description,
29
- corollary: corollary,
30
- language: language,
31
- locale: locale,
32
- type: type,
33
- extra: extra,
34
- beta: beta,
35
- authors: authors,
36
- collaborators: collaborators,
37
- teacher_info: teacher_info,
38
- id_format: id_format,
39
- slug: slug,
40
- expectations: expectations.to_a,
41
- exercises: exercises.sort_by { |e| order.position_for(e[:id]) }}
35
+ raise Mumukit::Sync::SyncError, "Missing guide language" if language.blank?
36
+ file = build_fields_h(guide_schema.file_fields) { |field| self[field.reverse_name] }
37
+ metadata = build_fields_h(guide_schema.metadata_fields) { |field| self.meta[field.name.to_s] }
38
+ file.merge(metadata).merge(
39
+ expectations: expectations.to_a,
40
+ slug: slug,
41
+ exercises: exercises.sort_by { |e| order.position_for(e[:id]) }).compact
42
42
  end
43
-
44
43
  end
45
44
  end
@@ -1,5 +1,6 @@
1
1
  class Mumukit::Sync::Store::Github
2
2
  class GuideExport < Mumukit::Sync::Store::Github::Operation
3
+ include Mumukit::Sync::Store::Github::WithSchema
3
4
 
4
5
  attr_accessor :guide_resource_h, :bot, :author_email
5
6
 
@@ -39,7 +40,7 @@ class Mumukit::Sync::Store::Github
39
40
  end
40
41
 
41
42
  def clear_repo(local_repo)
42
- local_repo.remove Mumukit::Sync::Store::Github::Schema::Guide.file_patterns
43
+ local_repo.remove guide_schema.file_patterns
43
44
  rescue Git::GitExecuteError => e
44
45
  puts 'Nothing to clean, repo seems to be empty'
45
46
  end
@@ -1,6 +1,7 @@
1
1
  class Mumukit::Sync::Store::Github
2
2
  class GuideReader
3
3
  include Mumukit::Sync::Store::Github::WithFileReading
4
+ include Mumukit::Sync::Store::Github::WithSchema
4
5
 
5
6
  attr_reader :dir
6
7
 
@@ -13,7 +14,7 @@ class Mumukit::Sync::Store::Github
13
14
  builder = GuideBuilder.new(@slug)
14
15
 
15
16
  read_guide_meta! builder
16
- Mumukit::Sync::Store::Github::Schema::Guide.file_fields.each do |it|
17
+ guide_schema.file_fields.each do |it|
17
18
  value = it.read_field_file 'guide', dir
18
19
  builder[it.reverse_name] = value
19
20
  end
@@ -33,24 +34,18 @@ class Mumukit::Sync::Store::Github
33
34
 
34
35
  def read_guide_meta!(builder)
35
36
  meta = read_meta! 'guide', dir
37
+ meta['language'] &&= { name: meta['language'] }
38
+ read_legacy! meta
36
39
 
37
- builder.language = { name: meta['language'] }
38
- builder.locale = meta['locale']
40
+ builder.meta = meta
39
41
 
40
- read! 'name', builder, meta
41
- read! 'id_format', builder, meta
42
- read! 'type', builder, meta
43
- read! 'beta', builder, meta
44
- read! 'teacher_info', builder, meta
45
-
46
- read_legacy! builder, meta
47
42
 
48
43
  builder.order = Mumukit::Sync::Store::Github::Ordering.from meta['order']
49
44
  end
50
45
 
51
- def read_legacy!(builder, meta)
52
- builder.id_format ||= meta['original_id_format']
53
- builder.type ||= meta['learning'] ? 'learning' : 'practice'
46
+ def read_legacy!(meta)
47
+ meta['id_format'] ||= meta['original_id_format']
48
+ meta['type'] ||= meta['learning'] ? 'learning' : 'practice'
54
49
  end
55
50
 
56
51
  def read!(key, builder, meta)
@@ -74,7 +69,7 @@ class Mumukit::Sync::Store::Github
74
69
  builder.id = id
75
70
  builder.name = meta['name'] || name
76
71
 
77
- Mumukit::Sync::Store::Github::Schema::Exercise.file_fields.each do |it|
72
+ exercise_schema.file_fields.each do |it|
78
73
  value = it.read_field_file "exercise #{name}", root
79
74
  builder[it.reverse_name] = value
80
75
  end
@@ -1,5 +1,7 @@
1
1
  class Mumukit::Sync::Store::Github
2
2
  class GuideWriter
3
+ include Mumukit::Sync::Store::Github::WithSchema
4
+
3
5
  attr_accessor :dir
4
6
 
5
7
  def initialize(dir)
@@ -26,8 +28,8 @@ class Mumukit::Sync::Store::Github
26
28
  end
27
29
  write_licenses!(guide)
28
30
 
29
- write_metadata_fields! dir, Mumukit::Sync::Store::Github::Schema::Guide, guide
30
- write_file_fields! dir, Mumukit::Sync::Store::Github::Schema::Guide, guide, guide[:language]
31
+ write_metadata_fields! dir, guide_schema, guide
32
+ write_file_fields! dir, guide_schema, guide, guide[:language]
31
33
  end
32
34
 
33
35
  def format_id(guide, exercise)
@@ -39,8 +41,8 @@ class Mumukit::Sync::Store::Github
39
41
 
40
42
  FileUtils.mkdir_p dirname
41
43
 
42
- write_metadata_fields! dirname, Mumukit::Sync::Store::Github::Schema::Exercise, e
43
- write_file_fields! dirname, Mumukit::Sync::Store::Github::Schema::Exercise, e, (e[:language] || guide[:language])
44
+ write_metadata_fields! dirname, exercise_schema, e
45
+ write_file_fields! dirname, exercise_schema, e, (e[:language] || guide[:language])
44
46
  end
45
47
 
46
48
  def write_licenses!(guide)
@@ -129,6 +129,3 @@ class Mumukit::Sync::Store::Github
129
129
  end
130
130
  end
131
131
  end
132
-
133
- require_relative './schema/exercise'
134
- require_relative './schema/guide'
@@ -3,6 +3,8 @@ module Mumukit::Sync::Store
3
3
  ## This Store enables importing and exporting content
4
4
  ## from and to Github
5
5
  class Github
6
+ extend Mumukit::Core::Configurable
7
+
6
8
  def initialize(bot, author_email = nil, web_hook_base_url = nil)
7
9
  @bot = bot
8
10
  @author_email = author_email || bot.email
@@ -32,11 +34,16 @@ module Mumukit::Sync::Store
32
34
  web_hook_base_url: @web_hook_base_url,
33
35
  bot: @bot).run!
34
36
  end
37
+
38
+ def self.defaults
39
+ struct
40
+ end
35
41
  end
36
42
  end
37
43
 
38
44
  require 'mumukit/auth'
39
45
 
46
+ require_relative './with_schema'
40
47
  require_relative './github/bot'
41
48
  require_relative './github/git_lib'
42
49
  require_relative './github/with_file_reading'
@@ -0,0 +1,14 @@
1
+ module Mumukit::Sync::Store::Github::WithSchema
2
+ def exercise_schema
3
+ Mumukit::Sync::Store::Github.config.exercise_schema
4
+ end
5
+
6
+ def guide_schema
7
+ Mumukit::Sync::Store::Github.config.guide_schema
8
+ end
9
+
10
+ def build_fields_h(fields)
11
+ fields.map { |field| [field.reverse_name, yield(field)] }.to_h
12
+ end
13
+ end
14
+
@@ -17,7 +17,5 @@ require_relative './store/base'
17
17
  require_relative './store/null'
18
18
  require_relative './store/github'
19
19
  require_relative './store/json'
20
- require_relative './store/thesaurus'
21
20
  require_relative './store/with_wrapped_language'
22
21
  require_relative './store/with_filtered_id'
23
- require_relative './store/bibliotheca'
@@ -1,5 +1,5 @@
1
1
  module Mumukit
2
2
  module Sync
3
- VERSION = '0.4.1'
3
+ VERSION = '1.0.0'
4
4
  end
5
5
  end
data/mumukit-sync.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency 'git', '~> 1.5'
29
29
  spec.add_dependency 'octokit', '~> 4.1'
30
30
 
31
- spec.add_development_dependency "bundler", "~> 1.16"
31
+ spec.add_development_dependency "bundler", ">= 1.16"
32
32
  spec.add_development_dependency "rake", "~> 10.0"
33
33
  spec.add_development_dependency "rspec", "~> 3.0"
34
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mumukit-sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franco Bulgarelli
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-20 00:00:00.000000000 Z
11
+ date: 2019-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mumukit-core
@@ -84,14 +84,14 @@ dependencies:
84
84
  name: bundler
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '1.16'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.16'
97
97
  - !ruby/object:Gem::Dependency
@@ -131,6 +131,7 @@ extra_rdoc_files: []
131
131
  files:
132
132
  - ".gitignore"
133
133
  - ".rspec"
134
+ - ".ruby-version"
134
135
  - ".travis.yml"
135
136
  - CODE_OF_CONDUCT.md
136
137
  - Gemfile
@@ -147,7 +148,6 @@ files:
147
148
  - lib/mumukit/sync/inflator/single_choice.rb
148
149
  - lib/mumukit/sync/store.rb
149
150
  - lib/mumukit/sync/store/base.rb
150
- - lib/mumukit/sync/store/bibliotheca.rb
151
151
  - lib/mumukit/sync/store/github.rb
152
152
  - lib/mumukit/sync/store/github/bot.rb
153
153
  - lib/mumukit/sync/store/github/exercise_builder.rb
@@ -163,13 +163,11 @@ files:
163
163
  - lib/mumukit/sync/store/github/operation.rb
164
164
  - lib/mumukit/sync/store/github/ordering.rb
165
165
  - lib/mumukit/sync/store/github/schema.rb
166
- - lib/mumukit/sync/store/github/schema/exercise.rb
167
- - lib/mumukit/sync/store/github/schema/guide.rb
168
166
  - lib/mumukit/sync/store/github/with_file_reading.rb
169
167
  - lib/mumukit/sync/store/json.rb
170
168
  - lib/mumukit/sync/store/null.rb
171
- - lib/mumukit/sync/store/thesaurus.rb
172
169
  - lib/mumukit/sync/store/with_filtered_id.rb
170
+ - lib/mumukit/sync/store/with_schema.rb
173
171
  - lib/mumukit/sync/store/with_wrapped_language.rb
174
172
  - lib/mumukit/sync/syncer.rb
175
173
  - lib/mumukit/sync/version.rb
@@ -193,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
191
  - !ruby/object:Gem::Version
194
192
  version: '0'
195
193
  requirements: []
196
- rubygems_version: 3.0.3
194
+ rubygems_version: 3.0.4
197
195
  signing_key:
198
196
  specification_version: 4
199
197
  summary: Synchronization tool for resources
@@ -1,29 +0,0 @@
1
- module Mumukit::Sync::Store
2
-
3
- ## This Store enables importing content
4
- ## from Bibliotheca API
5
- class Bibliotheca < Mumukit::Sync::Store::Base
6
- include Mumukit::Sync::Store::WithWrappedLanguage
7
- include Mumukit::Sync::Store::WithFilteredId
8
-
9
- def initialize(bibliotheca_bridge)
10
- @bibliotheca_bridge = bibliotheca_bridge
11
- end
12
-
13
- def sync_keys
14
- %w(guide topic book).flat_map do |kind|
15
- @bibliotheca_bridge
16
- .send(kind.as_variable_name.pluralize)
17
- .map { |it| Mumukit::Sync.key kind, it['slug'] }
18
- end
19
- end
20
-
21
- def do_read(sync_key)
22
- @bibliotheca_bridge.send(sync_key.kind.as_variable_name, sync_key.id)
23
- end
24
-
25
- def write_resource!(*)
26
- Mumukit::Sync::Store.read_only!
27
- end
28
- end
29
- end
@@ -1,37 +0,0 @@
1
- module Mumukit::Sync::Store::Github::Schema::Exercise
2
- extend Mumukit::Sync::Store::Github::Schema
3
-
4
- def self.fields_schema
5
- [
6
- {name: :id, kind: :special},
7
- {name: :name, kind: :special},
8
-
9
- {name: :tags, kind: :metadata, reverse: :tag_list, transform: with { |it| it.to_a }},
10
- {name: :layout, kind: :metadata},
11
- {name: :editor, kind: :metadata},
12
-
13
- {name: :type, kind: :metadata},
14
- {name: :extra_visible, kind: :metadata},
15
- {name: :language, kind: :metadata, transform: name },
16
- {name: :teacher_info, kind: :metadata},
17
- {name: :manual_evaluation, kind: :metadata},
18
- {name: :choices, kind: :metadata},
19
-
20
- {name: :expectations, kind: :file, extension: 'yml', transform: yaml_list('expectations')},
21
- {name: :assistance_rules, kind: :file, extension: 'yml', transform: yaml_list('rules')},
22
- {name: :randomizations, kind: :file, extension: 'yml', transform: yaml_hash},
23
-
24
- {name: :goal, kind: :metadata},
25
- {name: :test, kind: :file, extension: :test},
26
- {name: :extra, kind: :file, extension: :code},
27
- {name: :default, kind: :file, extension: :code, reverse: :default_content},
28
-
29
- {name: :description, kind: :file, extension: 'md', required: true},
30
- {name: :hint, kind: :file, extension: 'md'},
31
- {name: :corollary, kind: :file, extension: 'md'},
32
- {name: :initial_state, kind: :file, extension: 'md'},
33
- {name: :final_state, kind: :file, extension: 'md'},
34
- {name: :free_form_editor_source, kind: :file, extension: 'html'}
35
- ]
36
- end
37
- end
@@ -1,34 +0,0 @@
1
- module Mumukit::Sync::Store::Github::Schema::Guide
2
- extend Mumukit::Sync::Store::Github::Schema
3
-
4
- def self.fields_schema
5
- [
6
- {name: :exercises, kind: :special},
7
- {name: :id, kind: :special},
8
- {name: :slug, kind: :special},
9
-
10
- {name: :name, kind: :metadata},
11
- {name: :locale, kind: :metadata},
12
- {name: :type, kind: :metadata},
13
- {name: :beta, kind: :metadata},
14
- {name: :teacher_info, kind: :metadata},
15
- {name: :language, kind: :metadata, transform: name },
16
- {name: :id_format, kind: :metadata},
17
- {name: :order, kind: :metadata, transform: with { |it| it.map { |e| e[:id] } }, reverse: :exercises},
18
- {name: :private, kind: :metadata},
19
-
20
- {name: :expectations, kind: :file, extension: 'yml', transform: yaml_list('expectations')},
21
- {name: :description, kind: :file, extension: 'md', required: true},
22
- {name: :corollary, kind: :file, extension: 'md'},
23
- {name: :sources, kind: :file, extension: 'md'},
24
- {name: :learn_more, kind: :file, extension: 'md'},
25
- {name: :extra, kind: :file, extension: :code},
26
- {name: :AUTHORS, kind: :file, extension: 'txt', reverse: :authors},
27
- {name: :COLLABORATORS, kind: :file, extension: 'txt', reverse: :collaborators}
28
- ]
29
- end
30
-
31
- def self.fixed_file_patterns
32
- %w(LICENSE.txt README.md COPYRIGHT.txt meta.yml *_*/*)
33
- end
34
- end
@@ -1,27 +0,0 @@
1
- module Mumukit::Sync::Store
2
-
3
- ## This Store enables importing languages
4
- ## from Thesaurus API
5
- class Thesaurus < Mumukit::Sync::Store::Base
6
- def initialize(thesaurus_bridge)
7
- @thesaurus_bridge = thesaurus_bridge
8
- end
9
-
10
- def sync_keys
11
- @thesaurus_bridge.runners.map { |it| Mumukit::Sync.key(:language, it) }
12
- end
13
-
14
- def do_read(sync_key)
15
- return unless sync_key.kind.like? :language
16
- # the only difference between an `importable_info`
17
- # and a `resource_h` is the way `runner_url` is named
18
- Mumukit::Bridge::Runner.new(sync_key.id)
19
- .importable_info
20
- .replace_key(:test_runner_url, :runner_url)
21
- end
22
-
23
- def write_resource!(*)
24
- Mumukit::Sync::Store.read_only!
25
- end
26
- end
27
- end