From: Ruben Beltran del Rio Date: Thu, 26 Dec 2024 14:40:03 +0000 (+0100) Subject: Add swiftbar page X-Git-Url: https://git.r.bdr.sh/rbdr/r.bdr.sh/commitdiff_plain/a141dd00e8129ba1e75b56cfea96d4cacff0b154?ds=sidebyside Add swiftbar page --- diff --git a/swiftbar/sourcehut-builds.1m.sh b/swiftbar/sourcehut-builds.1m.sh new file mode 100644 index 0000000..6ad4340 --- /dev/null +++ b/swiftbar/sourcehut-builds.1m.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash +# This plugin allows you to see the latest sourcehut builds and their status. +# +# Sourcehut Builds +# v1.0.0 +# Rubén Beltrán del Río +# Shows the status of your latest builds in sourcehut. +# curl,jq +# https://r.bdr.sh/swiftbar_scripts.html +# string(VAR_SOURCEHUT_API_TOKEN): Your sourcehut API Token. +# number(VAR_BUILD_COUNT=5): How many items to show. +# true +# VAR_SOURCEHUT_API_TOKEN=no, VAR_BUILD_COUNT=5 + +############################################################################### +# The Variables +############################################################################### +VAR_SOURCEHUT_API_TOKEN=${VAR_SOURCEHUT_API_TOKEN:-'ADD YOUR TOKEN HERE'} +VAR_BUILD_COUNT=${VAR_BUILD_COUNT:-5} + +############################################################################### +# The Code +############################################################################### + +curl \ + --oauth2-bearer "$VAR_SOURCEHUT_API_TOKEN" \ + -H 'Content-Type: application/json' \ + -d '{"query": "query { me { canonicalName jobs { results { id created updated status note tags tasks { name status } } } } }"}' \ + https://builds.sr.ht/query 2>/dev/null | \ +jq -r --arg count "$VAR_BUILD_COUNT" --arg now "$(date +%s)" ' +.data.me.canonicalName as $id | +( + [.data.me.jobs.results[0:($count|tonumber)] | .[] | + select( + (($now|tonumber) - ((.created|sub("\\.[0-9]+Z$"; "Z")|fromdate|tostring)|tonumber)) < 900 and + .status == "FAILED" + )] | length +) as $failed_count | +( + [.data.me.jobs.results[0:($count|tonumber)] | .[] | + select( + (($now|tonumber) - ((.created|sub("\\.[0-9]+Z$"; "Z")|fromdate|tostring)|tonumber)) < 900 and + .status == "SUCCESS" + )] | length +) as $success_count | +( + [.data.me.jobs.results[0:($count|tonumber)] | .[] | + select( + (($now|tonumber) - ((.created|sub("\\.[0-9]+Z$"; "Z")|fromdate|tostring)|tonumber)) < 900 and + .status == "RUNNING" + )] | length +) as $running_count | + ( + ":gearshape.arrow.trianglehead.2.clockwise.rotate.90:" + + (if $success_count > 0 then ":checkmark:\($success_count) " else "" end) + + (if $failed_count > 0 then ":xmark:\($failed_count) " else "" end) + + (if $running_count > 0 then ":play.circle: \($running_count) " else "" end) + ), + ("---"), + (.data.me.jobs.results[0:($count|tonumber)] | .[] | ( + if .status == "PENDING" then ":circle.dotted:" + elif .status == "QUEUED" then ":circle:" + elif .status == "RUNNING" then ":play.circle:" + elif .status == "SUCCESS" then ":checkmark:" + elif .status == "FAILED" then ":xmark:" + elif .status == "TIMEOUT" then ":clock.badge.xmark:" + elif .status == "CANCELLED" then ":circle.slash:" + else "?" end + ) + " " + $id + "/" + .tags[0] + " (" + (.id|tostring) + ") " + ( + [.tasks[] | + if .status == "PENDING" then ":circle.dotted:" + elif .status == "RUNNING" then ":play.circle:" + elif .status == "SUCCESS" then ":checkmark:" + elif .status == "FAILED" then ":xmark:" + elif .status == "SKIPPED" then ":circle.slash:" + else "?" end + ] | join("") + ) + " | href=https://builds.sr.ht/" + $id +"/job/" + (.id|tostring) + " tooltip=\"" + ( + [.tasks[] | .name + ": " + .status] | join(", ") + ) + "\"")' diff --git a/swiftbar_scripts.gmi b/swiftbar_scripts.gmi new file mode 100644 index 0000000..1e2bb80 --- /dev/null +++ b/swiftbar_scripts.gmi @@ -0,0 +1,22 @@ +## SwiftBar Scripts + +This page holds the SwiftBar[1] / xbar scripts I've made. Since I use the first +one, I'm not sure whether they work with xbar[2], but should probably be OK. + +=> https://swiftbar.app/ [1] SwiftBar +=> https://xbarapp.com/ [2] Xbar + +## I. +### Sourcehut Builds + +View the status of your last few builds in sourcehut. You can open the URL by +clicking on the menu items. +The count of failed, pending and successful runs of the last 15m are shown +next to the icon. + +To use the plugin you'll need to set your sourcehut token in the +VAR_SOURCEHUT_API_TOKEN variable (See the 'ADD YOUR TOKEN HERE' string). You +can also control how many builds to show by changing the VAR_BUILD_COUNT +variable (defaults to 5) + +=> ./swiftbar/sourcehut-builds.1m.sh ⧇ source