Skip to content

Commit

Permalink
Add initial support for Glab (wimpysworld#947)
Browse files Browse the repository at this point in the history
* Add initial support for Glab

* use urlencoded path instead of id

* Add get gitlab releases (wimpysworld#8)

* added get_gitlab_releases()

* failed to filter for supported ARCHS

* fix typo

---------

Co-authored-by: Martin Wimpress <[email protected]>
  • Loading branch information
philclifford and flexiondotorg authored May 7, 2024
1 parent 9f3ce5c commit ae36cad
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 26 deletions.
Binary file added .github/gitlab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions 01-main/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ git-delta
github-desktop
gitkraken
gitter
glab
glow
google-chat-electron
google-chrome-beta
Expand Down
1 change: 1 addition & 0 deletions 01-main/packages/.shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
disable=SC2034,SC2148
23 changes: 23 additions & 0 deletions 01-main/packages/glab
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

DEFVER=1
#get_gitlab_releases "34675721"
#get_gitlab_releases "gitlab-org%2Fcli"
# PROJ="gitlab-org/cli"
# PROJ=${PROJ/\//%2F}
#ARCHS_SUPPORTED="amd64 arm64 armhf
get_gitlab_releases "gitlab-org%2Fcli" "latest"

if [ "${ACTION}" != "prettylist" ]; then
URL=$(jq <${CACHE_FILE} -r '.[] |select(.name|contains("x86_64.deb"))| .direct_asset_url')
#URL=$(jq <${CACHE_FILE} --arg arch ${HOST_CPU/armhf/arm} -r '.[] |select(.name|contains($arch))|select(.name|contains(".deb"))| .direct_asset_url')

#URL= $(jq <${CACHE_FILE} -r '.[] | .direct_asset_url' | grep ".*${HOST_CPU}\.deb"
#URL="${URL//\"}"

VERSION_PUBLISHED="${URL##*/releases/v}"
VERSION_PUBLISHED=${VERSION_PUBLISHED%%/*}
fi

PRETTY_NAME="Glab"
WEBSITE="https://gitlab.com/gitlab-org/cli"
SUMMARY="A GitLab CLI tool bringing GitLab to your command line"
73 changes: 47 additions & 26 deletions deb-get
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,29 @@ function get_github_releases() {
fi
}

function get_gitlab_releases() {
METHOD="gitlab"
CACHE_FILE="${CACHE_DIR}/${APP}.json"
# Cache gitlab releases json for 1 hour to try and prevent API rate limits
#
# Do not process gitlab releases while generating a pretty list or upgrading
# if $1 is org/app or user/repo it must be urlencoded
# the gitlab api can take a release or use permalink/latest to get the latest release
# So for gitlab sourced apps that use this release model users can use 99-local to pin a version
#

if [[ ' install update fix-installed ' =~ " ${ACTION} " ]]; then
if [ ! -e "${CACHE_FILE}" ] || [ -n "$(find "${CACHE_FILE}" -mmin +"${DEBGET_CACHE_RTN:-60}")" ]; then
fancy_message info "Updating ${CACHE_FILE}"
RELEASE=${2/%latest/permalink/latest}

local URL="https://gitlab.com/api/v4/projects/${1}/releases/${RELEASE}/assets/links"
wgetcmdarray=(wget -q --no-use-server-timestamps "${URL}" -O "${CACHE_FILE}")

${ELEVATE} "${wgetcmdarray[@]}" || ( fancy_message warn "Updating ${CACHE_FILE} failed." )
fi
fi
}
function get_website() {
METHOD="website"
CACHE_FILE="${CACHE_DIR}/${APP}.html"
Expand Down Expand Up @@ -348,7 +371,7 @@ function remove_deb() {

# Remove repos/PPA/key even if the app is not installed.
case "${METHOD}" in
direct|github|website)
direct|github|gitlab|website)
if [ -f "${CACHE_DIR}/${FILE}" ]; then
fancy_message info "Removing ${CACHE_DIR}/${FILE}"
${ELEVATE} rm "${CACHE_DIR}/${FILE}" 2>/dev/null
Expand All @@ -370,7 +393,7 @@ function version_deb() {
function info_deb() {
local INSTALLED="${VERSION_INSTALLED:-No}"
case "${METHOD}" in
(direct|github|website)
(direct|github|gitlab|website)
printf '%s\n' "${PRETTY_NAME}"
printf ' %s:\t%s\n' Package "${APP}" Repository "${APP_SRC}" Updater deb-get Installed "${INSTALLED}" Published "${VERSION_PUBLISHED}" Architecture "${ARCHS_SUPPORTED}" Download "${URL}" Website "${WEBSITE}" Summary "${SUMMARY}";;
(apt)
Expand Down Expand Up @@ -466,7 +489,7 @@ function validate_deb() {
fi
fi

if { { [[ ' github website ' =~ " ${METHOD} " ]] && [ -s "${CACHE_FILE}" ]; } || [ "${METHOD}" == direct ]; } &&
if { { [[ ' github website gitlab ' =~ " ${METHOD} " ]] && [ -s "${CACHE_FILE}" ]; } || [ "${METHOD}" == direct ]; } &&
! [[ ' prettylist remove purge ' =~ " ${ACTION} " ]] &&
{ [ -z "${URL}" ] || [ -z "${VERSION_PUBLISHED}" ]; } &&
{ [ -z "${ARCHS_SUPPORTED}" ] || [[ " ${ARCHS_SUPPORTED} " =~ " ${HOST_ARCH} " ]]; } &&
Expand Down Expand Up @@ -568,16 +591,16 @@ cat <<"EOMSG"
| :------: | :------------- | :------------ |
EOMSG
for FULL_APP in "${APPS[@]}"; do
if validate_deb "${FULL_APP}"; then
if [ "${APP_SRC}" == "${REPO}" ] || { [ "${REPO}" == "01-main" ] && [ "${APP_SRC}" == "00-builtin" ]; }; then
case "${METHOD}" in
apt) ICON="debian.png";;
github) ICON="github.png";;
ppa) ICON="launchpad.png";;
*) ICON="direct.png";;
esac
echo "| [<img src=\"../.github/${ICON}\" align=\"top\" width=\"20\" />](${WEBSITE}) | "'`'"${APP}"'`'" | <i>${SUMMARY}</i> |"
fi
validate_deb "${FULL_APP}"
if [ "${APP_SRC}" == "${REPO}" ] || { [ "${REPO}" == "01-main" ] && [ "${APP_SRC}" == "00-builtin" ]; }; then
case "${METHOD}" in
apt) ICON="debian.png";;
github) ICON="github.png";;
gitlab) ICON="gitlab.png";;
ppa) ICON="launchpad.png";;
*) ICON="direct.png";;
esac
echo "| [<img src=\"../.github/${ICON}\" align=\"top\" width=\"20\" />](${WEBSITE}) | "'`'"${APP}"'`'" | <i>${SUMMARY}</i> |"
fi
done
}
Expand All @@ -597,12 +620,11 @@ function update_debs() {
local STATUS=""
update_apt
for APP in "${INSTALLED_APPS[@]}"; do
if validate_deb "${APPNAME2FULL[$APP]}"; then
if [ "${METHOD}" == "direct" ] || [ "${METHOD}" == "github" ] || [ "${METHOD}" == "website" ]; then
STATUS=$(dpkg-query -Wf '${Status}' "${APP}")
if [ "${STATUS}" == "install ok installed" ] && dpkg --compare-versions "${VERSION_PUBLISHED}" gt "${VERSION_INSTALLED}"; then
fancy_message info "${APP} (${VERSION_INSTALLED}) has an update pending. ${VERSION_PUBLISHED} is available."
fi
validate_deb "${APPNAME2FULL[$APP]}"
if [ "${METHOD}" == "direct" ] || [ "${METHOD}" == "github" ] || [ "${METHOD}" == "gitlab" ] || [ "${METHOD}" == "website" ]; then
STATUS=$(dpkg-query -Wf '${Status}' "${APP}")
if [ "${STATUS}" == "install ok installed" ] && dpkg --compare-versions "${VERSION_PUBLISHED}" gt "${VERSION_INSTALLED}"; then
fancy_message info "${APP} (${VERSION_INSTALLED}) has an update pending. ${VERSION_PUBLISHED} is available."
fi
fi
done
Expand All @@ -612,12 +634,11 @@ function upgrade_debs() {
local STATUS=""
upgrade_apt
for APP in "${INSTALLED_APPS[@]}"; do
if validate_deb "${APPNAME2FULL[$APP]}"; then
if [ "${METHOD}" == "direct" ] || [ "${METHOD}" == "github" ] || [ "${METHOD}" == "website" ]; then
STATUS=$(dpkg-query -Wf '${Status}' "${APP}")
if [ "${STATUS}" == "install ok installed" ]; then
install_deb "${URL}"
fi
validate_deb "${APPNAME2FULL[$APP]}"
if [ "${METHOD}" == "direct" ] || [ "${METHOD}" == "github" ]|| [ "${METHOD}" == "gitlab" ] || [ "${METHOD}" == "website" ]; then
STATUS=$(dpkg-query -Wf '${Status}' "${APP}")
if [ "${STATUS}" == "install ok installed" ]; then
install_deb "${URL}"
fi
fi
done
Expand Down Expand Up @@ -1386,7 +1407,7 @@ function dg_action_install() {
fi

case "${METHOD}" in
direct|github|website) install_deb "${URL}";;
direct|github|gitlab|website) install_deb "${URL}";;
apt) install_apt;;
ppa) install_ppa;;
esac
Expand Down

0 comments on commit ae36cad

Please sign in to comment.