@@ -197,10 +197,10 @@ gitea.exists() { split_repo "$1" && auth api 200 404 "repos/$REPLY" ; }
197
197
198
198
~~~shell
199
199
$ gitea exists foo/bar </dev/null; echo [$? ]
200
- curl --silent --write-out %\{http_code\} --output /dev/null -H Authorization:\ token\ EXAMPLE_TOKEN https://example.com/gitea/api/v1/repos/foo/bar
200
+ curl --silent --write-out \\ n %\{http_code\} -H Authorization:\ token\ EXAMPLE_TOKEN https://example.com/gitea/api/v1/repos/foo/bar
201
201
[0]
202
202
$ curl_status=404 gitea exists foo/bar </dev/null; echo [$? ]
203
- curl --silent --write-out %\{http_code\} --output /dev/null -H Authorization:\ token\ EXAMPLE_TOKEN https://example.com/gitea/api/v1/repos/foo/bar
203
+ curl --silent --write-out \\ n %\{http_code\} -H Authorization:\ token\ EXAMPLE_TOKEN https://example.com/gitea/api/v1/repos/foo/bar
204
204
[1]
205
205
~~~
206
206
@@ -214,11 +214,11 @@ gitea.delete() { split_repo "$1" && auth api 204 "" "/repos/$REPLY" -X DELETE; }
214
214
215
215
~~~shell
216
216
$ gitea delete foo/bar </dev/null
217
- curl --silent --write-out %\{http_code\} --output /dev/null -X DELETE -H Authorization:\ token\ EXAMPLE_TOKEN https://example.com/gitea/api/v1/repos/foo/bar
217
+ curl --silent --write-out \\ n %\{http_code\} -X DELETE -H Authorization:\ token\ EXAMPLE_TOKEN https://example.com/gitea/api/v1/repos/foo/bar
218
218
Failure: HTTP code 200 (expected 204)
219
219
[70]
220
220
$ curl_status=204 gitea delete foo/bar </dev/null; echo [$? ]
221
- curl --silent --write-out %\{http_code\} --output /dev/null -X DELETE -H Authorization:\ token\ EXAMPLE_TOKEN https://example.com/gitea/api/v1/repos/foo/bar
221
+ curl --silent --write-out \\ n %\{http_code\} -X DELETE -H Authorization:\ token\ EXAMPLE_TOKEN https://example.com/gitea/api/v1/repos/foo/bar
222
222
[0]
223
223
~~~
224
224
@@ -235,7 +235,7 @@ gitea.deploy-key() {
235
235
236
236
~~~shell
237
237
$ curl_status=201 gitea deploy-key foo/bar baz spam false
238
- curl --silent --write-out %\{http_code\} --output /dev/null -X POST -H Content-Type:\ application/json -d @- -H Authorization:\ token\ EXAMPLE_TOKEN https://example.com/gitea/api/v1/repos/foo/bar/keys
238
+ curl --silent --write-out \\ n %\{http_code\} -X POST -H Content-Type:\ application/json -d @- -H Authorization:\ token\ EXAMPLE_TOKEN https://example.com/gitea/api/v1/repos/foo/bar/keys
239
239
{
240
240
" title" : " baz" ,
241
241
" key" : " spam" ,
@@ -263,7 +263,7 @@ gitea.new() {
263
263
# Defaults apply before command line; default API url is /org/ORGNAME/repos
264
264
$ export GIT_AUTHOR_NAME=" PJ Eby
" EMAIL=" [email protected] "
265
265
$ gitea --private new biz/baz description whatever
266
- curl --silent --write-out %\{http_code\} --output /dev/null -X POST -H Content-Type:\ application/json -d @- https://example.com/gitea/api/v1/org/biz/repos\?token=EXAMPLE_TOKEN
266
+ curl --silent --write-out \\ n %\{http_code\} -X POST -H Content-Type:\ application/json -d @- https://example.com/gitea/api/v1/org/biz/repos\?token=EXAMPLE_TOKEN
267
267
{
268
268
" name" : " baz" ,
269
269
" private" : true,
@@ -273,7 +273,7 @@ gitea.new() {
273
273
# When the repo is the current user, the API url is /user/repos
274
274
$ GITEA_CREATE=(private= true)
275
275
$ gitea --public -d something new some_user/spam
276
- curl --silent --write-out %\{http_code\} --output /dev/null -X POST -H Content-Type:\ application/json -d @- https://example.com/gitea/api/v1/user/repos\?token=EXAMPLE_TOKEN
276
+ curl --silent --write-out \\ n %\{http_code\} -X POST -H Content-Type:\ application/json -d @- https://example.com/gitea/api/v1/user/repos\?token=EXAMPLE_TOKEN
277
277
{
278
278
" name" : " spam" ,
279
279
" private" : false,
@@ -282,12 +282,12 @@ gitea.new() {
282
282
283
283
# Deployment happens if you provide a GITEA_DEPLOY_KEY
284
284
$ GITEA_DEPLOY_KEY=example-key curl_status=201 gitea new foo/bar
285
- curl --silent --write-out %\{http_code\} --output /dev/null -X POST -H Content-Type:\ application/json -d @- https://example.com/gitea/api/v1/org/foo/repos\?token=EXAMPLE_TOKEN
285
+ curl --silent --write-out \\ n %\{http_code\} -X POST -H Content-Type:\ application/json -d @- https://example.com/gitea/api/v1/org/foo/repos\?token=EXAMPLE_TOKEN
286
286
{
287
287
" name" : " bar" ,
288
288
" private" : true
289
289
}
290
- curl --silent --write-out %\{http_code\} --output /dev/null -X POST -H Content-Type:\ application/json -d @- -H Authorization:\ token\ EXAMPLE_TOKEN https://example.com/gitea/api/v1/repos/foo/bar/keys
290
+ curl --silent --write-out \\ n %\{http_code\} -X POST -H Content-Type:\ application/json -d @- -H Authorization:\ token\ EXAMPLE_TOKEN https://example.com/gitea/api/v1/repos/foo/bar/keys
291
291
{
292
292
" title" : " default" ,
293
293
" key" : " example-key" ,
@@ -300,12 +300,12 @@ gitea.new() {
300
300
> GITEA_DEPLOY_READONLY=false \
301
301
> curl_status=201 \
302
302
> gitea new foo/bar
303
- curl --silent --write-out %\{http_code\} --output /dev/null -X POST -H Content-Type:\ application/json -d @- https://example.com/gitea/api/v1/org/foo/repos\?token=EXAMPLE_TOKEN
303
+ curl --silent --write-out \\ n %\{http_code\} -X POST -H Content-Type:\ application/json -d @- https://example.com/gitea/api/v1/org/foo/repos\?token=EXAMPLE_TOKEN
304
304
{
305
305
" name" : " bar" ,
306
306
" private" : true
307
307
}
308
- curl --silent --write-out %\{http_code\} --output /dev/null -X POST -H Content-Type:\ application/json -d @- -H Authorization:\ token\ EXAMPLE_TOKEN https://example.com/gitea/api/v1/repos/foo/bar/keys
308
+ curl --silent --write-out \\ n %\{http_code\} -X POST -H Content-Type:\ application/json -d @- -H Authorization:\ token\ EXAMPLE_TOKEN https://example.com/gitea/api/v1/repos/foo/bar/keys
309
309
{
310
310
" title" : " sample-title" ,
311
311
" key" : " example-key" ,
@@ -365,8 +365,8 @@ gitea.vendor() {
365
365
# New Repository
366
366
$ mkdir foo; cd foo; echo " v1" >f
367
367
$ curl_status=404,200 gitea -p -r foo -t 1.1 vendor </dev/null 2>&1|grep -v '^ Author:'
368
- curl --silent --write-out %\{http_code\} --output /dev/null -H Authorization:\ token\ EXAMPLE_TOKEN https://example.com/gitea/api/v1/repos/some_user/foo
369
- curl --silent --write-out %\{http_code\} --output /dev/null -X POST -H Content-Type:\ application/json -d @- https://example.com/gitea/api/v1/user/repos\?token=EXAMPLE_TOKEN
368
+ curl --silent --write-out \\ n %\{http_code\} -H Authorization:\ token\ EXAMPLE_TOKEN https://example.com/gitea/api/v1/repos/some_user/foo
369
+ curl --silent --write-out \\ n %\{http_code\} -X POST -H Content-Type:\ application/json -d @- https://example.com/gitea/api/v1/user/repos\?token=EXAMPLE_TOKEN
370
370
{
371
371
" name" : " foo" ,
372
372
" private" : false
@@ -389,7 +389,7 @@ gitea.vendor() {
389
389
$ rm -rf .git
390
390
$ echo " v2" >>f
391
391
$ gitea -r foo -t 1.2 vendor </dev/null 2>&1|grep -v '^ Author:'
392
- curl --silent --write-out %\{http_code\} --output /dev/null -H Authorization:\ token\ EXAMPLE_TOKEN https://example.com/gitea/api/v1/repos/some_user/foo
392
+ curl --silent --write-out \\ n %\{http_code\} -H Authorization:\ token\ EXAMPLE_TOKEN https://example.com/gitea/api/v1/repos/some_user/foo
393
393
Cloning into bare repository '.git'...
394
394
done.
395
395
[vendor *] Vendor update to 1.2 (glob)
@@ -493,15 +493,15 @@ api() {
493
493
# extglob is needed for pattern matching
494
494
local r=0; shopt -s extglob; api " $@ " || r=$? ; shopt -u extglob; return $r
495
495
fi
496
- read-curl --silent --write-out ' %{http_code}' --output /dev/null " ${@: 4} " " ${GITEA_URL%/ } /api/v1/${3#/ } "
497
- local true=" @($1 )" false=" @($2 )"
496
+ read-curl --silent --write-out ' \n %{http_code}' " ${@: 4} " " ${GITEA_URL%/ } /api/v1/${3#/ } "
497
+ local true=" @($1 )" false=" @($2 )" code= ${REPLY ##* $' \n ' } ; REPLY= ${REPLY % $code }
498
498
# shellcheck disable=2053 # glob matching is what we want!
499
- if [[ $REPLY == $true ]]; then return 0; elif [[ $2 && $REPLY == $false ]]; then return 1
500
- else case $REPLY in
499
+ if [[ $code == $true ]]; then return 0; elif [[ $2 && $code == $false ]]; then return 1
500
+ else case $code in
501
501
000) fail " Invalid server response: check GITEA_URL" 78 ;; # EX_PROTOCOL
502
502
401) fail " Unauthorized: check GITEA_USER and GITEA_API_TOKEN" 77 ;; # EX_NOPERM
503
503
404) fail " Server returned 404 Not Found" 69 ;; # EX_UNAVAILABLE
504
- * ) fail " Failure: HTTP code $REPLY (expected $1 ${2: + or $2 } )" 70 ;; # EX_SOFTWARE
504
+ * ) fail " Failure: HTTP code $code (expected $1 ${2: + or $2 } )" 70 ;; # EX_SOFTWARE
505
505
esac
506
506
fi
507
507
}
@@ -511,34 +511,34 @@ fail() { echo "$1" >&2; return "${2-64}"; }
511
511
512
512
~~~shell
513
513
$ api 200 " " x extra args </dev/null; echo [$? ]
514
- curl --silent --write-out %\{http_code\} --output /dev/null extra args https://example.com/gitea/api/v1/x
514
+ curl --silent --write-out \\ n %\{http_code\} extra args https://example.com/gitea/api/v1/x
515
515
[0]
516
516
517
517
$ api " " " 400| 200" x extra args </dev/null; echo [$? ]
518
- curl --silent --write-out %\{http_code\} --output /dev/null extra args https://example.com/gitea/api/v1/x
518
+ curl --silent --write-out \\ n %\{http_code\} extra args https://example.com/gitea/api/v1/x
519
519
[1]
520
520
521
521
$ curl_status=000 api 200 " " x extra args </dev/null; echo [$? ]
522
- curl --silent --write-out %\{http_code\} --output /dev/null extra args https://example.com/gitea/api/v1/x
522
+ curl --silent --write-out \\ n %\{http_code\} extra args https://example.com/gitea/api/v1/x
523
523
Invalid server response: check GITEA_URL
524
524
[78]
525
525
526
526
$ curl_status=401 api 200 " " /y </dev/null
527
- curl --silent --write-out %\{http_code\} --output /dev/null https://example.com/gitea/api/v1/y
527
+ curl --silent --write-out \\ n %\{http_code\} https://example.com/gitea/api/v1/y
528
528
Unauthorized: check GITEA_USER and GITEA_API_TOKEN
529
529
[77]
530
530
531
531
$ curl_status=404 api 200 401 /z </dev/null; echo [$? ]
532
- curl --silent --write-out %\{http_code\} --output /dev/null https://example.com/gitea/api/v1/z
532
+ curl --silent --write-out \\ n %\{http_code\} https://example.com/gitea/api/v1/z
533
533
Server returned 404 Not Found
534
534
[69]
535
535
536
536
$ curl_status=404 api 200 404 /z </dev/null; echo [$? ]
537
- curl --silent --write-out %\{http_code\} --output /dev/null https://example.com/gitea/api/v1/z
537
+ curl --silent --write-out \\ n %\{http_code\} https://example.com/gitea/api/v1/z
538
538
[1]
539
539
540
540
$ curl_status=501 api 200 401 /z </dev/null; echo [$? ]
541
- curl --silent --write-out %\{http_code\} --output /dev/null https://example.com/gitea/api/v1/z
541
+ curl --silent --write-out \\ n %\{http_code\} https://example.com/gitea/api/v1/z
542
542
Failure: HTTP code 501 (expected 200 or 401)
543
543
[70]
544
544
~~~
0 commit comments