this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ci(ts): keep json schema event enum in sync

+85 -5
+1 -1
.gitlab-ci.yml
··· 33 33 - just gen_typescript 34 34 script: 35 35 - | 36 - for file in typescript/*.ts; do 36 + for file in {events.go,typescript/*.ts}; do 37 37 if ! diff -q $file typescript_original/$(basename $file); then 38 38 diff typescript_original/$(basename $file) $file 39 39 echo "Generated file $file is different from original, please run 'just gen_typescript' and commit the changes"
+4 -3
Justfile
··· 22 22 sed -i '/^generator .* {/,/^}/d' schema.prisma 23 23 sed -i '1i\ 24 24 generator goprisma {\n\ 25 - provider = "go run github.com/steebchen/prisma-client-go"\n\ 25 + provider = "go run github.com/steebchen/prisma-client-go"\n\ 26 26 previewFeatures = ["fullTextSearchPostgres", "postgresqlExtensions"]\n\ 27 27 }\ 28 28 ' schema.prisma ··· 30 30 31 31 32 32 genprisma: 33 - go get github.com/steebchen/prisma-client-go 34 - go run github.com/steebchen/prisma-client-go generate 33 + go get github.com/steebchen/prisma-client-go 34 + go run github.com/steebchen/prisma-client-go generate 35 35 36 36 gen_typescript: 37 + bash scripts/sync-event-enum.sh 37 38 go run scripts/typing.go 38 39 39 40 generate:
+2 -1
events.go
··· 35 35 // When to push the notification 36 36 SendAt time.Time `json:"send_at"` 37 37 // Type of event that triggered the notification 38 - Event Event `json:"event" jsonschema:"enum=save_schedule,enum=clear_schedule,enum=clear_stored_schedule,enum=restore_schedule,enum=restore_schedule_eager,enum=clear_scheduled_jobs,enum=show_scheduled_jobs,enum=new_post,enum=godchild_request,enum=new_comment,enum=comment_reply,enum=custom,enum=test,enum=godchild_accepted,enum=godchild_rejected,enum=pending_signup,enum=login_stuck,enum=booking_paid,enum=contribution_paid,enum=shotgun_opens_soon,enum=shotgun_closes_soon"` 38 + // next-line-generate event-enum-jsonschema-values 39 + Event Event `json:"event" jsonschema:"enum=clear_scheduled_jobs,enum=clear_stored_schedule,enum=show_scheduled_jobs,enum=save_schedule,enum=restore_schedule,enum=restore_schedule_eager,enum=clear_schedule,enum=new_post,enum=godchild_request,enum=custom,enum=test,enum=godchild_accepted,enum=godchild_rejected,enum=pending_signup,enum=login_stuck,enum=booking_paid,enum=contribution_paid,enum=shotgun_opens_soon,enum=shotgun_closes_soon"` 39 40 // Churros ID of the ressource (the ticket, the post, the comment, etc) 40 41 // Used to determine to whom the notification should be sent 41 42 // For godchild_request, this is not a user id, but a godparent request id.
+78
scripts/sync-event-enum.sh
··· 1 + #!/bin/bash 2 + 3 + # Exit on any error 4 + set -e 5 + 6 + # Function to extract event constants from Go file within the same const block 7 + extract_events() { 8 + local file="$1" 9 + # Create a temporary file to store the const block 10 + local tempfile=$(mktemp) 11 + 12 + # Extract the const block containing Event definitions 13 + awk '/^const \($/ {p=1;next} /^\)$/ {p=0} p' "$file" > "$tempfile" 14 + 15 + # Extract event values from the const block 16 + grep -o 'Event = "[^"]*"' "$tempfile" | cut -d'"' -f2 | tr '\n' '=' | sed 's/=$//' | sed 's/=/,enum=/g' 17 + 18 + # Clean up 19 + rm "$tempfile" 20 + } 21 + 22 + # Function to update JSON schema in Go file 23 + update_schema() { 24 + local file="$1" 25 + local events="$2" 26 + 27 + # Create temporary file 28 + local tempfile=$(mktemp) 29 + 30 + # Flag to track if we found the generate comment 31 + local next_line_update=0 32 + 33 + # Process the file line by line 34 + while IFS= read -r line; do 35 + if [ $next_line_update -eq 1 ]; then 36 + # Update the line after the comment 37 + echo "$line" | sed "s/jsonschema:\"enum=[^\"]*\"/jsonschema:\"enum=$events\"/" >> "$tempfile" 38 + next_line_update=0 39 + elif [[ $line =~ "next-line-generate event-enum-jsonschema-values" ]]; then 40 + # Mark the next line for update 41 + echo "$line" >> "$tempfile" 42 + next_line_update=1 43 + else 44 + echo "$line" >> "$tempfile" 45 + fi 46 + done < "$file" 47 + 48 + # Replace original file with updated content 49 + mv "$tempfile" "$file" 50 + } 51 + 52 + # Main script 53 + main() { 54 + local file="${1:-events.go}" # Default to events.go if no file specified 55 + 56 + if [ ! -f "$file" ]; then 57 + echo "Error: File $file not found" 58 + exit 1 59 + fi 60 + 61 + echo "Processing $file..." 62 + 63 + # Extract events and update schema 64 + local events=$(extract_events "$file") 65 + 66 + if [ -z "$events" ]; then 67 + echo "Error: No events found in const block" 68 + exit 1 69 + fi 70 + 71 + update_schema "$file" "$events" 72 + 73 + echo "Successfully updated JSON schema enum values" 74 + echo "New values: $events" 75 + } 76 + 77 + # Run the script 78 + main "$@"