forked from BookStackApp/devops
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added script to format crowdin top member report
Formats to JSON. Used to create the attribution details to be included in the blogposts.
- Loading branch information
1 parent
33ff86a
commit e00e611
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}"); | ||
} |