Files
gitlab-search-alfred-workflow/search
2023-02-27 13:14:48 +02:00

31 lines
769 B
Bash
Executable File

#!/usr/bin/env bash
API_BASE="https://gitlab.com/api/v4"
SCOPE="groups"
ID="$GROUP"
if [[ -z "$GROUP" ]]; then
SCOPE="users"
ID=$(curl "$API_BASE/user" | jq '.id')
fi
if [[ -z $(which jq) ]]; then
echo '{"items":[{"title":"Please install jq","subtitle":"Select this to open instructions","arg":"https://stedolan.github.io/jq/download/"}]}'
else
if [[ ! -d ".cache" ]]; then
mkdir .cache
fi
query=$1
hash=$(echo $query | md5 -q)
fl=".cache/projects-$hash.json"
if [[ ! -f $fl ]]; then
url="$API_BASE/$SCOPE/$ID/projects?private_token=$TOKEN&include_subgroups=true&per_page=20&search=$query"
curl $url >$fl
fi
jq 'map({title: ["Open Project: ",.path] | join(""), subtitle: .path_with_namespace, arg:.web_url}) | {items:.}' $fl
fi