This repository has been archived by the owner on Dec 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmove-a-repo
executable file
·168 lines (141 loc) · 4.29 KB
/
move-a-repo
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
165
166
167
168
#!/bin/bash
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright 2019 Joyent, Inc.
#
#
# Call this to move a repo out of cr.joyent.us (Gerrit) and set it up in GitHub.
#
# This is a very *manual* script. It does *some* of the work, but often just
# provides some info and prompts to continue when you do the appropriate work.
#
# Prerequisites:
# - You probably need to be setup as trent has his tooling for now.
#
# Usage:
# ./bin/move-a-repo REPO-NAME
#
# Example:
# ./bin/move-a-repo joyent/sdc-manta
#
if [[ -n "$TRACE" ]]; then
export PS4='[\D{%FT%TZ}] ${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -o xtrace
fi
set -o errexit
set -o pipefail
VERSION=1.0.1
# ---- support functions
function fatal
{
echo "$0: fatal error: $*"
exit 1
}
function errexit
{
[[ $1 -ne 0 ]] || exit 0
fatal "error exit status $1"
}
function usage
{
echo "Usage: ./move-a-repo REPO-NAME"
}
# ---- mainline
trap 'errexit $?' EXIT
TOP=$(cd $(dirname $0)/../; pwd)
JSON=$(which json)
[[ -n "$JSON" ]] || fatal "'json' is not on your PATH"
while getopts "hy" opt
do
case "$opt" in
h)
usage
exit 0
;;
*)
usage
fatal "unknown option: -$opt"
exit 1
;;
esac
done
shift $(( $OPTIND - 1 ))
repoName=$1
[[ -n "$repoName" ]] || fatal "missing REPO-NAME argument"
[[ ${repoName} == joyent/* ]] \
|| fatal "cannot move '$repoName', it isn't under 'joyent/'"
# Working temp dir.
wrkDir=/var/tmp/move-a-repo-$(date '+%Y%m%dT%H%M%S')
mkdir $wrkDir
echo "# https://github.com/$repoName"
baseName=$(basename $repoName)
echo ""
echo "## Move open CRs for $repoName"
while true; do
ssh -o ConnectTimeout=5 cr gerrit query --format=JSON -- is:open project:$repoName \
| (grep -v '"type":"stats"' || true) \
| json -ga project url owner.email subject > $wrkDir/open-crs.txt
if [[ -s $wrkDir/open-crs.txt ]]; then
cat $wrkDir/open-crs.txt
echo ""
nOpenCrs=$(cat $wrkDir/open-crs.txt | wc -l | awk '{print $1}')
echo "There are $nOpenCrs open CRs for '$repoName'."
echo "Press 'Enter' when those are moved to PRs."
read </dev/tty
else
echo "(no open CRs)"
break
fi
done
echo ""
echo "## Update 'not use GitHub PRs' possible hits in README.md et al"
checkDir=$HOME/all/$baseName
if [[ ! -d $checkDir ]]; then
checkDir=$HOME/joy/$baseName
fi
if [[ ! -d $checkDir ]]; then
fatal "cannot find a clone of $repoName to check for Gerrit doc hits"
fi
echo "Checking '$checkDir' for candidate hits:"
(cd $checkDir && (rg -g '!deps' 'not use GitHub PRs' || true))
(cd $checkDir && (rg -g '!deps' 'cr.joyent.us' || true))
cat <<EOM
If there were candidate hits, please create a PR to update those:
cd ~/joy/$baseName
giddyup
vi README.md
git checkout -b TOOLS-2327
git ci -am "TOOLS-2327 move repos out of Gerrit (drop referral to Gerrit for CR)"
hub pull-request -p -o --no-edit
EOM
read -p "Print 'Enter' when done" </dev/tty
echo ""
echo "## Set GitHub repo branch protection (via 'jr gh set-branch-protection')"
jr gh set-branch-protection $baseName
read -p "Press 'Enter' to continue" </dev/tty
echo ""
echo "## Turn off merge commits"
echo "Opening 'https://github.com/$repoName/settings' so you can tweak settings"
open https://github.com/$repoName/settings
read -p "Press 'Enter' when done" </dev/tty
echo ""
echo "## Hide the repo in Gerrit"
open "https://cr.joyent.us/#/admin/projects/$repoName"
read -p "Print 'Enter' when done (set 'State: Hidden', then 'Save Changes')" </dev/tty
# Update jenkins job if relevant
jenkinsJob=$(jr list -l mg -Ho labels.mg $baseName)
if [[ -n $jenkinsJob ]]; then
echo ""
echo "## Update the Jenkins job (drop gerrit BRANCH ref, and cr.joyent.us repo)"
open "https://jenkins.joyent.us/job/$jenkinsJob/configure"
read -p "Press 'Enter' when done" </dev/tty
fi
#echo ""
#echo "## Add a comment to TOOLS-2327 that this repo is moved"
#open https://jira.joyent.us/browse/TOOLS-2327
#read -p "Press 'Enter' when done" </dev/tty
echo ""
echo "Successfully moved repo '$repoName' to https://github.com/$repoName"