-
Notifications
You must be signed in to change notification settings - Fork 0
/
enum_refactor.sh
58 lines (51 loc) · 2.15 KB
/
enum_refactor.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
#!/bin/bash
for filename in homeassistant/components/$1; do
filename=$(basename -- "$filename")
echo "Processing $filename..."
branchname="refactor_enum_${filename}_tests"
echo " Using branch name $branchname..."
if [ `git --no-pager branch --list $branchname` ]
then
echo "Branch name $branchname already exists, skipping."
continue
fi
python3 script/enum_refactor.py $filename || { echo 'Command failed' ; exit 1; }
if [ ! -d "tests/components/$filename" ]
then
echo " No tests for $filename, skipping."
continue
fi
COUNT=$(git --no-pager diff --stat tests/components/${filename}/ | grep "changed" | sed 's@^[^0-9]*\([0-9]\+\).*@\1@')
if test -z "$COUNT"
then
echo " No changes for $filename"
continue
else
echo "$COUNT Changes for $filename"
fi
pytest tests/components/$filename
if [ "$?" -ne 0 ]; then
echo " Some tests failed. Stopping."
break
fi
read -p " Examine the diff. press [enter] to continue with commit and push, <ctrl>-c to stop. If you make any edits, isort and restart this script."
git stash || { echo 'Command failed' ; exit 1; }
git checkout -b $branchname || { echo 'Command failed' ; exit 1; }
git stash pop || { echo 'Command failed' ; exit 1; }
COUNT=$(git --no-pager diff --stat homeassistant/components/${filename}/ | grep "changed" | sed 's@^[^0-9]*\([0-9]\+\).*@\1@')
if test -z "$COUNT"
then
echo " No changes to main component for $filename"
else
echo " CHANGES for main component $filename"
git add homeassistant/components/${filename}/* || { echo 'Command failed' ; exit 1; }
git commit -m"Use new enums in ${filename}" || { echo 'Command failed' ; exit 1; }
fi
git add tests/components/${filename}/* || { echo 'Command failed' ; exit 1; }
git commit -m"Use new enums in ${filename} tests"
git push --set-upstream origin $branchname || { echo 'Command failed' ; exit 1; }
git checkout dev || { echo 'Command failed' ; exit 1; }
break
done
echo Finished, used 'git checkout -- .' to revert changed files
#git checkout -- .