Set lock_path correctly.
[openstack-build/neutron-build.git] / tools / abandon_old_reviews.sh
1 #!/usr/bin/env bash
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14 #
15 # WARNING!
16 # Please do not run this script without talking to the Neutron PTL. Auto
17 # abandoning people's changes is a good thing, but must be done with care.
18 #
19 # before you run this modify your .ssh/config to create a
20 # review.openstack.org entry:
21 #
22 #   Host review.openstack.org
23 #   User <yourgerritusername>
24 #   Port 29418
25 #
26
27 # Note: due to gerrit bug somewhere, this double posts messages. :(
28
29 # first purge the all reviews that are more than 4w old and blocked by a core -2
30
31 if [ "$1" = "--dry-run" ]; then
32     echo "Enabling dry run mode"
33     DRY_RUN=1
34 else
35     DRY_RUN=0
36 fi
37
38 set -o errexit
39
40 function abandon_review {
41     local gitid=$1
42     shift
43     local msg=$@
44     # echo ssh review.openstack.org gerrit review $gitid --abandon --message \"$msg\"
45     if [ $DRY_RUN -eq 1 ]; then
46         echo "Would abandon $gitid"
47     else
48         echo "Abandoning $gitid"
49         ssh review.openstack.org gerrit review $gitid --abandon --message \"$msg\"
50     fi
51 }
52
53 PROJECTS="(project:openstack/neutron OR project:openstack/neutron-fwaas OR \
54            project:openstack/neutron-lbaas OR project:openstack/neutron-vpnaas OR \
55            project:openstack/python-neutronclient OR project:openstack/neutron-specs)"
56
57 blocked_reviews=$(ssh review.openstack.org "gerrit query --current-patch-set --format json $PROJECTS status:open age:4w label:Code-Review<=-2" | jq .currentPatchSet.revision | grep -v null | sed 's/"//g')
58
59 blocked_msg=$(cat <<EOF
60
61 This review is > 4 weeks without comment and currently blocked by a
62 core reviewer with a -2. We are abandoning this for now.
63
64 Feel free to reactivate the review by pressing the restore button and
65 contacting the reviewer with the -2 on this review to ensure you
66 address their concerns.
67
68 EOF
69 )
70
71 # For testing, put in a git rev of something you own and uncomment
72 # blocked_reviews="b6c4218ae4d75b86c33fa3d37c27bc23b46b6f0f"
73
74 for review in $blocked_reviews; do
75     # echo ssh review.openstack.org gerrit review $review --abandon --message \"$msg\"
76     echo "Blocked review $review"
77     abandon_review $review $blocked_msg
78 done
79
80 # then purge all the reviews that are > 4w with no changes and Jenkins has -1ed
81
82 failing_reviews=$(ssh review.openstack.org "gerrit query  --current-patch-set --format json $PROJECTS status:open age:4w NOT label:Verified>=1,jenkins" | jq .currentPatchSet.revision | grep -v null | sed 's/"//g')
83
84 failing_msg=$(cat <<EOF
85
86 This review is > 4 weeks without comment, and failed Jenkins the last
87 time it was checked. We are abandoning this for now.
88
89 Feel free to reactivate the review by pressing the restore button and
90 leaving a 'recheck' comment to get fresh test results.
91
92 EOF
93 )
94
95 for review in $failing_reviews; do
96     echo "Failing review $review"
97     abandon_review $review $failing_msg
98 done