-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost-commit.smartling.sh
executable file
·86 lines (72 loc) · 2.74 KB
/
post-commit.smartling.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh
#
# svn post-commit hook to upload your localization file to
# Smartling and get email notification
#
# == INSTALLATION ==
#
# Copy this file into your svn hooks directory for the repo that you want to use
# this post-commit script in (eg. /path/to/svn/somerepo/hooks/) and add a line to
# post-commit and call it with the following:
#
# /path/to/svn/repo/hooks/post-commit.smartling.sh "$REPOS" "$REV"
#
# (you should have $REPOS and $REV defined already in the post-commit script)
#
SMARTLING_API_KEY="YOUR_SMARTLING_API_KEY"
SMARTLING_PROJECT_ID="YOUR_SMARTLINK_PROJECT_KEY"
SMARTLING_FILE_URI="YOUR_SMARTLINK_FILE_URI"
# email recipients comma-separated
EMAIL_RECIPIENTS="[email protected],[email protected]"
# path to your language file
SOURCE_FILE_PATH="file:///svn/repos/somerepo/trunk/i18n/en_US.xml"
# file path to match the file we are looking for. A match means we will
# upload $SOURCE_FILE_PATH to Smartling. Note that is path is reported by
# svn and will be different than what is set in $SOURCE_FILE_PATH. Simply
# matching the file name will work if you have no other similarly named
# files in your repo, but it would be more foolproof if you specify something
# more unique like a specific directory path
CHANGED_FILE_MATCH_PATH="trunk/somerepo/i18n/en_US.xml"
REPOS="$1"
REV="$2"
TIMESTAMP=`/bin/date +%Y%m%d-%H%M`
EXPORT_FILE="en_US-$TIMESTAMP.xml"
EXPORT_FILE_PATH="/tmp/$EXPORT_FILE"
SMARTLING_UPLOAD_PATH="file=@$EXPORT_FILE_PATH;type=text/plain"
CHANGED_FILES=`/usr/bin/svnlook changed -r "$REV" "$REPOS"`
#get the log message
COMMIT_MESSAGE=`/usr/bin/svnlook log -r "$REV" "$REPOS"`
#get the author
COMMIT_AUTHOR=`/usr/bin/svnlook author -r "$REV" "$REPOS"`
# uncomment for testing on the command line
#echo ""
#echo "###"
#echo "Time: $TIMESTAMP"
#echo "Changed files for $REV:"
#echo $CHANGED_FILES
#echo "---"
#echo "author: $COMMIT_AUTHOR"
#echo "---"
#echo "message: $COMMIT_MESSAGE"
#echo "---"
#echo "export path: $EXPORT_FILE_PATH"
#echo "SMARTLING_UPLOAD_PATH: $SMARTLING_UPLOAD_PATH"
#echo "###"
if [[ "$CHANGED_FILES" =~ $CHANGED_FILE_MATCH_PATH ]]
then
/usr/bin/svn export -q --non-interactive --trust-server-cert $SOURCE_FILE_PATH $EXPORT_FILE_PATH
API_RESPONSE=$(/usr/bin/curl -ksS\
-F "file=@$EXPORT_FILE_PATH;type=text/plain"\
-F "apiKey=$SMARTLING_API_KEY"\
-F "projectId=$SMARTLING_PROJECT_ID"\
-F "fileType=xliff"\
-F "fileUri=$SMARTLING_FILE_URI"\
"https://api.smartling.com/v1/file/upload")
#echo "APL_RESPONSE: $API_RESPONSE"
# notify via email
BODY="\n\n[SVN REVISION]\n$REV\n\n\
[AUTHOR]\n$COMMIT_AUTHOR\n\n\
[COMMIT MESSAGE]\n$COMMIT_MESSAGE\n\n\
[Smartling API RESPONSE]\n$API_RESPONSE"
echo -e $BODY | /bin/mail -s "[svn post-commit] upload to Smartling" $EMAIL_RECIPIENTS
fi