mirror of
https://github.com/chenasraf/gitlab-search-alfred-workflow.git
synced 2026-05-17 17:48:01 +00:00
31 lines
769 B
Bash
Executable File
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
|