Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions commands/package-versions/metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# command metadata
# generated by stubbs:add-command
# Thu Oct 19 15:19:18 CDT 2017
NAME=package-versions
DESCRIPTION="Retrieves versions for specified remote package."
OPTIONS="org repo package"
GENERATE_HELP="true"
68 changes: 68 additions & 0 deletions commands/package-versions/options.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Generated by stubbs:add-option. Do not edit, if using stubbs.
# Created: Thu Oct 19 15:21:05 CDT 2017
#
#/ usage: bintray:package-versions --org <> --repo <> --package <>

# _rerun_options_parse_ - Parse the command arguments and set option variables.
#
# rerun_options_parse "$@"
#
# Arguments:
#
# * the command options and their arguments
#
# Notes:
#
# * Sets shell variables for any parsed options.
# * The "-?" help argument prints command usage and will exit 2.
# * Return 0 for successful option parse.
#
rerun_options_parse() {

unrecognized_args=()

while (( "$#" > 0 ))
do
OPT="$1"
case "$OPT" in
--org) rerun_option_check $# $1; ORG=$2 ; shift 2 ;;
--repo) rerun_option_check $# $1; REPO=$2 ; shift 2 ;;
--package) rerun_option_check $# $1; PACKAGE=$2 ; shift 2 ;;
# help option
-\?|--help)
rerun_option_usage
exit 2
;;
# unrecognized arguments
*)
unrecognized_args+=("$OPT")
shift
;;
esac
done

# Set defaultable options.

# Check required options are set
[[ -z "$ORG" ]] && { echo >&2 "missing required option: --org" ; return 2 ; }
[[ -z "$REPO" ]] && { echo >&2 "missing required option: --repo" ; return 2 ; }
[[ -z "$PACKAGE" ]] && { echo >&2 "missing required option: --package" ; return 2 ; }
# If option variables are declared exportable, export them.

# Make unrecognized command line options available in $_CMD_LINE
if [ ${#unrecognized_args[@]} -gt 0 ]; then
export _CMD_LINE="${unrecognized_args[@]}"
fi
#
return 0
}


# If not already set, initialize the options variables to null.
: ${ORG:=}
: ${REPO:=}
: ${PACKAGE:=}
# Default command line to null if not set
: ${_CMD_LINE:=}


24 changes: 24 additions & 0 deletions commands/package-versions/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

#/ command: bintray:package-versions: "Retrieves versions for specified remote package."
#/ usage: rerun bintray:package-versions --org <> --repo <> --package <>
#/ rerun-variables: RERUN, RERUN_VERSION, RERUN_MODULES, RERUN_MODULE_DIR
#/ option-variables: ORG REPO PACKAGE

. $RERUN_MODULE_DIR/lib/functions.sh package-versions || {
echo >&2 "Failed loading function library." ; exit 1 ;
}

set -o errexit -o nounset -o pipefail

rerun_options_parse "$@"

# Command implementation
# ----------------------

# - - -
scrape_bintray_package_for_versions "$ORG" "$REPO" "$PACKAGE"
# - - -

# Done. Exit with last command exit status.
exit $?
21 changes: 18 additions & 3 deletions generator.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@

## modules

## commands

# rerun bintray: package-uri
RERUN_MODULES=$(pwd)/modules ./rerun stubbs: \
add-command \
--command package-uri \
--description "Retrieves URIs for remote package artifacts of a specified version." \
--module bintray

# rerun bintray: package-versions
RERUN_MODULES=$(pwd)/modules ./rerun stubbs: \
add-command \
--command package-versions \
--description "Retrieves versions for specified remote package." \
--module bintray

## options

# --org
RERUN_MODULES=$(pwd)/modules ./rerun stubbs: \
add-option \
--arg "true" \
--command "package-delete,package-exists,package-update,package-upload,package-upload-deb,package-uri" \
--command "package-delete,package-exists,package-update,package-upload,package-upload-deb,package-uri,package-versions" \
--description "The bintray organization." \
--export "false" \
--long "org" \
Expand All @@ -20,7 +35,7 @@ RERUN_MODULES=$(pwd)/modules ./rerun stubbs: \
RERUN_MODULES=$(pwd)/modules ./rerun stubbs: \
add-option \
--arg "true" \
--command "package-delete,package-exists,package-update,package-upload,package-upload-deb,package-uri" \
--command "package-delete,package-exists,package-update,package-upload,package-upload-deb,package-uri,package-versions" \
--description "The targeted repo." \
--export "false" \
--long "repo" \
Expand All @@ -32,7 +47,7 @@ RERUN_MODULES=$(pwd)/modules ./rerun stubbs: \
RERUN_MODULES=$(pwd)/modules ./rerun stubbs: \
add-option \
--arg "true" \
--command "package-delete,package-exists,package-update,package-upload,package-upload-deb,package-uri" \
--command "package-delete,package-exists,package-update,package-upload,package-upload-deb,package-uri,package-versions" \
--description "The package name." \
--export "false" \
--long "package" \
Expand Down
2 changes: 1 addition & 1 deletion options/org/metadata
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# option metadata
# generated by stubbs:add-option
# Mon Oct 9 15:06:22 CDT 2017
# Thu Oct 19 15:20:16 CDT 2017
NAME=org
DESCRIPTION="The bintray organization."
ARGUMENTS=true
Expand Down
2 changes: 1 addition & 1 deletion options/package/metadata
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# option metadata
# generated by stubbs:add-option
# Mon Oct 9 15:10:43 CDT 2017
# Thu Oct 19 15:21:04 CDT 2017
NAME=package
DESCRIPTION="The package name."
ARGUMENTS=true
Expand Down
2 changes: 1 addition & 1 deletion options/repo/metadata
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# option metadata
# generated by stubbs:add-option
# Mon Oct 9 15:09:15 CDT 2017
# Thu Oct 19 15:20:43 CDT 2017
NAME=repo
DESCRIPTION="The targeted repo."
ARGUMENTS=true
Expand Down
130 changes: 130 additions & 0 deletions tests/package-versions-1-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/usr/bin/env roundup
#
#/ usage: rerun stubbs:test -m bintray -p package-versions [--answers <>]
#

set -u

# Helpers
# -------
[[ -f ./functions.sh ]] && . ./functions.sh

rerun() {
command $RERUN -M $RERUN_MODULES "$@"
}

# Constants

DEFAULT_ORG="example-org"
DEFAULT_REPO="example-repo"
DEFAULT_PACKAGE="example-package"

DEFAULT_VERSIONS=$(cat <<END_HEREDOC
1.0.0
1.0.3
1.4.0
END_HEREDOC
)

DEFAULT_PACKAGE_RESPONSE_MOCK=$(cat <<'END_HEREDOC'
<html>
<head>
<script>
//1507586309599
function navi(e){
location.href = e.target.href.replace('/:','/'); e.preventDefault();
}
</script>
</head>
<body>
<pre><a onclick="navi(event)" href=":1.0.0/" rel="nofollow">1.0.0/</a></pre>
<pre><a onclick="navi(event)" href=":1.0.3/" rel="nofollow">1.0.3/</a></pre>
<pre><a onclick="navi(event)" href=":1.4.0/" rel="nofollow">1.4.0/</a></pre>
</body>
</html>
END_HEREDOC
)

DEFAULT_PACKAGE_RESPONSE_ERROR_MOCK="The requested path was not found."

DEFAULT_CURL_MOCK_TEMPFILE="/tmp/curl_mock_counter"

# The Plan
# --------
describe "package-versions"

after() {
if [ -e $DEFAULT_CURL_MOCK_TEMPFILE ]; then
rm $DEFAULT_CURL_MOCK_TEMPFILE
fi
}

# ------------------------------
it_errors_when_no_versions_are_found() {
# mock the curl calls
export DEFAULT_PACKAGE_RESPONSE_ERROR_MOCK
export DEFAULT_CURL_MOCK_TEMPFILE
echo 0 > $DEFAULT_CURL_MOCK_TEMPFILE
curl () {
curl_mock_counter=$(cat $DEFAULT_CURL_MOCK_TEMPFILE)
case $curl_mock_counter in
0)
echo "$DEFAULT_PACKAGE_RESPONSE_ERROR_MOCK"
echo 1 > $DEFAULT_CURL_MOCK_TEMPFILE
return 0
;;
*)
echo >&2 "unexpected call to curl: $@"
return 1
esac

return 1
}
export -f curl

# invoke rerun
local exitcode=
$(rerun bintray: package-versions \
--org "$DEFAULT_ORG" \
--repo "$DEFAULT_REPO" \
--package "$DEFAULT_PACKAGE") && {
echo >&2 "rerun test command succeeded"; return 1
} || {
exitcode=$?; test $exitcode -eq 3
} || {
echo >&2 "rerun test command failed with exit code: $exitcode"; return 1
}
}
# ------------------------------
it_returns_req_package_versions() {
# mock the curl calls
export DEFAULT_PACKAGE_RESPONSE_MOCK
export DEFAULT_CURL_MOCK_TEMPFILE
echo 0 > $DEFAULT_CURL_MOCK_TEMPFILE
curl () {
curl_mock_counter=$(cat $DEFAULT_CURL_MOCK_TEMPFILE)
case $curl_mock_counter in
0)
echo "$DEFAULT_PACKAGE_RESPONSE_MOCK"
echo 1 > $DEFAULT_CURL_MOCK_TEMPFILE
return 0
;;
*)
echo >&2 "unexpected call to curl: $@"
return 1
esac

return 1
}
export -f curl

# invoke rerun
requested_package_versions=$(rerun bintray: package-versions \
--org "$DEFAULT_ORG" \
--repo "$DEFAULT_REPO" \
--package "$DEFAULT_PACKAGE") || echo >&2 "rerun test call failed with exit code: $?"

# validate results
test "$requested_package_versions" == "$DEFAULT_VERSIONS"
}
# ------------------------------