Skip to content

Commit 32869d1

Browse files
Develop (#25)
* Display URL of card if it's updated * Sync main and master (#17) * Refactor and bump cards * Take in account matomo cards * Detect local database dynamically * Update config yml example * Add specs for main lib * Fix rubocop offenses * Define module variables * Add configs fixture in specs * Add specs for 'main.find_db_for' * Refactor and add documentation (#18) * Add .env.example * Add ruby platform to Gemfile.lock * Add error for config file not found * Fix rubocop offenses * Update git ignore * Add specs for main * Fix rubocop offenses * Remove failing spec * Light fix in cards * Add documentation * [Refactor] - Cleanup of main program and libraries (#19) * Refactor metabase_url * Move query_interpreter * Create Config class * Define Config class * Move ConfigNotFound to Config file * Add config class * Refactor config and main lib * Optimizing main creation * refactor main script * Fix rubocop offenses * Update rubocop rules and fix offenses * Fix specs * Add specs * Update specs * add specs for interpreter * Fix api collection specs * Fix api database specs * Fix api session specs * Fix api spec collection * Remove unnecessary libraries * Fix rubocop offenses * Add URL for accessing created questions (#22) * [Feature] - Meta column translator (#20) * Add warnings for undefined database * Free memory when fetching metabase cards * Light optimization for metabase collection * Move metabase card fetch in function context for memory * Enable columns translation * Remove byebug requirement * Feature/add description (#24) * Add description renaming * Rename 'meta' to columns in mapping * Fix Rubocop offenses * Refactor fs card column translation * Update cards subrepositories * Harmonize error output on STDOUT * Fix fs card translation * Remove unnecessary rubocop rule Co-authored-by: Quentinchampenois <[email protected]> * Update submodules * Ignore all .env files * Add description to model creation * Adapt specs * Modify main.rb to precise config file directly as sys arg * Update submodules --------- Co-authored-by: Quentin Champenois <[email protected]>
1 parent 129c8fc commit 32869d1

29 files changed

+530
-172
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
METABASE_HOST=metabase.example.com
2+
METABASE_USERNAME=[email protected]
3+
METABASE_PASSWORD=secretpassword

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
# rspec failure tracking
1212
.rspec_status
13-
.env
13+
.env*
1414
**/*.private
1515
config.yml
16+
.byebug_history

.rubocop.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
AllCops:
2+
NewCops: enable
23
TargetRubyVersion: 2.7.1
34
Exclude:
45
- "bin/*.rb"
@@ -23,22 +24,23 @@ Layout/LineLength:
2324
Enabled: true
2425
Exclude:
2526
- spec/api/collection_spec.rb
26-
Max: 120
27+
Max: 130
2728

2829
Metrics/AbcSize:
29-
Enabled: true
30-
Exclude:
31-
- lib/decidim_metabase/api/session.rb
32-
30+
Enabled: false
3331

3432
Metrics/ModuleLength:
3533
Enabled: true
3634
Exclude:
37-
- spec/api/collection_spec.rb
35+
- spec/**/*_spec.rb
36+
37+
Metrics/MethodLength:
38+
Enabled: false
3839

3940
Metrics/BlockLength:
4041
Enabled: true
4142
Exclude:
42-
- spec/api/collection_spec.rb
43-
- spec/api/database_spec.rb
44-
- spec/api/session_spec.rb
43+
- spec/**/*_spec.rb
44+
45+
Metrics/ClassLength:
46+
Enabled: false

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ gem "rspec", "~> 3.0"
1111

1212
gem "byebug"
1313
gem "rubocop", "~> 1.7"
14+
gem "webmock"

Gemfile.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,24 @@ PATH
1010
GEM
1111
remote: https://rubygems.org/
1212
specs:
13+
addressable (2.8.1)
14+
public_suffix (>= 2.0.2, < 6.0)
1315
ast (2.4.2)
1416
byebug (11.1.3)
1517
colorize (0.8.1)
18+
crack (0.4.5)
19+
rexml
1620
diff-lcs (1.5.0)
1721
dotenv (2.7.6)
1822
faraday (2.3.0)
1923
faraday-net_http (~> 2.0)
2024
ruby2_keywords (>= 0.0.4)
2125
faraday-net_http (2.0.3)
26+
hashdiff (1.0.1)
2227
parallel (1.22.1)
2328
parser (3.1.2.0)
2429
ast (~> 2.4.1)
30+
public_suffix (5.0.0)
2531
rainbow (3.1.1)
2632
rake (13.0.6)
2733
regexp_parser (2.3.0)
@@ -54,8 +60,13 @@ GEM
5460
ruby2_keywords (0.0.5)
5561
tsort (0.1.0)
5662
unicode-display_width (2.1.0)
63+
webmock (3.18.1)
64+
addressable (>= 2.8.0)
65+
crack (>= 0.3.2)
66+
hashdiff (>= 0.4.0, < 2.0.0)
5767

5868
PLATFORMS
69+
ruby
5970
x86_64-darwin-19
6071

6172
DEPENDENCIES
@@ -64,6 +75,7 @@ DEPENDENCIES
6475
rake (~> 13.0)
6576
rspec (~> 3.0)
6677
rubocop (~> 1.7)
78+
webmock
6779

6880
BUNDLED WITH
6981
2.3.10

cards/decidim_cards

Submodule decidim_cards updated 148 files

decidim_metabase.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ Gem::Specification.new do |spec|
3636
spec.add_dependency "dotenv"
3737
spec.add_dependency "faraday"
3838
spec.add_dependency "tsort"
39+
spec.metadata["rubygems_mfa_required"] = "true"
3940
end

docs/GETTING_STARTED.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Getting started with Metabase Automation !
2+
3+
Let's see how to setup your environment for using the Metabase Automation System.
4+
5+
## Requirements
6+
7+
* Online Metabase instance
8+
* Username + Password able to connect on the instance
9+
* Decidim Database already set on Metabase
10+
11+
## Let's start
12+
13+
1. Set the required environment variable
14+
Copy the file `.env.example` and rename it as `.env`. Once done, add your credentials and the metabase host. You must not add the metabase URL but the host only.
15+
16+
2. Create the main `config.yml` file
17+
This file is the global configuration of the project. It is used by the program to link local cards to the right Metabase database. Also, it allows to define the current locale and the decidim host.
18+
19+
There is several keys in this file :
20+
```yaml
21+
---
22+
database:
23+
decidim_cards:
24+
name: <EXISTING METABASE DATABASE>
25+
matomo_cards:
26+
name: <EXISTING METABASE DATABASE>
27+
collection_name: <NEW OR EXISTING METABASE COLLECTION>
28+
language: fr # en
29+
host: <HOST>
30+
```
31+
* `database` - Allows to link a cards folder to a Metabase database
32+
* In the example above, there is two keys `decidim_cards` and `matomo_cards`. These keys are the name of the folders present in `/cards`.
33+
* You must define at least one database. For example you can remove the database key `matomo_cards`.
34+
* You can find existing database in Metabase
35+
* `collection_name` - Name of collection on Metabase.
36+
* If the collection doesn't exist, the program will create it. Otherwise it use the existing one.
37+
* You can find an existing collection name in Metabase
38+
* `language` - Define the translation of cards in Metabase
39+
* Cards must contains the right translation to work as expected (see example [decidim users translations](../cards/decidim_cards/users/locales/en.yml))
40+
* If locale doesn't exist, default is English
41+
* `host` - Decidim host for cards which depends on the current host for request
42+
* You can find this host in the __Metabase database > table Decidim Organizations > Host__
43+
44+
3. Install dependencies
45+
Run `bundle install`
46+
47+
4. Execute program
48+
`bundle exec main.rb -v`
49+
50+
> To prevent multiple authentication for each execution, program will store a valid token in '/token.private'. If file doesn't exist or token is deprecated, program will refresh it. This file is ignored by git.

lib/decidim_metabase.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
require_relative "decidim_metabase/object/filesystem_card"
1414
require_relative "decidim_metabase/object/database"
1515
require_relative "decidim_metabase/http_requests"
16+
require_relative "decidim_metabase/config"
1617
require_relative "decidim_metabase/query_interpreter"
1718
require_relative "decidim_metabase/topological_sort"
1819
require_relative "decidim_metabase/utils"
1920
require_relative "decidim_metabase/main"
2021

22+
# DecidimMetabase allows to create and manage Metabase cards
2123
module DecidimMetabase
2224
class Error < StandardError; end
2325

0 commit comments

Comments
 (0)