Skip to content

Instantly share code, notes, and snippets.

@gedex
Last active October 30, 2018 04:52
Show Gist options
  • Save gedex/74b6d3ed1ce8ed394dec4bb2df3cd9f1 to your computer and use it in GitHub Desktop.
Save gedex/74b6d3ed1ce8ed394dec4bb2df3cd9f1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
wcez_usage() {
if [[ ! -z "$1" ]]; then
echo -e "$1\n"
fi
echo "Usage: wcez <extension-slug> <dst> [-b branch] [-t tag]"
}
wcez() {
if [[ "$#" -lt 2 ]]; then
wcez_usage
return 1
fi
local slug dst tag tmp
local branch="master"
local current=`pwd`
while [ "$1" ]; do
if [ "$1" == "-t" ]; then
shift
tag="$1"
shift
elif [ "$1" == "-b" ]; then
shift
branch="$1"
shift
else
# extension-slug followed by dst (of zip file)
slug="$1"
shift
dst="$1"
shift
fi
done
if [[ -z "$slug" ]]; then
wcez_usage "Error: missing extension-slug"
return 1
fi
if [[ -z "$dst" ]]; then
wcez_usage "Error: missing dst"
return 1
fi
tmp=`mktemp -d`
if [ $? -ne 0 ]; then
echo "Unable to create temporary directory for git-clone"
return 1
fi
git clone "[email protected]:woocommerce/$slug" "$tmp"
if [ $? -ne 0 ]; then
echo "Failed to clone [email protected]:woocommerce/$slug"
rm -rf "$tmp"
return 1
fi
git ls-remote --heads "[email protected]:woocommerce/$slug" "$branch" | grep "$branch" >/dev/null
if [ "$?" == "1" ]; then
echo "Branch $branch does not exists"
rm -rf "$tmp"
return 1
fi
cd "$tmp"
git archive "origin/$branch" --prefix="$slug/" -o "$dst"
if [ $? -ne 0 ]; then
echo "Failed to create the zip with git-archive"
cd "$current"
rm -rf "$tmp"
return 1
fi
echo "Archive created at $dst."
cd "$current"
rm -rf "$tmp"
return 0
}
wcer_usage() {
if [[ ! -z "$1" ]]; then
echo -e "$1\n"
fi
echo "Usage: wcer <extension-slug> [-l] [-b]"
echo ""
echo " -l only show latest release"
echo " -b show body"
}
wcer() {
if [[ "$#" -lt 1 ]]; then
wcer_usage
return 1
fi
local slug only_latest_release show_body
while [ "$1" ]; do
if [ "$1" == "-l" ]; then
only_latest_release="yes"
shift
elif [ "$1" == "-b" ]; then
show_body="yes"
shift
else
slug="$1"
shift
fi
done
if [[ -z "$slug" ]]; then
wcer_usage "Error: missing extension-slug"
return 1
fi
local jq_in='.[] | .tag_name'
local api_url="https://api.github.com/repos/woocommerce/${slug}/releases"
if [[ "$only_latest_release" == "yes" ]]; then
api_url="https://api.github.com/repos/woocommerce/${slug}/releases/latest"
jq_in='.tag_name'
fi
if [[ "$show_body" == "yes" ]]; then
jq_in="${jq_in}, .body"
fi
curl -s -H "Authorization: token ${GITHUB_TOKEN}" "$api_url" | jq "$jq_in"
}
@gedex
Copy link
Author

gedex commented Oct 24, 2016

The script is created for sourcing, e.g. source wc-extension-zip.bash, instead of executing the bash script (you can source it from ~/.bash_profile). If you're using bash_it, you can put wc-extension-zip.bash under custom dir.

Example of running this:

$ wcez woocommerce-box-office ~/Desktop/woocommerce-box-office.zip
Cloning into '/var/folders/lk/xzr9s0655d3f54p8t2p2p45h0000gn/T/tmp.ZprGDhPF'...
remote: Counting objects: 1524, done.
remote: Total 1524 (delta 0), reused 0 (delta 0), pack-reused 1524
Receiving objects: 100% (1524/1524), 370.61 KiB | 317.00 KiB/s, done.
Resolving deltas: 100% (943/943), done.
Checking connectivity... done.
Archive created at /Users/gedex/Desktop/woocommerce-box-office.zip.

@gedex
Copy link
Author

gedex commented Oct 30, 2018

Added wcer to see releases or latest release of an extension.

Examples

$ wcer
Usage: wcer <extension-slug> [-l] [-b]

 -l only show latest release
 -b show body

$ wcer woocommerce-product-addons
"3.0.1"
"3.0.0"
"2.9.7"
"2.9.6"
"2.9.5"
"2.9.4"
"2.9.3"
"2.9.2"
"2.9.1"
"version/2.9.0"
"2.8.1"
"2.8.0"
"2.7.26"
"2.7.25"
"2.7.24"
"2.7.23"
"2.7.22"
"2.7.21"
"2.7.20"
"2.7.19"
"2.7.18"
"2.7.17"
"2.7.16"
"2.7.15"
"2.7.14"
"2.7.13"
"2.7.12"
"2.7.10"
"2.7.6"

$ wcer woocommerce-product-addons -l
"3.0.1"

$ wcer woocommerce-product-addons -l -b
"3.0.1"
"2018-10-29 - version 3.0.1\r\n* Fix - Admin settings display sometimes not refreshed to new 3.0 version. Add versioning to CSS.\r\n* Fix - Non required radio buttons causes undefined error when selecting on None.\r\n* Fix - Remove file upload path from displaying on line item summary.\r\n* Fix - When show tax inclusive on shop/pages is enabled, summary amount not reflecting tax.\r\n* Fix - When saving price type settings, the type gets reverted to previous settings in certain cases."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment