-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathapi_check_lockfile
More file actions
executable file
·43 lines (36 loc) · 1.21 KB
/
api_check_lockfile
File metadata and controls
executable file
·43 lines (36 loc) · 1.21 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
#!/usr/bin/env bash
# Hit the API lockfile endpoints with curl.
#
# Usage:
# bin/api_check_lockfile <Gemfile.lock> # POST and print { slug, retry_after_seconds, ... }
# bin/api_check_lockfile --show <slug> # GET /lockfiles/:slug as JSON
#
# Override host with API_HOST (default: api.localhost:3000):
# API_HOST=api.railsbump.org bin/api_check_lockfile Gemfile.lock
#
# Scheme auto-selects: https for api.railsbump.org, http for localhost.
# Override with API_SCHEME if needed.
set -euo pipefail
HOST="${API_HOST:-api.localhost:3000}"
case "$HOST" in
*localhost*|127.0.0.1*) DEFAULT_SCHEME="http" ;;
*) DEFAULT_SCHEME="https" ;;
esac
SCHEME="${API_SCHEME:-$DEFAULT_SCHEME}"
BASE="${SCHEME}://${HOST}"
usage() {
sed -n '2,/^$/p' "$0" >&2
exit 1
}
[[ $# -ge 1 ]] || usage
if [[ "$1" == "--show" ]]; then
[[ $# -eq 2 ]] || usage
curl -sS "${BASE}/lockfiles/$2" | jq .
exit 0
fi
LOCKFILE="$1"
[[ -f "$LOCKFILE" ]] || { echo "Not a file: $LOCKFILE" >&2; exit 1; }
command -v jq >/dev/null || { echo "jq required" >&2; exit 1; }
curl -sS -X POST "${BASE}/lockfiles" \
-H 'Content-Type: application/json' \
--data-binary "$(jq -Rs '{lockfile: {content: .}}' < "$LOCKFILE")" | jq .