forked from xmonad/xmonad-web
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_sponsors.sh
executable file
·99 lines (89 loc) · 2.43 KB
/
_sponsors.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env bash
set -eu -o pipefail
shopt -s lastpipe inherit_errexit
function o { printf -->&2 "%s:%s\\n" "${0##*/}" "$(printf " %q" "$@")"; "$@"; }
function gh-org-sponsors-tiers {
# shellcheck disable=SC2016
gh api graphql -F org="${1:?org}" -f query='
query Tiers($org: String!) {
organization(login: $org) {
... on Sponsorable {
sponsorsListing {
tiers(first: 100) {
nodes {
id
name
description
monthlyPriceInDollars
}
}
}
}
}
}
' --jq '.data.organization.sponsorsListing.tiers.nodes[]'
}
function gh-org-sponsors-at-tier {
# shellcheck disable=SC2016
gh api graphql --paginate -F org="${1:?org}" -F tier="${2:?tier}" -f query='
query Sponsors($endCursor: String, $org: String!, $tier: ID!) {
organization(login: $org) {
... on Sponsorable {
sponsors(first: 100, tierId: $tier, after: $endCursor) {
nodes {
... on User { login, name, url, websiteUrl }
... on Organization { login, name, url, websiteUrl }
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
}
' --jq '.data.organization.sponsors.nodes[]'
}
function gh-org-sponsors {
# shellcheck disable=SC2016
gh api graphql --paginate -F org="${1:?org}" -f query='
query Sponsors($endCursor: String, $org: String!) {
organization(login: $org) {
... on Sponsorable {
sponsors(first: 100, after: $endCursor) {
nodes {
... on User { login, name, url, websiteUrl }
... on Organization { login, name, url, websiteUrl }
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
}
' --jq '.data.organization.sponsors.nodes[]'
}
function jq-tierids-since {
jq --arg since "${1:?since}" -s -r 'until(.[0].description | contains($since); del(.[0])) | .[].id'
}
function jq-sort-by {
jq -s "sort_by(.${1:?key}) | .[]"
}
function jq-intersect-by {
jq --argjson filter "${2:?filter}" "select([.${1:?key}] | inside([\$filter[].${1:?key}]))"
}
function named-sponsors {
public_sponsors=$(o gh-org-sponsors "${1:?org}" | jq -s '')
GITHUB_TOKEN="${ADMIN_GITHUB_TOKEN:?}" o gh-org-sponsors-tiers "${1:?org}" | \
jq-tierids-since XMonad.Layout.Named | \
tac | \
while read -r tier; do
GITHUB_TOKEN="${ADMIN_GITHUB_TOKEN:?}" o gh-org-sponsors-at-tier "${1:?org}" "$tier" \
| jq-sort-by login
done | \
jq-intersect-by login "$public_sponsors" | \
jq -s ''
}
"$@"