1+ name : Knowledge Keeper Structured Commits
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+
8+ jobs :
9+ send-diff-metadata :
10+ runs-on : ubuntu-latest
11+ steps :
12+ - uses : actions/checkout@v3
13+ with :
14+ fetch-depth : 0
15+
16+ - name : Install jq
17+ run : sudo apt-get update && sudo apt-get install -y jq
18+
19+ - name : Send structured commit metadata to webhook
20+ run : |
21+ echo "🔄 Generating structured commit diff payload..."
22+
23+ payload='{"connection_type": "GITHUB", "repository_connection_id": 23, "source_data": ['
24+ sep=""
25+
26+ set +e
27+ shas=$(git rev-list --no-merges "${{ github.event.before }}..${{ github.event.after }}" 2>/dev/null)
28+ set -e
29+
30+ if [ -z "$shas" ]; then
31+ echo "⚠️ Empty or invalid revision range. Falling back to last 5 commits."
32+ shas=$(git rev-list -n 5 HEAD)
33+ fi
34+
35+ for sha in $shas; do
36+ commit_msg=$(git log -1 --pretty=format:"%s" "$sha")
37+ file_changes="[]"
38+
39+ while IFS=$'\t' read -r added removed file; do
40+ [ -z "$file" ] && continue
41+
42+ if [ "$added" -eq 0 ] && [ "$removed" -gt 0 ]; then
43+ change_type="deleted"
44+ elif [ "$removed" -eq 0 ] && [ "$added" -gt 0 ]; then
45+ change_type="added"
46+ else
47+ change_type="modified"
48+ fi
49+
50+ summary="$file: $added additions, $removed deletions"
51+
52+ if [ "$change_type" != "deleted" ]; then
53+ diff_info=$(git diff --unified=1 "$sha^" "$sha" -- "$file" | grep -v "^@@" | grep -v "^index" | grep -v "^diff" | grep -v "^---" | grep -v "^+++")
54+ if [ -n "$diff_info" ]; then
55+ diff_info_escaped=$(echo "$diff_info" | jq -Rs .)
56+ else
57+ diff_info_escaped="\"\""
58+ fi
59+ else
60+ diff_info_escaped="\"\""
61+ fi
62+
63+ file_change=$(jq -n --arg path "$file" --arg type "$change_type" --arg added "$added" --arg removed "$removed" --arg summary "$summary" --argjson changes "$diff_info_escaped" '{
64+ file_path: $path,
65+ change_type: $type,
66+ additions: ($added | tonumber? // 0),
67+ deletions: ($removed | tonumber? // 0),
68+ diff_summary: $summary,
69+ changes_preview: $changes
70+ }')
71+
72+ file_changes=$(echo "$file_changes" | jq ". + [$file_change]")
73+ done < <(git show --numstat --oneline "$sha")
74+
75+ commit_block=$(jq -n --arg id "$sha" --arg msg "$commit_msg" --argjson files "$file_changes" '{
76+ commit_message: $msg,
77+ commit_id: $id,
78+ file_changes: $files
79+ }')
80+
81+ payload="${payload}${sep}${commit_block}"
82+ sep=","
83+ done
84+
85+ payload="${payload}]}"
86+ echo "✅ Final Payload:"
87+ echo "$payload" | jq .
88+
89+ curl -X POST https://api-core.knowledgekeeper.ai/api/v1/webhooks/git \
90+ -H "x-api-key: 6234a77c99776de3278615469b9e9960d3153a51b49b8fdabd7b9b897e3f30d0" \
91+ -H "Content-Type: application/json" \
92+ -d "$payload"
93+
0 commit comments