App-git-hub
view release on metacpan or search on metacpan
share/lib/git-hub view on Meta::CPAN
# You should probably add at least the 'repo' and 'user' scopes:
git hub scope-add <token-id> repo user
You can also just run setup command, and it will guide you:
git hub setup
Would you like to run it now?
...
prompt-to-run-setup
}
config-not-setup() {
cat <<...
Greetings!!!
You seem to be a brand new 'git hub' user, since your config is not set up.
The 'git-hub' should soon be your new best friend. Configuration is really
share/lib/git-hub view on Meta::CPAN
[github]
login = your-github-login-id
api-token = c956f87abab2da54882cc1f1ade42efcc2b15dc7
json-lib = json-perl.bash
use-auth = 1
Would you like to start the automated 'setup' process right now? (Do it!)
...
prompt-to-run-setup
}
prompt-to-run-setup() {
prompt
source-ext git-hub-setup
command:setup || exit 1
exit 0
}
#------------------------------------------------------------------------------
# Reusable helper functions:
#------------------------------------------------------------------------------
editor-title-body() {
rm -f "$GIT_HUB_MSG_FILE"
share/lib/git-hub view on Meta::CPAN
source-ext help-functions.bash
if can "help:$command"; then
msg=$'\n'"$msg"$'\n'"$("help:$command")"$'\n'
fi
echo "$msg" >&2
exit 1
}
abort() { echo "Abort: $1" >&2; exit 1; }
prompt() {
local msg answer default yn=false password=false
case $# in
0) msg="${prompt_msg:-Press <ENTER> to continue, or <CTL>-C to exit.}" ;;
1)
msg="$1"
if [[ "$msg" =~ \[yN\] ]]; then
default=n
yn=true
elif [[ "$msg" =~ \[Yn\] ]]; then
default=y
yn=true
fi
;;
2)
msg="$1"
default="$2"
;;
*) die "Invalid usage of prompt" ;;
esac
if [[ "$msg" =~ [Pp]assword ]]; then
password=true
msg=$'\n'"$msg"
fi
while true; do
if "$password"; then
read -s -p "$msg" answer
else
read -p "$msg" answer
share/lib/git-hub.d/git-hub-cache-clear view on Meta::CPAN
#!/usr/bin/env bash
set -e
command:cache-clear() {
a="$(prompt "Delete all of '$GIT_HUB_CACHE'? [yN]")"
if [ "$a" == y ]; then
rm -fr "$GIT_HUB_CACHE"
msg_ok="'$GIT_HUB_CACHE' deleted."
else
msg_ok="'$GIT_HUB_CACHE' not deleted."
fi
}
share/lib/git-hub.d/git-hub-pr view on Meta::CPAN
local diff="$(git diff $parent_remote_name/$parent_base..$branch_name)"
if [ -z "$diff" ]; then
abort "No changes between $parent_remote_name/$parent_base and $branch_name."
fi
local head="$owner:$branch_name"
local base="$parent_base"
local url="/repos/$parent_owner_repo/pulls"
if [[ "$number" =~ ^[0-9]+$ ]]; then
local prompt_msg="Attach PR $owner/$repo:$branch_name -> $parent_owner_repo:$parent_base to issue #$number? [yN]"
local doit=$(prompt "$prompt_msg")
if [[ "$doit" =~ ^[yY] ]]; then
api-post "$url" "$(
json-dump-object head "$head" base "$base" issue "$number"
)"
msg_ok="Attached PR to issue: $(JSON.get -s /html_url -)"
else
msg_ok=0
fi
else
editor-title-body "
share/lib/git-hub.d/git-hub-setup view on Meta::CPAN
The 'git hub' Setup Tool
This dialog will walk you through the steps involved in creating or updating
the configuration needed by the 'git hub' command. It should only take a
minute.
Your config will be stored here: '$GIT_HUB_CONFIG'.
...
prompt
mkdir -p "$GIT_HUB_USER_DIR"
}
setup:login() {
clear
cat <<...
Step #1 - Login ID
The 'git hub' command needs to know your GitHub login id.
...
read-config-value login && login="$value" || login=
if [ -n "$login" ]; then
echo "Your login is currently set to '$login'".
echo
a="$(prompt "Do you want to keep this value? [Yn] ")"
[ "$a" == y ] && return
fi
while true; do
echo
login="$(prompt "Enter your GitHub login id: ")"
[[ "$login" =~ ^[-a-zA-Z0-9]+$ ]] && break
echo "Invalid login value '$login'"
done
write-config-value login "$login" ||
die "Can't write-config-value login $login"
cat <<...
Login changed to '$login'.
...
prompt
}
setup:api-token() {
clear
cat <<...
Step #2 - API Token
More advanced commands require an authentication token (with the appropriate
scopes added).
share/lib/git-hub.d/git-hub-setup view on Meta::CPAN
It seems that you already have a token. To see your token, run these commands:
git hub config api-token
git hub token-list
Verify that this is the correct token, If not, we will generate a new token
for you and put it in the config file.
...
a="$(prompt "Is this the correct token? [Yn]")"
[ "$a" == y ] && return
fi
cat <<...
To generate a new token, the commands require your GitHub password.
The password will not be stored after the commands finish running.
...
export GIT_HUB_PASSWORD="$(
prompt "Enter your GitHub password (for '$login'): "
)"
echo
echo
echo 'Generating a new authentication token...'
local rc=0 token_id= desc="API Token for git-hub ($(date "+%s"))"
token_id="$(git hub token-new -qr "$desc")" || rc=$?
if [ "$rc" -eq 2 ]; then
export GIT_HUB_2FA_OTP="$(
prompt "Enter your 2 Factor Auth Code: "
)"
token_id="$(git hub token-new -qr "$desc")" || true
fi
[ -n "$token_id" ] || die "Command failed"
echo "Token successfully generated (token id: $token_id)."
echo
echo "Adding the 'user', 'repo' and 'gist' scopes to the token..."
$(git hub scope-add $token_id user repo gist &> /dev/null) || exit $?
echo "Scopes successfully added."
echo
echo "Adding the new token to your config file..."
local token_value="$(git hub token-get $token_id token)" || exit $?
write-config-value api-token $token_value ||
die "Can't write-config-value api-token $token_value"
echo "Token successfully added to config file."
echo
prompt
unset GIT_HUB_PASSWORD
}
setup:use-auth() {
clear
cat <<...
Step #3 - Use Authentication
Many commands don't require you to send your authentication token, but there
share/lib/git-hub.d/git-hub-setup view on Meta::CPAN
2) GitHub only allows 60 unauthenticated calls per hour, as opposed to 5000
for authenticated calls. For this reason it is preferable to always
authenticate.
There is a config option called 'use-auth' that you can set to always send the
authentication token.
...
read-config-value use-auth && auth="$value" || auth=
if [ -z "$auth" ]; then
a="$(prompt "Would you like to turn this option on? [Yn]")"
[ "$a" == n ] && return
elif [ "$auth" == false ]; then
echo 'You have this option turned off.'
echo
a="$(prompt "Would you like to turn this option on? [yN]")"
else
write-config-value use-auth true ||
die "Can't write-config-value use-auth true"
echo 'You already have this option turned on.'
echo
a="$(prompt "Would you like to keep this option on? [Yn]")"
fi
if [ "$a" == y ]; then
write-config-value use-auth true ||
die "Can't write-config-value use-auth true"
else
write-config-value use-auth false ||
die "Can't write-config-value use-auth false"
fi
}
share/lib/git-hub.d/git-hub-setup view on Meta::CPAN
There is a setting to use Perl to handle the JSON which is much faster. It
requires Perl and the JSON::MaybeXS modules for Perl.
...
if [ -n "$set" ]; then
cat <<...
You already have this option set to '$set'.
...
prompt
elif [ "$perl" == OK ]; then
if [ "$perl_json_pp" == OK ] ||
[ "$perl_json" == OK ] ||
[ "$perl_json_maybexs" == OK ]
then
cat <<...
You seem to have the prerequisites to speed up your 'git-hub' experience.
...
a="$(prompt "Would you like to turn this setting on? [Yn]")"
[ "$a" == y ] && write-config-value json-lib json-perl.bash ||
die "Can't write-config-value use-auth false"
else
cat <<...
You seem to have Perl, but none of the 'JSON::MaybeXS', 'JSON' or 'JSON::PP'
modules, so we can't use the setting at this time.
Try installing the JSON::MaybeXS module from CPAN and then run 'git hub setup'
again.
...
prompt
fi
else
cat <<...
Perl seems to not be installed on your system, so we can't use the setting at
this time.
If you want to use this speedup in the future, try installing Perl and the
JSON::MaybeXS module from CPAN and then run 'git hub setup' again.
...
prompt
fi
}
setup:outro() {
clear
cat <<'...'
Setup Complete
The setup process is now complete!
( run in 0.466 second using v1.01-cache-2.11-cpan-0b5f733616e )