forked from adobe/brackets
-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to pull string changes from thimble on build
- Loading branch information
Gideon Thomas
committed
Mar 8, 2016
1 parent
bcbc027
commit de0d398
Showing
4 changed files
with
95 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
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
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,26 @@ | ||
/*global process */ | ||
|
||
var request = require("request"); | ||
|
||
request({ | ||
uri: "https://api.github.com/repos/mozilla/brackets/contents/" + process.argv[2], | ||
method: "GET", | ||
headers: { | ||
"User-Agent": "gideonthomas" | ||
} | ||
}, function(err, res, body) { | ||
"use strict"; | ||
|
||
if(!err && res.statusCode === 200) { | ||
try { | ||
var content = JSON.parse(body); | ||
process.stdout.write(content.sha); | ||
} catch(e) { | ||
console.error("Failed to convert response to JSON with: ", e); | ||
process.exit(1); | ||
} | ||
} else { | ||
console.error("Failed to get file contents with: ", err || body); | ||
process.exit(1); | ||
} | ||
}); |
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,65 @@ | ||
#!/bin/bash | ||
set -e # exit with nonzero exit code if anything fails | ||
|
||
if [ "$UPDATE_STRINGS" == "true" ] | ||
then | ||
# Get the latest tarball of Thimble and extract the locales/ directory | ||
curl -L https://api.github.com/repos/mozilla/thimble.mozilla.org/tarball/master | \ | ||
tar -xv --include '/locales/' --strip-components 1 | ||
|
||
# Temporarily stage any changes between the thimble locales folder and the | ||
# Brackets locales folder so that we can diff them | ||
git add locales | ||
|
||
# Get the list of files that are new or that were changed | ||
CHANGED="$(git diff --cached --name-only --diff-filter=M locales)" | ||
ADDED="$(git diff --cached --name-only --diff-filter=A locales)" | ||
|
||
for CHANGED_FILE in $CHANGED | ||
do | ||
# Get the SHA of the existing version of the locale file in Brackets | ||
sha="$(node scripts/get-file-sha.js $CHANGED_FILE)" | ||
# Get the locale that was changed | ||
locale="$(echo $CHANGED_FILE | sed -e 's/locales\///g' -e 's/\/editor\.properties//g')" | ||
# Base64 encode the new file's contents | ||
content="$(base64 $CHANGED_FILE)" | ||
body="{ \ | ||
\"message\": \"Thimble-L10N - Update strings for $locale\", \ | ||
\"content\": \"$content\", \ | ||
\"sha\": \"$sha\" \ | ||
}" | ||
|
||
# Commit the change to the repo | ||
curl --location-trusted -X PUT \ | ||
-H "Content-Type: application/json" \ | ||
-H "Accept: application/json" \ | ||
-H "Authorization: token $GH_TOKEN" \ | ||
-d "$body" | ||
"https://api.github.com/repos/mozilla/brackets/contents/$CHANGED_FILE" | ||
|
||
echo "Successfully updated strings for $locale" | ||
done | ||
|
||
for ADDED_FILE in $ADDED | ||
do | ||
# Get the locale that was changed | ||
locale="$(echo $ADDED_FILE | sed -e 's/locales\///g' -e 's/\/editor\.properties//g')" | ||
# Base64 encode the new file's contents | ||
content="$(base64 $ADDED_FILE)" | ||
body="{ \ | ||
\"message\": \"Thimble-L10N - Add strings for $locale\", \ | ||
\"content\": \"$content\", \ | ||
}" | ||
|
||
# Commit the new file to the repo | ||
curl -X PUT \ | ||
-H "Content-Type: application/json" \ | ||
-H "Accept: application/json" \ | ||
-H "Authorization: token $GH_TOKEN" \ | ||
-d "$body" | ||
"https://api.github.com/repos/mozilla/brackets/contents/$ADDED_FILE" | ||
echo "Successfully added strings for $locale" | ||
done | ||
|
||
git reset locales | ||
fi |