Rename the `rails/` directory to `tools/` for agent discoverability — agents frequently failed to locate helper scripts due to the non-intuitive directory name. Add backward-compat symlink `rails/ → tools/`. New tool suites: - Authentik: auth-token, user-list, user-create, group-list, app-list, flow-list, admin-status (8 scripts) - Coolify: team-list, project-list, service-list, service-status, deploy, env-set (7 scripts) - Woodpecker: pipeline-list, pipeline-status, pipeline-trigger (3 stubs) - GLPI: session-init, computer-list, ticket-list, ticket-create, user-list (6 scripts) - Health: stack-health.sh — stack-wide connectivity check Infrastructure: - Shared credential loader at tools/_lib/credentials.sh - install.sh creates symlink + chmod on tool scripts - All ~253 rails/ path references updated across 68+ files Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
115 lines
3.4 KiB
Bash
Executable File
115 lines
3.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# pr-metadata.sh - Get PR metadata as JSON on GitHub or Gitea
|
|
# Usage: pr-metadata.sh -n <pr_number> [-o <output_file>]
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR/detect-platform.sh"
|
|
|
|
# Parse arguments
|
|
PR_NUMBER=""
|
|
OUTPUT_FILE=""
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
-n|--number)
|
|
PR_NUMBER="$2"
|
|
shift 2
|
|
;;
|
|
-o|--output)
|
|
OUTPUT_FILE="$2"
|
|
shift 2
|
|
;;
|
|
-h|--help)
|
|
echo "Usage: pr-metadata.sh -n <pr_number> [-o <output_file>]"
|
|
echo ""
|
|
echo "Options:"
|
|
echo " -n, --number PR number (required)"
|
|
echo " -o, --output Output file (optional, prints to stdout if omitted)"
|
|
echo " -h, --help Show this help"
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo "Unknown option: $1"
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [[ -z "$PR_NUMBER" ]]; then
|
|
echo "Error: PR number is required (-n)" >&2
|
|
exit 1
|
|
fi
|
|
|
|
detect_platform > /dev/null
|
|
|
|
if [[ "$PLATFORM" == "github" ]]; then
|
|
METADATA=$(gh pr view "$PR_NUMBER" --json number,title,body,state,author,headRefName,baseRefName,files,labels,assignees,milestone,createdAt,updatedAt,url,isDraft)
|
|
|
|
if [[ -n "$OUTPUT_FILE" ]]; then
|
|
echo "$METADATA" > "$OUTPUT_FILE"
|
|
else
|
|
echo "$METADATA"
|
|
fi
|
|
elif [[ "$PLATFORM" == "gitea" ]]; then
|
|
OWNER=$(get_repo_owner)
|
|
REPO=$(get_repo_name)
|
|
REMOTE_URL=$(git remote get-url origin 2>/dev/null)
|
|
|
|
# Extract host from remote URL
|
|
if [[ "$REMOTE_URL" == https://* ]]; then
|
|
HOST=$(echo "$REMOTE_URL" | sed -E 's|https://([^/]+)/.*|\1|')
|
|
elif [[ "$REMOTE_URL" == git@* ]]; then
|
|
HOST=$(echo "$REMOTE_URL" | sed -E 's|git@([^:]+):.*|\1|')
|
|
else
|
|
echo "Error: Cannot determine host from remote URL" >&2
|
|
exit 1
|
|
fi
|
|
|
|
API_URL="https://${HOST}/api/v1/repos/${OWNER}/${REPO}/pulls/${PR_NUMBER}"
|
|
|
|
# Use tea's auth token if available
|
|
TEA_TOKEN=$(tea login list 2>/dev/null | grep "$HOST" | awk '{print $NF}' || true)
|
|
|
|
if [[ -n "$TEA_TOKEN" ]]; then
|
|
RAW=$(curl -sS -H "Authorization: token $TEA_TOKEN" "$API_URL")
|
|
else
|
|
RAW=$(curl -sS "$API_URL")
|
|
fi
|
|
|
|
# Normalize Gitea response to match our expected schema
|
|
METADATA=$(echo "$RAW" | python3 -c "
|
|
import json, sys
|
|
data = json.load(sys.stdin)
|
|
normalized = {
|
|
'number': data.get('number'),
|
|
'title': data.get('title'),
|
|
'body': data.get('body', ''),
|
|
'state': data.get('state'),
|
|
'author': data.get('user', {}).get('login', ''),
|
|
'headRefName': data.get('head', {}).get('ref', ''),
|
|
'baseRefName': data.get('base', {}).get('ref', ''),
|
|
'labels': [l.get('name', '') for l in data.get('labels', [])],
|
|
'assignees': [a.get('login', '') for a in data.get('assignees', [])],
|
|
'milestone': data.get('milestone', {}).get('title', '') if data.get('milestone') else '',
|
|
'createdAt': data.get('created_at', ''),
|
|
'updatedAt': data.get('updated_at', ''),
|
|
'url': data.get('html_url', ''),
|
|
'isDraft': data.get('draft', False),
|
|
'mergeable': data.get('mergeable'),
|
|
'diffUrl': data.get('diff_url', ''),
|
|
}
|
|
json.dump(normalized, sys.stdout, indent=2)
|
|
")
|
|
|
|
if [[ -n "$OUTPUT_FILE" ]]; then
|
|
echo "$METADATA" > "$OUTPUT_FILE"
|
|
else
|
|
echo "$METADATA"
|
|
fi
|
|
else
|
|
echo "Error: Unknown platform" >&2
|
|
exit 1
|
|
fi
|