mumukit-sync 0.3.5 → 0.4.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: e5a273da509a30c17365db8f990425f7116dc5ab6884ff21a75fd84c6d05f7a3
4
- data.tar.gz: b1d81c933d5896316a560539126164926a0577dcf2970ea87f2dbd82f75df6ba
3
+ metadata.gz: 7feb07d1901e4d169f61f50b7d9d5e5b002ef659d7315fd78f06ca5506886e0a
4
+ data.tar.gz: dc32e9012638c59634d1e509ae95259e03353fc3301feaf94f3adc9effd29dd8
5
5
  SHA512:
6
- metadata.gz: e08e6107f11396be371a1c049b4b3593e1c8e87d3e2dd2a51725734d2d35b8d993b7a66a92c55ea8b7cb4f9a46d2744efcdf8fae57866bf4f94478d2056b97ee
7
- data.tar.gz: 4602d21980a71ed33b2d550f470af08fe8bfabcb0c1a6011c0317bdc525a59a7e4f4595fd03e0b5452b786e819fd79f34bd41a313127e2614c7e013333a8750f
6
+ metadata.gz: 7e12bc3c131aaa6f6aa623613daa615490b56d93b52c6a952eee900a91f6f30f65736e0c0d62a05e1da6d0169b40f6c6d8f2cf2fd368eec9fad6760029b4e9d8
7
+ data.tar.gz: 1bd94411302041cb9fa4c303a7ed7adfa58e67a7c5ef4d0d9d6a706c21b2e4c94112e8d94891c9606c4b5a1555bd3c617cafd677506362e8d7212582c315cbf5
@@ -26,6 +26,9 @@ module Mumukit
26
26
  def self.classify(kind)
27
27
  kind.as_module_name
28
28
  end
29
+
30
+ class SyncError < StandardError
31
+ end
29
32
  end
30
33
  end
31
34
 
@@ -2,6 +2,13 @@ require 'mumukit/bridge'
2
2
 
3
3
  module Mumukit::Sync
4
4
  module Store
5
+ def self.non_discoverable!
6
+ raise Mumukit::Sync::SyncError, 'Non-discoverable store'
7
+ end
8
+
9
+ def self.read_only!
10
+ raise Mumukit::Sync::SyncError, 'Read-only store'
11
+ end
5
12
  end
6
13
  end
7
14
 
@@ -23,7 +23,7 @@ module Mumukit::Sync::Store
23
23
  end
24
24
 
25
25
  def write_resource!(*)
26
- raise 'Read-only store'
26
+ Mumukit::Sync::Store.read_only!
27
27
  end
28
28
  end
29
29
  end
@@ -10,7 +10,7 @@ module Mumukit::Sync::Store
10
10
  end
11
11
 
12
12
  def sync_keys
13
- raise 'Non-discoverable store'
13
+ Mumukit::Sync::Store.non_discoverable!
14
14
  end
15
15
 
16
16
  def read_resource(sync_key)
@@ -19,8 +19,8 @@ class Mumukit::Sync::Store::Github
19
19
  local_repo.config('user.email', email)
20
20
  yield dir, local_repo
21
21
  rescue Git::GitExecuteError => e
22
- raise 'Repository is private or does not exist' if private_repo_error(e.message)
23
- raise e
22
+ raise Mumukit::Sync::SyncError, 'Repository is private or does not exist' if private_repo_error(e.message)
23
+ raise Mumukit::Sync::SyncError, e
24
24
  end
25
25
 
26
26
  def register_post_commit_hook!(slug, web_hook_base_url)
@@ -22,6 +22,8 @@ class Mumukit::Sync::Store::Github
22
22
  private
23
23
 
24
24
  def build_json
25
+ raise Mumukit::Sync::SyncError, "Missing guide language" if language[:name].blank?
26
+
25
27
  {name: name,
26
28
  description: description,
27
29
  corollary: corollary,
@@ -39,7 +39,7 @@ class Mumukit::Sync::Store::Github
39
39
  end
40
40
 
41
41
  def clear_repo(local_repo)
42
- local_repo.remove %w(LICENSE.txt README.md COPYRIGHT.txt AUTHORS.txt COLLABORATORS.txt description.md corollary.md meta.yml extra.yml expectations.* *_*/*)
42
+ local_repo.remove Mumukit::Sync::Store::Github::Schema::Guide.file_patterns
43
43
  rescue Git::GitExecuteError => e
44
44
  puts 'Nothing to clean, repo seems to be empty'
45
45
  end
@@ -12,9 +12,9 @@ class Mumukit::Sync::Store::Github
12
12
  def read_guide!
13
13
  builder = GuideBuilder.new(@slug)
14
14
 
15
- read_meta! builder
15
+ read_guide_meta! builder
16
16
  Mumukit::Sync::Store::Github::Schema::Guide.file_fields.each do |it|
17
- value = it.read_field_file(dir)
17
+ value = it.read_field_file 'guide', dir
18
18
  builder[it.reverse_name] = value
19
19
  end
20
20
  read_exercises! builder
@@ -22,10 +22,17 @@ class Mumukit::Sync::Store::Github
22
22
  builder.build
23
23
  end
24
24
 
25
- def read_meta!(builder)
25
+ def read_meta!(description, dir)
26
26
  meta = read_yaml_file(File.join(dir, 'meta.yml'))
27
+ raise Mumukit::Sync::SyncError, "Missing #{description} meta.yml" unless meta
27
28
 
28
- raise 'Missing meta.yml' unless meta
29
+ meta
30
+ rescue Psych::SyntaxError
31
+ raise Mumukit::Sync::SyncError, "Bad #{description} metadata syntax"
32
+ end
33
+
34
+ def read_guide_meta!(builder)
35
+ meta = read_meta! 'guide', dir
29
36
 
30
37
  builder.language = { name: meta['language'] }
31
38
  builder.locale = meta['locale']
@@ -60,7 +67,7 @@ class Mumukit::Sync::Store::Github
60
67
  each_exercise_file do |root, position, id, name|
61
68
  builder = ExerciseBuilder.new
62
69
 
63
- meta = read_yaml_file(File.join(root, 'meta.yml'))
70
+ meta = read_meta! "exercise #{name}", root
64
71
  meta['language'] &&= { name: meta['language'] }
65
72
 
66
73
  builder.meta = meta
@@ -68,7 +75,7 @@ class Mumukit::Sync::Store::Github
68
75
  builder.name = meta['name'] || name
69
76
 
70
77
  Mumukit::Sync::Store::Github::Schema::Exercise.file_fields.each do |it|
71
- value = it.read_field_file(root)
78
+ value = it.read_field_file "exercise #{name}", root
72
79
  builder[it.reverse_name] = value
73
80
  end
74
81
  yield builder
@@ -32,6 +32,14 @@ class Mumukit::Sync::Store::Github
32
32
  fields.select { |it| it.kind == :file }
33
33
  end
34
34
 
35
+ def file_patterns
36
+ file_fields.map(&:get_file_pattern) + fixed_file_patterns
37
+ end
38
+
39
+ def fixed_file_patterns
40
+ []
41
+ end
42
+
35
43
  def fields
36
44
  @field ||= fields_schema.map { |it| new_field(it) }
37
45
  end
@@ -74,6 +82,9 @@ class Mumukit::Sync::Store::Github
74
82
  end
75
83
 
76
84
  ## Writing fields to Github
85
+ def get_file_pattern
86
+ get_file_name extension: '*', test_extension: '*'
87
+ end
77
88
 
78
89
  def get_file_name(language)
79
90
  "#{name}.#{get_file_extension(language)}"
@@ -100,19 +111,19 @@ class Mumukit::Sync::Store::Github
100
111
 
101
112
  ## Reading fields from Github
102
113
 
103
- def find_file_name(root)
114
+ def find_file_name(description, root)
104
115
  files = Dir.glob("#{root}/#{name}.*")
105
116
  if files.length == 1
106
117
  files[0]
107
118
  elsif files.empty? && required
108
- raise "Missing #{name} file"
119
+ raise Mumukit::Sync::SyncError, "Missing #{description} #{name} file"
109
120
  else
110
121
  nil
111
122
  end
112
123
  end
113
124
 
114
- def read_field_file(root)
115
- find_file_name(root).try { |it| safe_transform.from.call it }
125
+ def read_field_file(description, root)
126
+ find_file_name(description, root).try { |it| safe_transform.from.call it }
116
127
  end
117
128
 
118
129
  end
@@ -16,13 +16,19 @@ module Mumukit::Sync::Store::Github::Schema::Guide
16
16
  {name: :id_format, kind: :metadata},
17
17
  {name: :order, kind: :metadata, transform: with { |it| it.map { |e| e[:id] } }, reverse: :exercises},
18
18
  {name: :private, kind: :metadata},
19
- {name: :expectations},
20
19
 
20
+ {name: :expectations, kind: :file, extension: 'yml', transform: yaml_list('expectations')},
21
21
  {name: :description, kind: :file, extension: 'md', required: true},
22
22
  {name: :corollary, kind: :file, extension: 'md'},
23
+ {name: :sources, kind: :file, extension: 'md'},
24
+ {name: :learn_more, kind: :file, extension: 'md'},
23
25
  {name: :extra, kind: :file, extension: :code},
24
26
  {name: :AUTHORS, kind: :file, extension: 'txt', reverse: :authors},
25
27
  {name: :COLLABORATORS, kind: :file, extension: 'txt', reverse: :collaborators}
26
28
  ]
27
29
  end
30
+
31
+ def self.fixed_file_patterns
32
+ %w(LICENSE.txt README.md COPYRIGHT.txt meta.yml *_*/*)
33
+ end
28
34
  end
@@ -5,7 +5,7 @@ module Mumukit::Sync::Store
5
5
  end
6
6
 
7
7
  def sync_keys
8
- raise 'Non-discoverable store'
8
+ Mumukit::Sync::Store.non_discoverable!
9
9
  end
10
10
 
11
11
  def do_read(_sync_key)
@@ -13,7 +13,7 @@ module Mumukit::Sync::Store
13
13
  end
14
14
 
15
15
  def write_resource!(*)
16
- raise 'Read-only store'
16
+ Mumukit::Sync::Store.read_only!
17
17
  end
18
18
  end
19
19
  end
@@ -4,7 +4,7 @@ module Mumukit::Sync::Store
4
4
  end
5
5
 
6
6
  def read_resource(key)
7
- raise "#{key.kind} #{key.id} not found"
7
+ raise Mumukit::Sync::SyncError, "Non-readable store"
8
8
  end
9
9
  end
10
10
  end
@@ -21,7 +21,7 @@ module Mumukit::Sync::Store
21
21
  end
22
22
 
23
23
  def write_resource!(*)
24
- raise 'Read-only store'
24
+ Mumukit::Sync::Store.read_only!
25
25
  end
26
26
  end
27
27
  end
@@ -1,5 +1,5 @@
1
1
  module Mumukit
2
2
  module Sync
3
- VERSION = '0.3.5'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  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.3.5
4
+ version: 0.4.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-01-16 00:00:00.000000000 Z
11
+ date: 2019-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mumukit-core