-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrm-cr
executable file
·153 lines (128 loc) · 3.74 KB
/
rm-cr
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
#!/bin/bash
SHELL=/bin/bash
set -e
. $(dirname "$0")/utility.sh
usage_message=$(cat <<EOF
usage: rm-cr OPTIONS...
Removes change from project's sqitch.plan and moves SQL files to ./deprecated.
If no project is specified, then all projects are searched for change.
If change is not found, no action is taken.
--change Change to remove.
--project NAME Project change belongs to.
--no-update-plan Don't remove change from sqitch.plan.
Examples:
bin/rm-cr --change "20231201_XYZ" --project "project-name"
bin/rm-cr --change "20231201_XYZ" --no-update-plan
EOF
)
function usage() {
echo "$usage_message"
}
g_change=
g_project=
g_update_plan=YES
g_note=
g_no_archive=
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--change|-c)
g_change="$2";
shift 2;
;;
--project|-p)
g_project="$2";
shift 2;
;;
--note|-n)
g_note="$2";
shift 2;
;;
--no-update-plan|-u)
g_update_plan="NO";
shift;
;;
--no-archive|-a)
g_no_archive="YES";
shift;
;;
--help|-h)
usage
exit 0
;;
--*)
echo "error: invalid option $1"
usage
exit 64
;;
*)
POSITIONAL+=("$1")
shift
;;
esac
done
set -- "${POSITIONAL[@]}"
if [ -z "$g_change" ]; then
g_change="${POSITIONAL[@]}"
if [ -z "$g_change" ]; then
echo "error: missing required option --change"
exit 64
fi
fi
if [ -z "$g_project" ]; then
g_projects=$(find . -name "sqitch.plan" -type f -exec dirname \{\} \;)
else
# g_projects=$(echo "$g_projects" | tr "," "\n")
g_projects="$g_project"
fi
function delete_change() {
local project="$1"
local change="$2"
if [ ! -d "$project" ]; then
echo "error: project $project does not exist!"
exit 64
fi
if [ ! -f "$project/deploy/${g_change}.sql" ]; then
echo "error: change $change does not exist in project $project!"
exit 64
fi
for type in deploy revert verify ; do
rm -f "$project/$type/${change}.sql"
done
grep -v -e "$change" "$project/sqitch.plan" > "$project/sqitch.plan.tmp"
mv -f "$project/sqitch.plan.tmp" "$project/sqitch.plan"
echo "info: change $change removed from project $project!"
exit 0
}
if [ "$g_no_archive" == "YES" ]; then
delete_change "$g_project" "$g_change"
exit 0
fi
for project in $g_projects; do
if [ -f "$project/deploy/${g_change}.sql" ]; then
mkdir -p $project/archive/deploy $project/archive/revert $project/archive/verify
for type in deploy revert verify ; do
mv "$project/$type/${g_change}.sql" "$project/archive/$type/${g_change}.sql"
done
if [ -d "$project/deploy/${g_change}" ]; then
mv "$project/deploy/${g_change}" "$project/archive/deploy/"
fi
tag=$(get_change_tag "$project" "$g_change")
issue_id=$(get_cr_issue_id "$project" "$g_change")
echo "$tag" >> "$project/archive/sqitch.history"
grep -e "$g_change" "$project/sqitch.plan" >> "$project/archive/sqitch.history"
grep -v -e "$g_change" "$project/sqitch.plan" > "$project/sqitch.plan.tmp"
mv -f "$project/sqitch.plan.tmp" "$project/sqitch.plan"
if [ ! -z "$issue_id" ]; then
echo "Archiving issue $issue_id"
gh issue close $issue_id
gh issue comment -b "This CR has been archived.<p>${g_note}" $issue_id
fi
echo "Change $project/$g_change moved to ./$project/archive"
exit 0
fi
done
echo "Change $g_change not found!"
exit 64