-
Notifications
You must be signed in to change notification settings - Fork 0
/
feature.sh
executable file
·164 lines (139 loc) · 3.73 KB
/
feature.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash -e
# @installable
MYSELF="$(readlink -f "$0")"
MYDIR="${MYSELF%/*}"
ME=$(basename $MYSELF)
source $MYDIR/env
[[ -f $LOCAL_ENV ]] && source $LOCAL_ENV
source $MYDIR/log.sh
source $MYDIR/db.sh
if [[ ! -n "$(curr_branch)" ]]; then
err "you have to be inside the repository directory"
branchd="$(db CURR_FEATURE_DIR)"
if [[ -d "$branchd" ]]; then
info "maybe you want to go to $branchd ?"
fi
exit 1
fi
if [[ -z "$(project_url)" ]]; then
err "coudn't determine project url, check if you are inside a git project"
exit 1
fi
if [[ "$1" != '-'* ]]; then
# name was passed directly as first arg with no prefix
name="$1"; shift
fi
project_id="$(db CURR_PROJECT_ID)"
literal_name=false
# sync with target branch before creating the new one
sync=true
while test $# -gt 0
do
case "$1" in
--name|-n)
shift
name="$1"
;;
--literal)
literal_name=true
;;
--sync-later|--no-sync)
sync=false
;;
--project|-p)
shift
# name_or_id="$1"
# project_id=$(prompt_project_id "$name_or_id")
project_id="$1"
;;
--like)
shift
lid=$1
task=$($MYDIR/runrun.sh GET "tasks/$lid")
if [[ ! -n "$task" ]]; then
err "task #$lid not found"
exit 1
fi
project_id=$(echo "$task" | $MYDIR/jprop.sh "['project_id']")
;;
--estimate)
shift
estimate="$1"
;;
-*)
echo "bad option '$1'"
exit 1
;;
esac
shift
done
if [[ -z "$project_id" ]]; then
project_id=1
fi
if [[ $literal_name != true ]]; then
name="$FEATURE_PREFIX/$(safe_name "$name")"
fi
if [[ "$RR_ENABLED" == true ]]; then
project_name="$($MYDIR/rr-find-project.sh $project_id)"
if [[ -z "$project_name" ]]; then
err "problem finding project"
exit 1
fi
else
project_name=$($MYDIR/psql.sh "select name from projects where id = $project_id")
fi
# TODO
#if [[ -z "$estimate" ]]; then
# info "no time estimate found, enter one [8h]"
# read estimate
#fi
TARGET_BRANCH=$(curr_branch)
if [[ "$sync" == true ]]; then
info "switching to $TARGET_BRANCH and syncing..."
git checkout $TARGET_BRANCH
git pull
fi
if [[ $(git branch | grep -c $name) -eq 1 ]]; then
info "feature already exists. switching to it..."
db CURR_FEATURE "$name"
db CURR_FEATURE_DIR "$(repo_root)"
git checkout $name
git merge $TARGET_BRANCH
git branch
$MYDIR/play.sh "$name"
exit 0
fi
info "will start '$name' on project '$project_name', with target branch '$TARGET_BRANCH'"
info "project URL: $(project_url)"
echo "<enter> to proceed, CTRL+C to abort"
read anyKey
if [[ "$(curr_branch)" != "$name" ]]; then
info "creating git branch..."
git checkout -b "$name"
db CURR_FEATURE "$name"
db CURR_FEATURE_DIR "$(repo_root)"
db CURR_FEATURE_TARGET_BRANCH "$TARGET_BRANCH"
else
info "branch already created..."
fi
if [[ $REMOTE_FEATURES == true ]]; then
info "pushing local branch to remote..."
git push -u origin $name
git branch --set-upstream-to=origin/$name $name
fi
project_url="$(project_url)"
if [[ "$RR_ENABLED" == true ]]; then
description="$project_url/-/tree/$name"
if [[ "$name" == *fix* ]]; then
issue_id=$(echo $name | cut -d'-' -f2)
if [[ $(nan $issue_id) == true ]]; then
err "couldn't determine issue id from feature name: $name"
fi
description="* $description * $project_url/-/issues/$issue_id"
fi
$MYDIR/rr-new-task.sh "$name" -p $project_id --description "$description"
info "additional project info on runrun..."
$MYDIR/rr-comment.sh "started a new feature on $(project_url)"
else
$MYDIR/play.sh "$name"
fi