|
5 | 5 | # Usage: script/sync-upstream [remote] |
6 | 6 | # |
7 | 7 | # 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 |
11 | 8 | # - [ ] handle merge conflicts with `git merge --continue` |
12 | | -# - [ ] remove all the TODOs |
13 | 9 |
|
14 | 10 | set -e |
15 | 11 |
|
16 | 12 | # If there's not an upstream remote, set it. |
17 | 13 | 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 |
19 | 15 | fi |
20 | 16 |
|
21 | | -git fetch upstream |
22 | | - |
23 | 17 | 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 |
24 | 25 |
|
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}" |
30 | 29 |
|
31 | 30 | TRANSLATABLE_FILES=" |
32 | | - _articles/en-US |
| 31 | + _articles |
33 | 32 | _data/locale/en-US.yml |
34 | 33 | " |
35 | 34 |
|
36 | 35 | ## 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 |
40 | 41 |
|
41 | | -CHANGED_FILES=$(git diff --name-only $BASE $HEAD -- $TRANSLATABLE_FILES) |
| 42 | +CHANGED_FILES=$(git diff --name-only $BASE_SHA $HEAD_SHA -- $TRANSLATABLE_FILES) |
42 | 43 |
|
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) |
48 | 47 | " |
49 | 48 |
|
50 | 49 | 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 |
52 | 57 | fi |
53 | 58 |
|
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') |
57 | 60 |
|
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