From 289cdb434053c1c63d0f2c34935375bb3e5e24f7 Mon Sep 17 00:00:00 2001 From: typebrook Date: Wed, 11 Mar 2020 10:47:48 +0800 Subject: update --- alias | 10 ++++++---- tools/github-release.sh | 19 ++++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/alias b/alias index d5da487..81c2a29 100644 --- a/alias +++ b/alias @@ -95,10 +95,13 @@ github_api() { gcg() { git clone git@github.com:$1/$2.git && cd $(basename $2) } -github_release_asset() { - command="github-release.sh\n github_api_token=$GITHUB_API_TOKEN\n owner=typebrook\n repo=tig\n tag=LATEST\n type=asset\n filename=$(which tig)\n overwrite=false" +release() { + command="github-release.sh\n github_api_token=$GITHUB_API_TOKEN\n repo=typebrook/tig\n tag=LATEST\n type=asset\n filename=$(which tig)\n overwrite=false" prompt "$command" } +asset() { + curl -LO https://github.com/$1/$2/releases/download/$3/$4 +} # tig alias cdt='cd ~/git/tig' @@ -109,8 +112,7 @@ alias get-tig='curl -LO https://github.com/typebrook/tig/releases/download/tig-2 upload_tig() { github-release.sh \ github_api_token=$GITHUB_API_TOKEN \ - owner=typebrook \ - repo=tig \ + repo=typebrook/tig \ tag=LATEST \ filename=$(which tig) overwrite=false diff --git a/tools/github-release.sh b/tools/github-release.sh index bed34db..e7ddb3b 100755 --- a/tools/github-release.sh +++ b/tools/github-release.sh @@ -7,10 +7,10 @@ # Originally created by stefanbuck # fork from: https://gist.github.com/stefanbuck/ce788fee19ab6eb0b4447a85fc99f447 # +# -- +# This script manages a release note or its asset with GitHub API v3. +# It accepts the following parameters: # -# This script accepts the following parameters: -# -# * owner # * repo # * tag # * type (asset or edit) @@ -18,12 +18,13 @@ # * github_api_token # * overwrite (optional, could be ture, false, delete, default to be false) # -# Script to manage a release or its asset using the GitHub API v3. -# # Example: # -# github-release.sh github_api_token=TOKEN owner=stefanbuck repo=playground tag=v0.1.0 type=asset filename=./build.zip overwrite=true +# # Upload a file as asset. If there is a asset with the same filename, then overwrite it. +# github-release.sh github_api_token=TOKEN repo=stefanbuck/playground tag=v0.1.0 type=asset filename=./build.zip overwrite=true # +# # Edit a release note with file content +# github-release.sh github_api_token=TOKEN repo=stefanbuck/playground tag=v0.1.0 type=edit filename=note # Check dependencies. set -e @@ -39,7 +40,7 @@ done # Define variables. GH_API="https://api.github.com" -GH_REPO="$GH_API/repos/$owner/$repo" +GH_REPO="$GH_API/repos/$repo" GH_TAGS="$GH_REPO/releases/tags/$tag" AUTH="Authorization: token $github_api_token" @@ -47,7 +48,7 @@ if [ "$tag" = 'LATEST' ]; then GH_TAGS="$GH_REPO/releases/latest" fi if [ "$type" = '' ]; then - sed -E -n -e ' /^$/ q; 11,$ s/^# *//p' "$0" + sed -E -n -e ' /^$/ q; /# --/,$ s/^# *//p' "$0" exit 0 fi @@ -85,7 +86,7 @@ upload_asset() { echo "Uploading asset... " # Construct url - GH_ASSET="https://uploads.github.com/repos/$owner/$repo/releases/$release_id/assets?name=$(basename $filename)" + GH_ASSET="https://uploads.github.com/repos/$repo/releases/$release_id/assets?name=$(basename $filename)" curl --data-binary @"$filename" -H "$AUTH" -H "Content-Type: application/octet-stream" $GH_ASSET } -- cgit v1.2.3-70-g09d2