]> BookStack Code Mirror - devops/commitdiff
Added script to format crowdin top member report
authorDan Brown <redacted>
Sun, 20 Sep 2020 08:37:55 +0000 (09:37 +0100)
committerDan Brown <redacted>
Sun, 20 Sep 2020 08:37:55 +0000 (09:37 +0100)
Formats to JSON. Used to create the attribution details
to be included in the blogposts.

meta-scripts/bookstack-format-crowdin-members-report [new file with mode: 0644]

diff --git a/meta-scripts/bookstack-format-crowdin-members-report b/meta-scripts/bookstack-format-crowdin-members-report
new file mode 100644 (file)
index 0000000..58778de
--- /dev/null
@@ -0,0 +1,43 @@
+#!/usr/bin/env php
+<?php
+
+function error($text) {
+       echo $text . "\n";
+       exit(1);
+}
+
+function output($text) {
+    echo $text . "\n";
+}
+
+
+// Check a file path is provided
+if (count($argv) < 2) {
+       error("Path to JSON report required");
+}
+
+// Check file path exists
+$reportFile = realpath($argv[1]);
+if (!file_exists($reportFile)) {
+       error("JSON report file not found at {$reportFile}");
+}
+
+$reportContent = file_get_contents($reportFile);
+$report = json_decode($reportContent, true);
+if (is_null($report)) {
+       error("Could not read JSON content from file {$reportFile}");
+}
+
+foreach ($report['data'] as $userData) {
+       $fullName = $userData['user']['fullName'];
+       $languages = array_map(function($lang) {
+               return '*' . $lang['name'] . '*';
+       }, $userData['languages']);
+
+       if (count($languages) === 0) {
+               continue;
+       }
+
+       $langString = implode(", ", $languages);
+       output("* {$fullName} - {$langString}");
+}
\ No newline at end of file