App-git-hub
view release on metacpan or search on metacpan
share/lib/git-hub view on Meta::CPAN
options+=("${after[@]}")
run-command "${options[@]}"
OK || return
done
done
}
#------------------------------------------------------------------------------
# `git hub` command functions:
#------------------------------------------------------------------------------
command:help() {
source-ext help-functions.bash
local cmd="${command_arguments[0]}"
if [ -n "$cmd" ]; then
if can "help:$cmd"; then
"help:$cmd"
echo
else
err "No help found for '$cmd'"
fi
elif $do_all; then
help:all
else
cat <<'...'
git-hub -- The GitHub Subcommand for Git
Try the following commands to get more help:
git hub help --all # Show all commands
git hub help <command> # Get help for a specific command
git help hub # Browse the complete 'git-hub' documentation
git hub --help # Browse the complete 'git-hub' documentation
git hub -h # Show the short documentation
Or read the documentation online:
https://github.com/ingydotnet/git-hub#readme
If you find bugs, or missing features, just run:
git hub issue-new ingydotnet/git-hub
Enjoy GitHubbing in the comfort of your terminal.
-- Ingy döt Net
...
fi
msg_ok=0
}
# NOTE: All the commands used to be defined here but now they have been moved
# into various files under the `cmd` directory for better grouping and code
# organization.
#------------------------------------------------------------------------------
# API calling functions:
#------------------------------------------------------------------------------
api-get() { api-call GET "$1" "$2"; }
api-post() { api-call POST "$1" "$2"; }
api-put() { api-call PUT "$1" "$2"; }
api-patch() { api-call PATCH "$1" "$2"; }
api-delete() { api-call DELETE "$1" "$2"; }
# Build a command to make the HTTP call to the API server, make the call, and
# check the result.
api-call() {
format-curl-command "$@"
if "$verbose_output"; then
local cc="${curl_command[@]}"
if ! "$show_token"; then
[ -n "$api_token" ] &&
cc="${cc/token $api_token/token ********}"
[ -n "$GIT_HUB_PASSWORD" ] &&
cc="${cc/$login:$GIT_HUB_PASSWORD/$login:********}"
fi
echo "$cc"$'\n' >&2
fi
if "$dry_run"; then
nay '*** NOTE: This is a dry run only. ***'
msg_ok=0
return 0
elif "$repeat_command"; then
# Use the cache
[ -e "$command_header_file" ] ||
error "-R flag not valid. Command not previously run."
rc=0
else
local cache_dir="$GIT_HUB_CACHE/$command_sha1"
mkdir -p "$cache_dir"
# Actually run the curl command!
(
set +e
# set -x # for debugging the real command
"${curl_command[@]}"
)
rc=$?
cache-response-files
fi
"$show_headers" && cat "$command_header_file" >&2
if [ -s "$command_output_file" ]; then
JSON__cache="$(cat "$command_output_file" | JSON.load)"
"$show_output" && cat "$command_output_file" >&2
"$show_json" && JSON.cache >&2
fi
check-api-call-status $rc
true
}
# Build curl command in a global array. This is the only way to preserve
# quoted whitespace.
format-curl-command() {
local action="$1"
local url="$2"
local data="$3"
[[ "$url" =~ [a-zA-Z0-9]/(/|$) ]] &&
error "API url '$url' looks suspiciously wrong"
"$use_auth" && require-auth 1
local user_agent="git-hub-$GIT_HUB_VERSION"
# Cheap trick to make github pretty-print the JSON output.
"$show_output" && user_agent="curl-$user_agent"
[[ "$url" =~ ^https?: ]] || url="$GIT_HUB_API_URI$url"
curl_command=(
curl
--request "$action"
"$url"
)
[ -n "$data" ] || [ "$action" = "PUT" ] && curl_command+=(-d "$data")
if [ -n "$basic_auth" ]; then
local login="$(get-login)"
if [ -n "$GIT_HUB_PASSWORD" ]; then
curl_command+=(-u "$login:$GIT_HUB_PASSWORD")
else
curl_command+=(-u "$login")
fi
if [ -n "$GIT_HUB_2FA_OTP" ]; then
curl_command+=(--header "X-GitHub-OTP: $GIT_HUB_2FA_OTP")
fi
elif [ -n "$api_token" ]; then
curl_command+=(--header "Authorization: token $api_token")
fi
local sha1seed="${curl_command[@]}"
[ -n "$api_token" ] && [ -n "$GIT_HUB_TEST_MAKE" ] &&
sha1seed="${sha1seed/$api_token/0123456789abcdef0123456789abcdef01234567}"
# echo "$sha1seed" >> sha1seed
"$show_output" && sha1seed+=' -O'
command_sha1="$(echo "$sha1seed" | $sha1sum | cut -d ' ' -f1)"
command_header_file="$GIT_HUB_CACHE/$command_sha1/head"
command_output_file="$GIT_HUB_CACHE/$command_sha1/out"
command_error_file="$GIT_HUB_CACHE/$command_sha1/err"
if ! "$no_cache" &&
[[ ! "$url" =~ hooks$ ]] &&
[ -e "$command_header_file" ]
then
etag="$(grep -Em1 '^ETag:' "$command_header_file" | tr -d '\r')"
if [ -n "$etag" ]; then
curl_command+=(--header "${etag/ETag/If-None-Match}")
fi
fi
curl_command+=(
--user-agent "$user_agent"
--dump-header "$GIT_HUB_CACHE/head"
--output "$GIT_HUB_CACHE/out"
--stderr "$GIT_HUB_CACHE/err"
--silent
--show-error
)
}
cache-response-files() {
grep -E '^Status: 304' "$GIT_HUB_CACHE/head" &> /dev/null || {
for f in head out err; do
[ -e "$GIT_HUB_CACHE/$f" ] &&
cp "$GIT_HUB_CACHE/$f" "$cache_dir"
done
}
}
check-api-call-status() {
OK=$1
if [ ! -f "$command_header_file" ]; then
ERROR="$(head -n1 $command_error_file)"
if [ $OK == 6 ]; then
ERROR+=$'\n'$'\n'"Check your internet connection."
verbose_output=true
fi
( run in 1.271 second using v1.01-cache-2.11-cpan-13bb782fe5a )