Icarus-Mod-Tools 1.8.1 → 1.8.2

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: d70aff1f7ed368044b414fdca605fa438e0fbfe68c2af436d534a233fc6bff17
4
- data.tar.gz: e4467d443894344c50a2c3c663e262afd7e54cc806da308ecd16d732bcd2c844
3
+ metadata.gz: 63aa634da9108a8b439681f4bce95519bd04ba0e2cc416c5c2632502e8aa3c35
4
+ data.tar.gz: dce88dc6da4c3c43199973de099c7a578641ce03082bbac2a8943fcd69e6aa40
5
5
  SHA512:
6
- metadata.gz: 26c83360237ab149e6738e60966df113f8ede55460f85b0b2de29dd690cea238cdfda8af0ffc70f288ca58765b535d18b2cfcb21e0619b0a8226bfe099e7fecc
7
- data.tar.gz: 278435526ede69d45383920bee07fc3fc094924d022ed55c54141d00e9b53ef003d7688fb26bc4f251e3b13705b743013875583d553ca8c22198a7daeb590238
6
+ metadata.gz: 030db22ed72e78fec9a03a6f5412d35143492cd19080095b59efcafb47feb3db78b4a5cafc04edc1880e626f30d6127d35a470a7998ffe4403873672bf4002d0
7
+ data.tar.gz: 025040c5268bc151ea186573fb21dc083c51d4e9a5b5666fad8c988642aabbe4fe515fb882fe4ba0c03500357a8ea37cd868cfe1f1b5dc25c1f4456066f8d4d2
data/CHANGES.md CHANGED
@@ -4,19 +4,29 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  ## History (reverse chronological order)
6
6
 
7
- ### v1.6 - 2023-15
7
+ ### v1.8 - 2023-01-27
8
+
9
+ - Added support for `proginfo.json` files
10
+ - Refactored to better utilize caching
11
+
12
+ ### v1.7 - 2023-01-20
13
+
14
+ - Added `validation` command
15
+ - Added `--dry-run` to `sync` commands
16
+
17
+ ### v1.6 - 2023-01-15
8
18
 
9
19
  - Added `--check` to `sync mods` to check for updates without downloading
10
20
  - Added support for `readmeURL` in `modinfo.json`
11
21
 
12
- ### v1.5 - 2023-08
22
+ ### v1.5 - 2023-01-08
13
23
 
14
24
  - Moved source into the DonovanMods Github organization
15
25
  - Added `long_description` to `modinfo.json`
16
26
  - Added `imageURL` to `modinfo.json`
17
27
  - bugfixes
18
28
 
19
- ### v1.4 - 2023-03
29
+ ### v1.4 - 2023-01-03
20
30
 
21
31
  **BREAKING CHANGES!**
22
32
 
@@ -25,7 +35,7 @@ You'll need to move your ENV variables to a config file. See the README for more
25
35
  - Read configuration from `~/.imtconfig.json`
26
36
  - bugfixes
27
37
 
28
- ### v1.3 - 2023-02
38
+ ### v1.3 - 2023-01-02
29
39
 
30
40
  - First public release
31
41
  - Added sorting and filtering to the `list mods` command
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- Icarus-Mod-Tools (1.8.1)
4
+ Icarus-Mod-Tools (1.8.2)
5
5
  google-cloud-firestore (~> 2.7)
6
6
  octokit (~> 6.0)
7
7
  paint (~> 2.3)
data/README.md CHANGED
@@ -52,9 +52,17 @@ imt [options] [command]
52
52
  ### Commands
53
53
 
54
54
  ```sh
55
+ Commands:
55
56
  imt add # Adds entries to the databases
57
+ imt help [COMMAND] # Describe available commands or one specific command
56
58
  imt list # Lists the databases
57
59
  imt sync # Syncs the databases
60
+ imt validate # Validates various entries
61
+
62
+ Options:
63
+ -C, [--config=CONFIG] # Path to the config file
64
+ # Default: /Users/dyoung/.imtconfig.json
65
+ -V, [--version], [--no-version] # Print the version and exit
58
66
  ```
59
67
 
60
68
  #### `imt add`
@@ -63,9 +71,13 @@ imt [options] [command]
63
71
  Commands:
64
72
  imt add help [COMMAND] # Describe subcommands or one specific subcommand
65
73
  imt add modinfo # Adds an entry to 'meta/modinfo/list'
74
+ imt add proginfo # Adds an entry to 'meta/proginfo/list'
66
75
  imt add repos # Adds an entry to 'meta/repos/list'
67
76
 
68
77
  Options:
78
+ -C, [--config=CONFIG] # Path to the config file
79
+ # Default: /Users/dyoung/.imtconfig.json
80
+ -V, [--version], [--no-version] # Print the version and exit
69
81
  -v, [--verbose], [--no-verbose] # Increase verbosity. May be repeated for even more verbosity.
70
82
  # Default: [true]
71
83
  ```
@@ -77,9 +89,14 @@ Commands:
77
89
  imt list help [COMMAND] # Describe subcommands or one specific subcommand
78
90
  imt list modinfo # Displays data from 'meta/modinfo/list'
79
91
  imt list mods # Displays data from 'mods'
92
+ imt list proginfo # Displays data from 'meta/proginfo/list'
93
+ imt list progs # Displays data from 'progs'
80
94
  imt list repos # Displays data from 'meta/repos/list'
81
95
 
82
96
  Options:
97
+ -C, [--config=CONFIG] # Path to the config file
98
+ # Default: /Users/dyoung/.imtconfig.json
99
+ -V, [--version], [--no-version] # Print the version and exit
83
100
  -v, [--verbose], [--no-verbose] # Increase verbosity. May be repeated for even more verbosity.
84
101
  # Default: [true]
85
102
  ```
@@ -88,13 +105,20 @@ Options:
88
105
 
89
106
  ```sh
90
107
  Commands:
108
+ imt sync all # Run all sync jobs
91
109
  imt sync help [COMMAND] # Describe subcommands or one specific subcommand
92
110
  imt sync modinfo # Reads from 'meta/repos/list' and Syncs any modinfo files we find (github only for now)
93
111
  imt sync mods # Reads from 'meta/modinfo/list' and updates the 'mods' database accordingly
112
+ imt sync proginfo # Reads from 'meta/repos/list' and Syncs any proginfo files we find (github only for now)
113
+ imt sync progs # Reads from 'meta/proginfo/list' and updates the 'progs' database accordingly
94
114
 
95
115
  Options:
116
+ -C, [--config=CONFIG] # Path to the config file
117
+ # Default: /Users/dyoung/.imtconfig.json
118
+ -V, [--version], [--no-version] # Print the version and exit
96
119
  -v, [--verbose], [--no-verbose] # Increase verbosity. May be repeated for even more verbosity.
97
120
  # Default: [true]
121
+ [--dry-run], [--no-dry-run] # Dry run (no changes will be made)
98
122
  ```
99
123
 
100
124
  ## Development
@@ -1,15 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "tools/modinfo_sync"
4
- require "tools/proginfo_sync"
5
- require "tools/mod_sync"
6
- require "tools/prog_sync"
3
+ require "tools/sync/modinfo"
4
+ require "tools/sync/proginfo"
5
+ require "tools/sync/mods"
6
+ require "tools/sync/progs"
7
7
 
8
8
  module Icarus
9
9
  module Mod
10
10
  module CLI
11
11
  # Sync CLI command definitions
12
+ # rubocop:disable Style/GlobalVars
12
13
  class Sync < SubcommandBase
14
+ $firestore = nil
15
+
13
16
  class_option :dry_run, type: :boolean, default: false, desc: "Dry run (no changes will be made)"
14
17
 
15
18
  desc "all", "Run all sync jobs"
@@ -43,8 +46,12 @@ module Icarus
43
46
  end
44
47
 
45
48
  no_commands do
49
+ def firestore
50
+ $firestore ||= Firestore.new
51
+ end
52
+
46
53
  def sync_info(type)
47
- sync = (type == :modinfo ? Icarus::Mod::Tools::ModinfoSync : Icarus::Mod::Tools::ProginfoSync).new
54
+ sync = (type == :modinfo ? Icarus::Mod::Tools::Sync::Modinfo : Icarus::Mod::Tools::Sync::Proginfo).new(client: firestore)
48
55
 
49
56
  puts "Retrieving repository Data..." if verbose?
50
57
  repositories = sync.repositories
@@ -69,7 +76,7 @@ module Icarus
69
76
  end
70
77
 
71
78
  def sync_list(type)
72
- sync = (type == :mods ? Icarus::Mod::Tools::ModSync : Icarus::Mod::Tools::ProgSync).new
79
+ sync = (type == :mods ? Icarus::Mod::Tools::Sync::Mods : Icarus::Mod::Tools::Sync::Progs).new(client: firestore)
73
80
 
74
81
  puts "Retrieving Info Data..." if verbose?
75
82
  info_array = sync.info_array
@@ -128,6 +135,7 @@ module Icarus
128
135
  end
129
136
  end
130
137
  end
138
+ # rubocop:enable Style/GlobalVars
131
139
  end
132
140
  end
133
141
  end
@@ -25,6 +25,7 @@ module Icarus
25
25
  puts "Validating Entries..." if verbose?
26
26
  max_length = validator.array.map { |info| info.uniq_name.length }.max + 1
27
27
 
28
+ # rubocop:disable Lint/FormatParameterMismatch
28
29
  validator.array.each do |info|
29
30
  print Paint[format("%s %-#{max_length}s", "Running validation steps on", info.uniq_name), :cyan, :bright] if verbose > 1
30
31
 
@@ -46,6 +47,7 @@ module Icarus
46
47
  puts info.warnings.map { |warning| Paint["#{warning} in #{info.uniq_name}", :yellow] }.join("\n")
47
48
  puts "\n" if verbose > 1
48
49
  end
50
+ # rubocop:enable Lint/FormatParameterMismatch
49
51
 
50
52
  exit exit_code
51
53
  end
@@ -19,12 +19,12 @@ module Icarus
19
19
  @repos ||= list(:repositories)
20
20
  end
21
21
 
22
- def modinfo_list
23
- @modinfo_list ||= list(:modinfo)
22
+ def modinfo
23
+ @modinfo ||= list(:modinfo)
24
24
  end
25
25
 
26
- def proginfo_list
27
- @proginfo_list ||= list(:proginfo)
26
+ def proginfo
27
+ @proginfo ||= list(:proginfo)
28
28
  end
29
29
 
30
30
  def mods
@@ -72,7 +72,7 @@ module Icarus
72
72
 
73
73
  case type.to_sym
74
74
  when :modinfo, :proginfo
75
- update_array = (send("#{type}_list") + [payload]).flatten.uniq
75
+ update_array = (send(type) + [payload]).flatten.uniq
76
76
  response = @client.doc(collections.send(type)).set({ list: update_array }, merge:) if update_array.any?
77
77
  when :repositories
78
78
  response = @client.doc(collections.repositories).set({ list: payload }, merge:)
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+ require "net/http"
5
+ require "json"
6
+
7
+ module Icarus
8
+ module Mod
9
+ module Tools
10
+ module Sync
11
+ class RequestFailed < StandardError; end
12
+
13
+ # Sync helper methods
14
+ module Helpers
15
+ def retrieve_from_url(url)
16
+ res = Net::HTTP.get_response(URI(url))
17
+
18
+ raise RequestFailed, "HTTP Request failed for #{url} (#{res.code}): #{res.message}" unless res&.code == "200"
19
+
20
+ JSON.parse(res.body, symbolize_names: true)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "firestore"
4
+ require "github"
5
+ require "tools/sync/helpers"
6
+
7
+ module Icarus
8
+ module Mod
9
+ module Tools
10
+ module Sync
11
+ # Sync methods
12
+ class Modinfo
13
+ include Helpers
14
+
15
+ def initialize(client: nil)
16
+ @firestore = client || Firestore.new
17
+ @github = Github.new
18
+ @repositories = []
19
+ end
20
+
21
+ def repositories
22
+ @firestore.repos
23
+ end
24
+
25
+ def update(modinfo_array)
26
+ @firestore.update(:modinfo, modinfo_array)
27
+ end
28
+
29
+ def modinfo(url)
30
+ retrieve_from_url(url)
31
+ end
32
+
33
+ def data(repositories, verbose: false)
34
+ repositories.map do |repo|
35
+ print "searching #{repo}..." if verbose
36
+
37
+ case repo
38
+ when /github/
39
+ @github.repository = repo
40
+ modinfo_url = @github.find("modinfo.json")
41
+
42
+ unless modinfo_url
43
+ puts "Skipped...no modinfo.json" if verbose
44
+ next
45
+ end
46
+
47
+ puts "Found!" if verbose
48
+ modinfo_url
49
+ else
50
+ puts "Skipped...repository type not supported yet" if verbose
51
+ end
52
+ end.compact
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "firestore"
4
+ require "tools/sync/helpers"
5
+
6
+ module Icarus
7
+ module Mod
8
+ module Tools
9
+ module Sync
10
+ # Sync methods
11
+ class Mods
12
+ include Helpers
13
+
14
+ def initialize(client: nil)
15
+ @firestore = client || Firestore.new
16
+ end
17
+
18
+ def mods
19
+ @firestore.mods
20
+ end
21
+
22
+ def info_array
23
+ @info_array ||= @firestore.modinfo.map do |url|
24
+ retrieve_from_url(url)[:mods].map { |mod| Tools::Modinfo.new(mod) if mod[:name] =~ /[a-z0-9]+/i }
25
+ rescue Icarus::Mod::Tools::Sync::RequestFailed
26
+ warn "Skipped; Failed to retrieve #{url}"
27
+ next
28
+ rescue JSON::ParserError => e
29
+ warn "Skipped; Invalid JSON: #{e.full_message}"
30
+ next
31
+ end.flatten.compact
32
+ end
33
+
34
+ def find(modinfo)
35
+ @firestore.find_by_type(type: "mods", name: modinfo.name, author: modinfo.author)&.id
36
+ end
37
+
38
+ def find_info(modinfo)
39
+ @info_array.find { |mod| mod.name == modinfo.name }
40
+ end
41
+
42
+ def update(modinfo)
43
+ @firestore.update(:mod, modinfo, merge: false)
44
+ end
45
+
46
+ def delete(modinfo)
47
+ @firestore.delete(:mod, modinfo)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "firestore"
4
+ require "github"
5
+ require "tools/sync/helpers"
6
+
7
+ module Icarus
8
+ module Mod
9
+ module Tools
10
+ module Sync
11
+ # Sync methods
12
+ class Proginfo
13
+ include Helpers
14
+
15
+ def initialize(client: nil)
16
+ @firestore = client || Firestore.new
17
+ @github = Github.new
18
+ @repositories = []
19
+ end
20
+
21
+ def repositories
22
+ @firestore.repos
23
+ end
24
+
25
+ def update(proginfo_array)
26
+ @firestore.update(:proginfo, proginfo_array)
27
+ end
28
+
29
+ def proginfo(url)
30
+ retrieve_from_url(url)
31
+ end
32
+
33
+ def data(repositories, verbose: false)
34
+ repositories.map do |repo|
35
+ print "searching #{repo}..." if verbose
36
+
37
+ case repo
38
+ when /github/
39
+ @github.repository = repo
40
+ proginfo_url = @github.find("proginfo.json")
41
+
42
+ unless proginfo_url
43
+ puts "Skipped...no proginfo.json" if verbose
44
+ next
45
+ end
46
+
47
+ puts "Found!" if verbose
48
+ proginfo_url
49
+ else
50
+ puts "Skipped...repository type not supported yet" if verbose
51
+ end
52
+ end.compact
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "firestore"
4
+ require "tools/sync/helpers"
5
+
6
+ module Icarus
7
+ module Mod
8
+ module Tools
9
+ module Sync
10
+ # Sync methods
11
+ class Progs
12
+ include Helpers
13
+
14
+ def initialize(client: nil)
15
+ @firestore = client || Firestore.new
16
+ end
17
+
18
+ def progs
19
+ @firestore.progs
20
+ end
21
+
22
+ def info_array
23
+ @info_array ||= @firestore.proginfo.map do |url|
24
+ retrieve_from_url(url)[:programs].map { |prog| Tools::Proginfo.new(prog) if prog[:name] =~ /[a-z0-9]+/i }
25
+ rescue Icarus::Mod::Tools::Sync::RequestFailed
26
+ warn "Skipped; Failed to retrieve #{url}"
27
+ next
28
+ rescue JSON::ParserError => e
29
+ warn "Skipped; Invalid JSON: #{e.full_message}"
30
+ next
31
+ end.flatten.compact
32
+ end
33
+
34
+ def find(proginfo)
35
+ @firestore.find_by_type(type: "progs", name: proginfo.name, author: proginfo.author)&.id
36
+ end
37
+
38
+ def find_info(proginfo)
39
+ @info_array.find { |prog| prog.name == proginfo.name }
40
+ end
41
+
42
+ def update(proginfo)
43
+ @firestore.update(:prog, proginfo, merge: false)
44
+ end
45
+
46
+ def delete(proginfo)
47
+ @firestore.delete(:prog, proginfo)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -10,9 +10,9 @@ module Icarus
10
10
  def initialize(type)
11
11
  @array = case type
12
12
  when :modinfo
13
- ModSync.new.info_array
13
+ Sync::Mods.new.info_array
14
14
  when :proginfo
15
- ProgSync.new.info_array
15
+ Sync::Progs.new.info_array
16
16
  else
17
17
  raise ArgumentError, "Invalid type: #{type}"
18
18
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Icarus
4
4
  module Mod
5
- VERSION = "1.8.1"
5
+ VERSION = "1.8.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Icarus-Mod-Tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.1
4
+ version: 1.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donovan Young
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-27 00:00:00.000000000 Z
11
+ date: 2023-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-cloud-firestore
@@ -98,13 +98,13 @@ files:
98
98
  - lib/icarus/mod/github.rb
99
99
  - lib/icarus/mod/tools.rb
100
100
  - lib/icarus/mod/tools/baseinfo.rb
101
- - lib/icarus/mod/tools/mod_sync.rb
102
101
  - lib/icarus/mod/tools/modinfo.rb
103
- - lib/icarus/mod/tools/modinfo_sync.rb
104
- - lib/icarus/mod/tools/prog_sync.rb
105
102
  - lib/icarus/mod/tools/proginfo.rb
106
- - lib/icarus/mod/tools/proginfo_sync.rb
107
- - lib/icarus/mod/tools/sync_helpers.rb
103
+ - lib/icarus/mod/tools/sync/helpers.rb
104
+ - lib/icarus/mod/tools/sync/modinfo.rb
105
+ - lib/icarus/mod/tools/sync/mods.rb
106
+ - lib/icarus/mod/tools/sync/proginfo.rb
107
+ - lib/icarus/mod/tools/sync/progs.rb
108
108
  - lib/icarus/mod/tools/validator.rb
109
109
  - lib/icarus/mod/version.rb
110
110
  - sig/database/sync/sync.rbs
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "firestore"
4
- require "tools/sync_helpers"
5
-
6
- module Icarus
7
- module Mod
8
- module Tools
9
- # Sync methods
10
- class ModSync
11
- include SyncHelpers
12
-
13
- def initialize
14
- @firestore = Firestore.new
15
- end
16
-
17
- def mods
18
- @firestore.mods
19
- end
20
-
21
- def info_array
22
- @info_array ||= @firestore.modinfo_list.map do |url|
23
- retrieve_from_url(url)[:mods].map { |mod| Modinfo.new(mod) if mod[:name] =~ /[a-z0-9]+/i }
24
- rescue Icarus::Mod::Tools::RequestFailed
25
- warn "Skipped; Failed to retrieve #{url}"
26
- next
27
- rescue JSON::ParserError => e
28
- warn "Skipped; Invalid JSON: #{e.full_message}"
29
- next
30
- end.flatten.compact
31
- end
32
-
33
- def find(modinfo)
34
- @firestore.find_by_type(type: "mods", name: modinfo.name, author: modinfo.author)&.id
35
- end
36
-
37
- def find_info(modinfo)
38
- @info_array.find { |mod| mod.name == modinfo.name }
39
- end
40
-
41
- def update(modinfo)
42
- @firestore.update(:mod, modinfo, merge: false)
43
- end
44
-
45
- def delete(modinfo)
46
- @firestore.delete(:mod, modinfo)
47
- end
48
- end
49
- end
50
- end
51
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "firestore"
4
- require "github"
5
- require "tools/sync_helpers"
6
-
7
- module Icarus
8
- module Mod
9
- module Tools
10
- # Sync methods
11
- class ModinfoSync
12
- include SyncHelpers
13
-
14
- def initialize
15
- @firestore = Firestore.new
16
- @github = Github.new
17
- @repositories = []
18
- end
19
-
20
- def repositories
21
- @firestore.repos
22
- end
23
-
24
- def update(modinfo_array)
25
- @firestore.update(:modinfo, modinfo_array)
26
- end
27
-
28
- def modinfo(url)
29
- retrieve_from_url(url)
30
- end
31
-
32
- def data(repositories, verbose: false)
33
- repositories.map do |repo|
34
- print "searching #{repo}..." if verbose
35
-
36
- case repo
37
- when /github/
38
- @github.repository = repo
39
- modinfo_url = @github.find("modinfo.json")
40
-
41
- unless modinfo_url
42
- puts "Skipped...no modinfo.json" if verbose
43
- next
44
- end
45
-
46
- puts "Found!" if verbose
47
- modinfo_url
48
- else
49
- puts "Skipped...repository type not supported yet" if verbose
50
- end
51
- end.compact
52
- end
53
- end
54
- end
55
- end
56
- end
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "firestore"
4
- require "tools/sync_helpers"
5
-
6
- module Icarus
7
- module Mod
8
- module Tools
9
- # Sync methods
10
- class ProgSync
11
- include SyncHelpers
12
-
13
- def initialize
14
- @firestore = Firestore.new
15
- end
16
-
17
- def progs
18
- @firestore.progs
19
- end
20
-
21
- def info_array
22
- @info_array ||= @firestore.proginfo_list.map do |url|
23
- retrieve_from_url(url)[:programs].map { |prog| Proginfo.new(prog) if prog[:name] =~ /[a-z0-9]+/i }
24
- rescue Icarus::Mod::Tools::RequestFailed
25
- warn "Skipped; Failed to retrieve #{url}"
26
- next
27
- rescue JSON::ParserError => e
28
- warn "Skipped; Invalid JSON: #{e.full_message}"
29
- next
30
- end.flatten.compact
31
- end
32
-
33
- def find(proginfo)
34
- @firestore.find_by_type(type: "progs", name: proginfo.name, author: proginfo.author)&.id
35
- end
36
-
37
- def find_info(proginfo)
38
- @info_array.find { |prog| prog.name == proginfo.name }
39
- end
40
-
41
- def update(proginfo)
42
- @firestore.update(:prog, proginfo, merge: false)
43
- end
44
-
45
- def delete(proginfo)
46
- @firestore.delete(:prog, proginfo)
47
- end
48
- end
49
- end
50
- end
51
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "firestore"
4
- require "github"
5
- require "tools/sync_helpers"
6
-
7
- module Icarus
8
- module Mod
9
- module Tools
10
- # Sync methods
11
- class ProginfoSync
12
- include SyncHelpers
13
-
14
- def initialize
15
- @firestore = Firestore.new
16
- @github = Github.new
17
- @repositories = []
18
- end
19
-
20
- def repositories
21
- @firestore.repos
22
- end
23
-
24
- def update(proginfo_array)
25
- @firestore.update(:proginfo, proginfo_array)
26
- end
27
-
28
- def proginfo(url)
29
- retrieve_from_url(url)
30
- end
31
-
32
- def data(repositories, verbose: false)
33
- repositories.map do |repo|
34
- print "searching #{repo}..." if verbose
35
-
36
- case repo
37
- when /github/
38
- @github.repository = repo
39
- proginfo_url = @github.find("proginfo.json")
40
-
41
- unless proginfo_url
42
- puts "Skipped...no proginfo.json" if verbose
43
- next
44
- end
45
-
46
- puts "Found!" if verbose
47
- proginfo_url
48
- else
49
- puts "Skipped...repository type not supported yet" if verbose
50
- end
51
- end.compact
52
- end
53
- end
54
- end
55
- end
56
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "uri"
4
- require "net/http"
5
- require "json"
6
-
7
- module Icarus
8
- module Mod
9
- module Tools
10
- class RequestFailed < StandardError; end
11
-
12
- # Sync helper methods
13
- module SyncHelpers
14
- def retrieve_from_url(url)
15
- res = Net::HTTP.get_response(URI(url))
16
-
17
- raise Icarus::Mod::Tools::RequestFailed, "HTTP Request failed for #{url} (#{res.code}): #{res.message}" unless res&.code == "200"
18
-
19
- JSON.parse(res.body, symbolize_names: true)
20
- end
21
- end
22
- end
23
- end
24
- end