loading up the forgejo repo on tangled to test page performance
at forgejo 7.0 kB view raw
1#!/bin/bash 2# Copyright twenty-panda <twenty-panda@posteo.com> 3# SPDX-License-Identifier: MIT 4 5label_worth=worth 6label_bug=bug 7label_feature=feature 8label_ui=forgejo/ui 9label_breaking=breaking 10label_security=security 11label_localization=forgejo/i18n 12 13payload=$(mktemp) 14pr=$(mktemp) 15trap "rm $payload $pr" EXIT 16 17function test_main() { 18 set -ex 19 PS4='${BASH_SOURCE[0]}:$LINENO: ${FUNCNAME[0]}: ' 20 21 test_payload_labels $label_worth $label_breaking $label_security $label_bug 22 test "$(categorize)" = 'AA Breaking security bug fixes' 23 24 test_payload_labels $label_worth $label_security $label_bug 25 test "$(categorize)" = 'AB Security bug fixes' 26 27 test_payload_labels $label_worth $label_breaking $label_security $label_feature 28 test "$(categorize)" = 'AC Breaking security features' 29 30 test_payload_labels $label_worth $label_security $label_feature 31 test "$(categorize)" = 'AD Security features' 32 33 test_payload_labels $label_worth $label_security 34 test "$(categorize)" = 'ZA Security changes without a feature or bug label' 35 36 test_payload_labels $label_worth $label_breaking $label_feature 37 test "$(categorize)" = 'BA Breaking features' 38 39 test_payload_labels $label_worth $label_breaking $label_bug 40 test "$(categorize)" = 'BB Breaking bug fixes' 41 42 test_payload_labels $label_worth $label_breaking 43 test "$(categorize)" = 'ZB Breaking changes without a feature or bug label' 44 45 test_payload_labels $label_worth $label_ui $label_feature 46 test "$(categorize)" = 'CA User Interface features' 47 48 test_payload_labels $label_worth $label_ui $label_bug 49 test "$(categorize)" = 'CB User Interface bug fixes' 50 51 test_payload_labels $label_worth $label_ui 52 test "$(categorize)" = 'ZC User Interface changes without a feature or bug label' 53 54 test_payload_labels $label_worth $label_localization 55 test "$(categorize)" = 'DA Localization' 56 57 test_payload_labels $label_worth $label_feature 58 test "$(categorize)" = 'EA Features' 59 60 test_payload_labels $label_worth $label_bug 61 test "$(categorize)" = 'EB Bug fixes' 62 63 test_payload_labels $label_worth 64 test "$(categorize)" = 'ZE Other changes without a feature or bug label' 65 66 test_payload_labels 67 test "$(categorize)" = 'ZF Included for completeness but not worth a release note' 68 69 test_payload_draft "fix(security)!: breaking security bug fix" 70 test "$(categorize)" = 'AA Breaking security bug fixes' 71 72 test_payload_draft "fix(security): security bug fix" 73 test "$(categorize)" = 'AB Security bug fixes' 74 75 test_payload_draft "feat!: breaking feature" 76 test "$(categorize)" = 'BA Breaking features' 77 78 test_payload_draft "fix!: breaking bug fix" 79 test "$(categorize)" = 'BB Breaking bug fixes' 80 81 test_payload_draft "feat: feature" 82 test "$(categorize)" = 'EA Features' 83 84 test_payload_draft "fix: bug fix" 85 test "$(categorize)" = 'EB Bug fixes' 86 87 test_payload_draft "something with no prefix" 88 test "$(categorize)" = 'ZE Other changes without a feature or bug label' 89} 90 91function main() { 92 cat >$payload 93 categorize 94} 95 96function categorize() { 97 # 98 # If this is a backport, refer to the original PR to figure 99 # out the classification. 100 # 101 if $(jq --raw-output .IsBackportedFrom <$payload); then 102 jq --raw-output '.BackportedFrom[0]' <$payload >$pr 103 else 104 jq --raw-output '.Pr' <$payload >$pr 105 fi 106 107 labels=$(jq --raw-output '.labels[].name' <$pr) 108 109 # 110 # Was this PR labeled `worth a release note`? 111 # 112 if echo "$labels" | grep --quiet $label_worth; then 113 worth=true 114 else 115 worth=false 116 fi 117 118 # 119 # If there was no release-notes/N.md file and it is not 120 # worth a release note, just forget about it. 121 # 122 if test -z "$(jq --raw-output .Draft <$payload)"; then 123 if ! $worth; then 124 echo -n ZF Included for completeness but not worth a release note 125 exit 0 126 fi 127 fi 128 129 is_ui=false 130 is_bug=false 131 is_feature=false 132 is_localization=false 133 is_breaking=false 134 is_security=false 135 136 # 137 # first try to figure out the category from the labels 138 # 139 case "$labels" in 140 *$label_bug*) 141 is_bug=true 142 ;; 143 *$label_feature*) 144 is_feature=true 145 ;; 146 *$label_localization*) 147 is_localization=true 148 ;; 149 esac 150 151 case "$labels" in 152 *$label_security*) 153 is_security=true 154 ;; 155 esac 156 157 case "$labels" in 158 *$label_breaking*) 159 is_breaking=true 160 ;; 161 esac 162 163 case "$labels" in 164 *$label_ui*) 165 is_ui=true 166 ;; 167 esac 168 169 # 170 # then try the prefix of the release note 171 # 172 if ! $is_bug && ! $is_feature; then 173 draft="$(jq --raw-output .Draft <$payload)" 174 case "$draft" in 175 fix\(security\)!:*) 176 is_bug=true 177 is_breaking=true 178 is_security=true 179 ;; 180 fix\(security\):*) 181 is_bug=true 182 is_security=true 183 ;; 184 fix!:*) 185 is_bug=true 186 is_breaking=true 187 ;; 188 fix:*) 189 is_bug=true 190 ;; 191 feat!:*) 192 is_feature=true 193 is_breaking=true 194 ;; 195 feat:*) 196 is_feature=true 197 ;; 198 esac 199 fi 200 201 if $is_bug; then 202 if $(jq --raw-output .IsBackportedTo <$payload); then 203 # 204 # if it has been backported, it was in the release notes of an older stable release 205 # and does not need to be in this more recent release notes 206 # 207 echo -n ZG Already announced in the release notes of an older stable release 208 exit 0 209 fi 210 fi 211 212 if $is_security; then 213 if $is_bug; then 214 if $is_breaking; then 215 echo -n AA Breaking security bug fixes 216 else 217 echo -n AB Security bug fixes 218 fi 219 elif $is_feature; then 220 if $is_breaking; then 221 echo -n AC Breaking security features 222 else 223 echo -n AD Security features 224 fi 225 else 226 echo -n ZA Security changes without a feature or bug label 227 fi 228 elif $is_breaking; then 229 if $is_feature; then 230 echo -n BA Breaking features 231 elif $is_bug; then 232 echo -n BB Breaking bug fixes 233 else 234 echo -n ZB Breaking changes without a feature or bug label 235 fi 236 elif $is_ui; then 237 if $is_feature; then 238 echo -n CA User Interface features 239 elif $is_bug; then 240 echo -n CB User Interface bug fixes 241 else 242 echo -n ZC User Interface changes without a feature or bug label 243 fi 244 elif $is_localization; then 245 echo -n DA Localization 246 else 247 if $is_feature; then 248 echo -n EA Features 249 elif $is_bug; then 250 echo -n EB Bug fixes 251 else 252 echo -n ZE Other changes without a feature or bug label 253 fi 254 fi 255} 256 257function test_payload_labels() { 258 local label1="$1" 259 local label2="$2" 260 local label3="$3" 261 local label4="$4" 262 263 cat >$payload <<EOF 264{ 265 "Pr": { 266 "labels": [ 267 { 268 "name": "$label1" 269 }, 270 { 271 "name": "$label2" 272 }, 273 { 274 "name": "$label3" 275 }, 276 { 277 "name": "$label4" 278 } 279 ] 280 }, 281 "IsBackportedFrom": false, 282 "Draft": "" 283} 284EOF 285} 286 287function test_payload_draft() { 288 local draft="$1" 289 290 cat >$payload <<EOF 291{ 292 "Pr": { 293 "labels": [ 294 { 295 "name": "$label_worth" 296 } 297 ] 298 }, 299 "IsBackportedFrom": false, 300 "Draft": "$draft" 301} 302EOF 303} 304 305"${@:-main}"