diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/gist | 24 | ||||
| -rwxr-xr-x | scripts/upload-github-release-asset.sh | 8 |
2 files changed, 20 insertions, 12 deletions
diff --git a/scripts/gist b/scripts/gist index 9dfa31d..b55012b 100755 --- a/scripts/gist +++ b/scripts/gist | |||
| @@ -49,6 +49,9 @@ auth_header="Authorization: token $github_api_token" | |||
| 49 | mkdir -p $folder | 49 | mkdir -p $folder |
| 50 | index=$folder/index | 50 | index=$folder/index |
| 51 | 51 | ||
| 52 | # Validate settings. | ||
| 53 | [ "$TRACE" ] && set -x && echo foo | ||
| 54 | |||
| 52 | # get the list of gists | 55 | # get the list of gists |
| 53 | _update() { | 56 | _update() { |
| 54 | curl -s -H "$auth_header" $github_api/users/$user/gists |\ | 57 | curl -s -H "$auth_header" $github_api/users/$user/gists |\ |
| @@ -107,15 +110,19 @@ _show_detail() { | |||
| 107 | # create a new gist with a file and description | 110 | # create a new gist with a file and description |
| 108 | # TODO support folder of files | 111 | # TODO support folder of files |
| 109 | _create_gist() { | 112 | _create_gist() { |
| 110 | FILE=$(basename $1) | 113 | echo -n 'description: ' |
| 114 | read DESC | ||
| 111 | 115 | ||
| 112 | jq --arg FILE "$FILE" --arg DESC "$2" '. as $content | { | 116 | echo $@ | tr " " "\n" |\ |
| 113 | public: true, | 117 | while read file; do |
| 114 | files: { | 118 | FILE=$(basename $file) |
| 115 | ($FILE): {content: $content} | 119 | jq --arg FILE "$FILE" '. as $content | { ($FILE): {content: $content} }' -Rs $file |
| 116 | }, | 120 | done |\ |
| 121 | jq -s --arg DESC "$DESC" '{ | ||
| 122 | public: true, | ||
| 123 | files: add, | ||
| 117 | description: ($DESC) | 124 | description: ($DESC) |
| 118 | }' -R -s $1 |\ | 125 | }' |\ |
| 119 | curl -s -H "$auth_header" --data @- $github_api/gists > /dev/null && \ | 126 | curl -s -H "$auth_header" --data @- $github_api/gists > /dev/null && \ |
| 120 | _update | 127 | _update |
| 121 | } | 128 | } |
| @@ -134,7 +141,8 @@ case "$1" in | |||
| 134 | cat $index | 141 | cat $index |
| 135 | ;; | 142 | ;; |
| 136 | create | c) | 143 | create | c) |
| 137 | _create_gist "$2" "$3" | 144 | shift; |
| 145 | _create_gist $@ | ||
| 138 | ;; | 146 | ;; |
| 139 | edit | e) | 147 | edit | e) |
| 140 | _edit_gist "$2" "$3" | 148 | _edit_gist "$2" "$3" |
diff --git a/scripts/upload-github-release-asset.sh b/scripts/upload-github-release-asset.sh index 6923870..0325530 100755 --- a/scripts/upload-github-release-asset.sh +++ b/scripts/upload-github-release-asset.sh | |||
| @@ -62,17 +62,17 @@ eval $(echo "$response" | grep -C2 "\"name\":.\+$(basename $filename)" | grep -m | |||
| 62 | if [ "$asset_id" = "" ]; then | 62 | if [ "$asset_id" = "" ]; then |
| 63 | echo "No need to overwrite asset" | 63 | echo "No need to overwrite asset" |
| 64 | else | 64 | else |
| 65 | if [ "$overwrite" ]; then | 65 | if [[ "$overwrite" == "true" ]] || [[ "$overwrite" == "delete" ]]; then |
| 66 | echo "Deleting asset($asset_id)... " | 66 | echo "Deleting asset($asset_id)... " |
| 67 | curl -X "DELETE" -H "Authorization: token $github_api_token" "https://api.github.com/repos/$owner/$repo/releases/assets/$asset_id" | 67 | curl -X "DELETE" -H "Authorization: token $github_api_token" "https://api.github.com/repos/$owner/$repo/releases/assets/$asset_id" |
| 68 | if [[ "$overwrite" == "delete" ]]; then | ||
| 69 | exit 0 | ||
| 70 | fi | ||
| 68 | else | 71 | else |
| 69 | echo "File already exists on tag $tag" | 72 | echo "File already exists on tag $tag" |
| 70 | echo "If you want to overwrite it, set overwrite=true" | 73 | echo "If you want to overwrite it, set overwrite=true" |
| 71 | exit 1 | 74 | exit 1 |
| 72 | fi | 75 | fi |
| 73 | if [ "$overwrite" == "delete" ]; then | ||
| 74 | exit 0 | ||
| 75 | fi | ||
| 76 | fi | 76 | fi |
| 77 | 77 | ||
| 78 | # Upload asset | 78 | # Upload asset |