-
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathpulls.sh
More file actions
executable file
·55 lines (46 loc) · 1.08 KB
/
pulls.sh
File metadata and controls
executable file
·55 lines (46 loc) · 1.08 KB
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
#!/bin/bash
source "$(dirname "$0")/setup.sh"
repo=$1
empty_result='{"items":[]}'
if [[ -z "$repo" || ! "$repo" =~ ^[a-zA-Z0-9._-]+/[a-zA-Z0-9._-]+$ ]]; then
printf '%s' "$empty_result"
exit 0
fi
repo_url="https://$API_HOST/$repo"
item=$(
cat <<'EOF'
{
title: "PR #\(.number): \(.title)",
subtitle: "Open \(.html_url)",
arg: .html_url,
text:{
copy: .html_url
}
}
EOF
)
err=$(mktemp) || {
printf '%s' "$empty_result"
exit 0
}
pulls=$(gh api "/repos/$repo/pulls" --method GET \
-F per_page=9 \
--hostname "$API_HOST" \
--cache "$CACHE_PULLS" \
--jq "[.[] | $item]" 2>"$err")
gh_exit=$?
err_msg=$(<"$err")
rm -f "$err"
if [[ $gh_exit -ne 0 ]]; then
if [[ -n "$err_msg" ]]; then
printf '%s\n' "$err_msg" >&2
fi
pulls="[]"
fi
if [[ -z "$pulls" ]]; then
pulls="[]"
fi
# Build final JSON: prepend the "Open pull requests page" item, then append PR items
printf '%s' "$pulls" | jq -c --arg url "$repo_url/pulls" \
'{items: ([{title: "Open pull requests page", subtitle: ("Open " + $url), arg: $url}] + .)}' \
2>/dev/null || printf '%s' "$empty_result"