Skip to content

Commit e9b4bc8

Browse files
committed
Get it working
1 parent a294c77 commit e9b4bc8

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

script/sync-translation

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,57 @@
55
# Usage: script/sync-upstream [remote]
66
#
77
# TODO:
8-
# - [x] create branch and merge upstream changes
9-
# - [x] get diff of changes to notable files
10-
# - [ ] open PR with checkboxes for changes to translatable files
118
# - [ ] handle merge conflicts with `git merge --continue`
12-
# - [ ] remove all the TODOs
139

1410
set -e
1511

1612
# If there's not an upstream remote, set it.
1713
if ! git remote show | grep -q upstream; then
18-
git remote add upstream https://github.com/github/open-source-guide.git
14+
git remote add upstream https://github.com/github/opensource.guide.git
1915
fi
2016

21-
git fetch upstream
22-
2317
REMOTE=${1:-"origin"}
18+
BASE="$REMOTE/gh-pages"
19+
# TODO: remove once script is working
20+
BASE=42b97f47d15422a27a7ac7acd1e3153efc98dc46 # randomly selected old commit for testing
21+
HEAD="upstream/gh-pages"
22+
23+
git fetch upstream
24+
git fetch $REMOTE
2425

25-
# BASE=$(git rev-parse $REMOTE/gh-pages)
26-
# TODO: replace v with ^
27-
BASE=0fc50236af4da7a5a339f9681f7c30634f415120 # randomly selected old commit for testing
28-
HEAD=$(git rev-parse upstream/i18n)
29-
BRANCH="sync-${HEAD:0:8}"
26+
BASE_SHA=$(git rev-parse $BASE)
27+
HEAD_SHA=$(git rev-parse $HEAD)
28+
BRANCH="sync-${HEAD_SHA:0:8}"
3029

3130
TRANSLATABLE_FILES="
32-
_articles/en-US
31+
_articles
3332
_data/locale/en-US.yml
3433
"
3534

3635
## Create a new branch and merge in the changes from upstream.
37-
# TODO: remove echos
38-
echo git checkout -b $BRANCH $BASE
39-
echo git merge --no-edit $HEAD
36+
echo "Creating branch $BRANCH based off $BASE"
37+
git checkout -B $BRANCH $BASE
38+
echo "Merging in latest changes from $HEAD"
39+
git merge -q --no-edit $HEAD
40+
git push $REMOTE $BRANCH
4041

41-
CHANGED_FILES=$(git diff --name-only $BASE $HEAD -- $TRANSLATABLE_FILES)
42+
CHANGED_FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA -- $TRANSLATABLE_FILES)
4243

43-
TEMPLATE="This pull request syncs changes from upstream.
44-
45-
[View changes](https://github.com/github/open-source-guide/compare/$BASE...$HEAD)
46-
47-
Check the changes in each of these files and update the translation accordingly:
44+
TEMPLATE="Sync changes from upstream
45+
\n
46+
\n[View changes](https://github.com/github/opensource.guide/compare/$BASE_SHA...$HEAD_SHA)
4847
"
4948

5049
if [ -z "$CHANGED_FILES" ]; then
51-
TEMPLATE="$TEMPLATE\nNo translatable files were changed upstream."
50+
TEMPLATE="$TEMPLATE\nNo files that need translation were changed upstream."
51+
else
52+
TEMPLATE="$TEMPLATE\nCheck the changes in each of these files and update the translation accordingly:\n"
53+
54+
for file in $CHANGED_FILES; do
55+
TEMPLATE="$TEMPLATE\n- [ ] \`$file\`"
56+
done
5257
fi
5358

54-
for file in $CHANGED_FILES; do
55-
TEMPLATE="$TEMPLATE\n- [ ] $file"
56-
done
59+
OWNER=$(git config --get remote.$REMOTE.url | sed -Ene 's#.*github.com[/:]([^/]*)/.*#\1#p')
5760

58-
# TODO: remove echos
59-
echo "$TEMPLATE"
60-
echo $TEMPLATE | echo hub pull-request -o -F - -h $BRANCH -b gh-pages
61+
echo $TEMPLATE | hub pull-request -o -F - -b $OWNER:gh-pages -h $OWNER:$BRANCH

0 commit comments

Comments
 (0)