Skip to content

Commit 71873c8

Browse files
committed
feat: add shell script to find OpenProject configuration values
Add find-config.sh bash script that: - Tests OpenProject API token authentication - Finds backend project ID automatically - Lists all work package types with IDs - Discovers custom field IDs - Lists users for assignee mapping - Shows all available statuses Users need to replace OP_TOKEN placeholder with their actual token and run the script on their local machine.
1 parent 27b1fa0 commit 71873c8

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

find-config.sh

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/bin/bash
2+
3+
# OpenProject Configuration Finder
4+
# Run this script on your LOCAL machine (not the service environment)
5+
6+
set -e
7+
8+
OP_TOKEN="YOUR_OPENPROJECT_TOKEN_HERE"
9+
OP_URL="https://op.stoatinternal.com"
10+
AUTH_HEADER="Authorization: Basic $(echo -n "apikey:${OP_TOKEN}" | base64)"
11+
12+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
13+
echo "OpenProject Configuration Finder"
14+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
15+
echo ""
16+
17+
# Test authentication
18+
echo "1. Testing API Token..."
19+
if ! curl -s -H "$AUTH_HEADER" "$OP_URL/api/v3/projects" > /dev/null 2>&1; then
20+
echo "❌ Token authentication failed!"
21+
echo "Please check that the token is valid and has API access."
22+
exit 1
23+
fi
24+
echo "✅ Token is valid!"
25+
echo ""
26+
27+
# Find backend project
28+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
29+
echo "2. Finding Backend Project ID"
30+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
31+
PROJECT_INFO=$(curl -s -H "$AUTH_HEADER" "$OP_URL/api/v3/projects/backend")
32+
PROJECT_ID=$(echo "$PROJECT_INFO" | jq -r '.id')
33+
PROJECT_NAME=$(echo "$PROJECT_INFO" | jq -r '.name')
34+
echo "✅ Project ID: $PROJECT_ID"
35+
echo " Name: $PROJECT_NAME"
36+
echo ""
37+
echo "📝 REPO_PROJECT_MAP=stoatchat/stoatchat:$PROJECT_ID"
38+
echo ""
39+
40+
# Find types
41+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
42+
echo "3. Finding Work Package Types"
43+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
44+
TYPES=$(curl -s -H "$AUTH_HEADER" "$OP_URL/api/v3/types")
45+
echo "✅ Available Types:"
46+
echo "$TYPES" | jq -r '._embedded.elements[] | " \(.id): \(.name)"'
47+
echo ""
48+
49+
# Build TYPE_MAP
50+
BUG_ID=$(echo "$TYPES" | jq -r '._embedded.elements[] | select(.name | ascii_downcase == "bug") | .id' | head -1)
51+
TASK_ID=$(echo "$TYPES" | jq -r '._embedded.elements[] | select(.name | ascii_downcase == "task") | .id' | head -1)
52+
FEATURE_ID=$(echo "$TYPES" | jq -r '._embedded.elements[] | select(.name | ascii_downcase == "feature") | .id' | head -1)
53+
54+
TYPE_MAP=""
55+
[[ -n "$BUG_ID" ]] && TYPE_MAP="${TYPE_MAP}Bug:${BUG_ID},"
56+
[[ -n "$TASK_ID" ]] && TYPE_MAP="${TYPE_MAP}Task:${TASK_ID},"
57+
[[ -n "$FEATURE_ID" ]] && TYPE_MAP="${TYPE_MAP}Feature:${FEATURE_ID},"
58+
TYPE_MAP=${TYPE_MAP%,} # Remove trailing comma
59+
60+
echo "📝 TYPE_MAP=$TYPE_MAP"
61+
echo ""
62+
63+
# Find custom fields
64+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
65+
echo "4. Finding Custom Fields"
66+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
67+
68+
# Get a work package to inspect custom fields
69+
WP=$(curl -s -H "$AUTH_HEADER" "$OP_URL/api/v3/work_packages?pageSize=1")
70+
if echo "$WP" | jq -e '._embedded.elements[0]' > /dev/null 2>&1; then
71+
echo "✅ Found custom fields:"
72+
CUSTOM_FIELDS=$(echo "$WP" | jq -r '._embedded.elements[0] | keys[] | select(startswith("customField"))')
73+
74+
if [ -n "$CUSTOM_FIELDS" ]; then
75+
echo "$CUSTOM_FIELDS" | while read -r field; do
76+
VALUE=$(echo "$WP" | jq -r "._embedded.elements[0].${field}")
77+
echo " $field: $VALUE"
78+
done
79+
echo ""
80+
echo "📝 Look for the 'GitHub Issue' field above"
81+
echo " (It should be an integer field, likely null or containing a GitHub issue number)"
82+
echo ""
83+
84+
# Try to guess which one
85+
FIRST_FIELD=$(echo "$CUSTOM_FIELDS" | head -1)
86+
echo " If unsure, try: OP_GITHUB_ISSUE_FIELD=$FIRST_FIELD"
87+
else
88+
echo "⚠️ No custom fields found"
89+
echo " You'll need to create a 'GitHub Issue' integer custom field in OpenProject"
90+
fi
91+
else
92+
echo "⚠️ No work packages found to inspect"
93+
echo " Create a work package first, or manually find the custom field ID"
94+
fi
95+
echo ""
96+
97+
# Find users
98+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
99+
echo "5. Finding Users (for ASSIGNEE_MAP)"
100+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
101+
USERS=$(curl -s -H "$AUTH_HEADER" "$OP_URL/api/v3/users")
102+
echo "✅ Available Users (first 10):"
103+
echo "$USERS" | jq -r '._embedded.elements[0:10][] | " \(.id): \(.login) (\(.firstName) \(.lastName))"'
104+
echo ""
105+
echo "📝 Map GitHub usernames to these IDs"
106+
echo " Example: ASSIGNEE_MAP=insertish:42,githubuser:43"
107+
echo ""
108+
109+
# Find statuses
110+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
111+
echo "6. Finding Statuses"
112+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
113+
STATUSES=$(curl -s -H "$AUTH_HEADER" "$OP_URL/api/v3/statuses")
114+
echo "✅ Available Statuses:"
115+
echo "$STATUSES" | jq -r '._embedded.elements[] | " \(.id): \(.name)"'
116+
echo ""
117+
118+
# Summary
119+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
120+
echo "✅ Configuration Discovery Complete!"
121+
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
122+
echo ""
123+
echo "Update your .env file with these values:"
124+
echo ""
125+
echo "REPO_PROJECT_MAP=stoatchat/stoatchat:$PROJECT_ID"
126+
echo "TYPE_MAP=$TYPE_MAP"
127+
echo "OP_GITHUB_ISSUE_FIELD=(see custom fields above)"
128+
echo "ASSIGNEE_MAP=(map your GitHub usernames to OpenProject user IDs above)"
129+
echo ""
130+
echo "Don't forget to generate a SECRET_TOKEN:"
131+
echo " openssl rand -hex 32"
132+
echo ""

0 commit comments

Comments
 (0)