]>
git.r.bdr.sh - rbdr/r.bdr.sh/blob - swiftbar/sourcehut-builds.1m.sh
f62324d4e5b58a31f8b2735e299691ca9f0add01
2 # This plugin allows you to see the latest sourcehut builds and their status.
4 # <xbar.title>Sourcehut Builds</xbar.title>
5 # <xbar.version>v1.0.0</xbar.version>
6 # <xbar.author>Rubén Beltrán del Río</xbar.author>
7 # <xbar.desc>Shows the status of your latest builds in sourcehut.</xbar.desc>
8 # <xbar.dependencies>curl,jq</xbar.dependencies>
9 # <xbar.abouturl>https://r.bdr.sh/swiftbar_scripts.html</xbar.abouturl>
10 # <xbar.var>string(VAR_SOURCEHUT_API_TOKEN): Your sourcehut API Token.</xbar.var>
11 # <xbar.var>number(VAR_BUILD_COUNT=10): How many items to show.</xbar.var>
12 # <swiftbar.hideRunInTerminal>true</swiftbar.hideRunInTerminal>
13 # <swiftbar.environment>VAR_SOURCEHUT_API_TOKEN=no, VAR_BUILD_COUNT=10</swiftbar.environment>
15 ###############################################################################
17 ###############################################################################
18 VAR_SOURCEHUT_API_TOKEN
=${VAR_SOURCEHUT_API_TOKEN:-'ADD YOUR TOKEN HERE'}
19 VAR_BUILD_COUNT
=${VAR_BUILD_COUNT:-10}
21 ###############################################################################
23 ###############################################################################
26 --oauth2-bearer "$VAR_SOURCEHUT_API_TOKEN" \
27 -H 'Content-Type: application/json' \
28 -d '{"query": "query { me { canonicalName jobs { results { id created updated status note tags tasks { name status } } } } }"}' \
29 https
://builds.sr.ht
/query
2>/dev
/null
| \
30 jq
-r --arg count
"$VAR_BUILD_COUNT" --arg now
"$(date +%s)" '
31 .data.me.canonicalName as $id |
33 [.data.me.jobs.results[0:($count|tonumber)] | .[] |
35 (($now|tonumber) - ((.created|sub("\\.[0-9]+Z$"; "Z")|fromdate|tostring)|tonumber)) < 900 and
40 [.data.me.jobs.results[0:($count|tonumber)] | .[] |
42 (($now|tonumber) - ((.created|sub("\\.[0-9]+Z$"; "Z")|fromdate|tostring)|tonumber)) < 900 and
47 [.data.me.jobs.results[0:($count|tonumber)] | .[] |
49 (($now|tonumber) - ((.created|sub("\\.[0-9]+Z$"; "Z")|fromdate|tostring)|tonumber)) < 900 and
54 ":gearshape.arrow.trianglehead.2.clockwise.rotate.90:" +
55 (if $success_count > 0 then ":checkmark:\($success_count) " else "" end) +
56 (if $failed_count > 0 then ":xmark:\($failed_count) " else "" end) +
57 (if $running_count > 0 then ":play.circle: \($running_count) " else "" end)
60 (.data.me.jobs.results[0:($count|tonumber)] | .[] | (
61 if .status == "PENDING" then ":circle.dotted:"
62 elif .status == "QUEUED" then ":circle:"
63 elif .status == "RUNNING" then ":play.circle:"
64 elif .status == "SUCCESS" then ":checkmark:"
65 elif .status == "FAILED" then ":xmark:"
66 elif .status == "TIMEOUT" then ":clock.badge.xmark:"
67 elif .status == "CANCELLED" then ":circle.slash:"
69 ) + " " + $id + "/" + .tags[0] + " (" + (.id|tostring) + ") " + (
71 if .status == "PENDING" then ":circle.dotted:"
72 elif .status == "RUNNING" then ":play.circle:"
73 elif .status == "SUCCESS" then ":checkmark:"
74 elif .status == "FAILED" then ":xmark:"
75 elif .status == "SKIPPED" then ":circle.slash:"
78 ) + " | href=https://builds.sr.ht/" + $id +"/job/" + (.id|tostring) + " tooltip=\"" + (
79 [.tasks[] | .name + ": " + .status] | join(", ")