summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortypebrook <typebrook@gmail.com>2020-02-02 15:49:48 +0800
committertypebrook <typebrook@gmail.com>2020-02-02 15:49:48 +0800
commit08b3d8510b23fb289cf216d1f8ea5f98b2062f97 (patch)
treefe77670e238fdca87f06003d34fc08c64a21e4d5
parent70a71dfaa07b4d80816617b15d2e684b8fd04201 (diff)
update
-rwxr-xr-xscripts/gist23
1 files changed, 15 insertions, 8 deletions
diff --git a/scripts/gist b/scripts/gist
index c1b8a8c..088fc13 100755
--- a/scripts/gist
+++ b/scripts/gist
@@ -134,7 +134,7 @@ _validate_config(){
134 134
135# load configuration 135# load configuration
136_apply_config() { 136_apply_config() {
137 _validate_config 137 _validate_config "$@" || return 1
138 138
139 AUTH_HEADER="Authorization: token $token" 139 AUTH_HEADER="Authorization: token $token"
140 [[ -z "$action" ]] && action="${EDITOR:-vi} *" 140 [[ -z "$action" ]] && action="${EDITOR:-vi} *"
@@ -162,12 +162,17 @@ getConfiguredClient() {
162 162
163## Allows to call the users configured client without if statements everywhere 163## Allows to call the users configured client without if statements everywhere
164http_method() { 164http_method() {
165 local header=""
166 local METHOD=$1; shift 165 local METHOD=$1; shift
166 [[ $METHOD =~ (POST|PATCH) ]] && read data
167 case "$configuredClient" in 167 case "$configuredClient" in
168 curl) [[ -n $token ]] && header="--header Authorization: token $token"; curl $METHOD -A curl -s $header $@ ;; 168 curl) [[ -n $token ]] && local extra="--header" local header="Authorization: token $token"
169 wget) [[ -n $token ]] && header="--header Authorization: token $token"; wget --method=$METHOD -qO- $header $@ ;; 169 [[ $METHOD =~ (POST|PATCH) ]] && extra2="--data"
170 httpie) [[ -n $token ]] && header="Authorization:token $token"; http -b $METHOD $@ $header;; 170 curl -X $METHOD -A curl -s $extra "$header" $extra2 "$data" $@ ;;
171 wget) [[ -n $token ]] && local extra="--header" local header="Authorization: token $token"
172 [[ $METHOD =~ (POST|PATCH) ]] && extra2='--body-data'
173 wget --method=$METHOD -qO- $extra "$header" $extra2 "$data" $@ ;;
174 httpie) [[ -n $token ]] && header="Authorization:token $token"
175 http -b $METHOD $@ "$header";;
171 fetch) fetch -q "$@" ;; 176 fetch) fetch -q "$@" ;;
172 esac 177 esac
173} 178}
@@ -251,6 +256,8 @@ _update() {
251 fi 256 fi
252 257
253 local response=$(http_method GET $GITHUB_API/$route) 258 local response=$(http_method GET $GITHUB_API/$route)
259
260 # FIXME if response fail
254 false && echo Failed to update gists && return 1 261 false && echo Failed to update gists && return 1
255 sed -i "$filter" $INDEX 262 sed -i "$filter" $INDEX
256 echo $response | _parse_response >> $INDEX 263 echo $response | _parse_response >> $INDEX
@@ -313,7 +320,7 @@ _goto_gist() {
313_delete_gist() { 320_delete_gist() {
314 for i in "$@"; do 321 for i in "$@"; do
315 _gist_id "$i" 322 _gist_id "$i"
316 curl -X DELETE -s -H "$AUTH_HEADER" $GITHUB_API/gists/$GIST_ID \ 323 http_method DELETE $GITHUB_API/gists/$GIST_ID \
317 && echo "$i" deleted \ 324 && echo "$i" deleted \
318 && sed -i -E "/^$i / d" $INDEX 325 && sed -i -E "/^$i / d" $INDEX
319 done 326 done
@@ -397,6 +404,7 @@ _new_file() {
397 echo /tmp/$filename 404 echo /tmp/$filename
398} 405}
399 406
407# FIXME curl bad credential exit code
400# create a new gist with files 408# create a new gist with files
401_create_gist() { 409_create_gist() {
402 _set_gist "$@" || return 1 410 _set_gist "$@" || return 1
@@ -409,8 +417,7 @@ _create_gist() {
409 echo "\"$(basename $file)\": {\"content\": \"$(sed '$ !s/$/\\n/' $file)\"}," 417 echo "\"$(basename $file)\": {\"content\": \"$(sed '$ !s/$/\\n/' $file)\"},"
410 done | tr -d '\n' | sed 's/^/{/; s/,$/}/' \ 418 done | tr -d '\n' | sed 's/^/{/; s/,$/}/' \
411 | echo "{ \"public\": $public, \"files\": $(cat -), \"description\": \"$description\"}" \ 419 | echo "{ \"public\": $public, \"files\": $(cat -), \"description\": \"$description\"}" \
412 | curl -s -H "$AUTH_HEADER" --data @- $GITHUB_API/gists \ 420 | http_method POST $GITHUB_API/gists \
413 | tee jojo \
414 | sed '1 s/^/[/; $ s/$/]/' \ 421 | sed '1 s/^/[/; $ s/$/]/' \
415 | _parse_response $index >> $INDEX 422 | _parse_response $index >> $INDEX
416 423