Compare commits

..

1 Commits

Author SHA1 Message Date
agent-company 02a108a58e fix: add pull_request trigger to CI workflow so tests gate all PRs
Build and Push / test (pull_request) Successful in 3m33s
Build and Push / build (pull_request) Has been skipped
The CI workflow previously only triggered on push to master, meaning PRs
were not tested before merge. Add pull_request trigger for the test job
while restricting the Docker build+push job to push events only.

Closes leeworks-agents/gitea-mobile#204

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-20 15:04:58 +00:00
2 changed files with 6 additions and 22 deletions
+4
View File
@@ -4,6 +4,9 @@ on:
push: push:
branches: branches:
- master - master
pull_request:
branches:
- master
jobs: jobs:
test: test:
@@ -24,6 +27,7 @@ jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: test needs: test
if: gitea.event_name == 'push'
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
+2 -22
View File
@@ -1,8 +1,6 @@
package middleware package middleware
import ( import (
"crypto/rand"
"encoding/hex"
"log/slog" "log/slog"
"net/http" "net/http"
"time" "time"
@@ -19,39 +17,21 @@ func (rw *responseWriter) WriteHeader(code int) {
rw.ResponseWriter.WriteHeader(code) rw.ResponseWriter.WriteHeader(code)
} }
// generateRequestID creates a short random hex string for request tracing. // Logging returns middleware that logs each HTTP request with structured logging.
func generateRequestID() string {
b := make([]byte, 8)
if _, err := rand.Read(b); err != nil {
return "unknown"
}
return hex.EncodeToString(b)
}
// Logging returns middleware that logs each HTTP request with structured fields:
// method, path, status, duration (ms), request-id, and remote address.
func Logging() func(http.Handler) http.Handler { func Logging() func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler { return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now() start := time.Now()
requestID := generateRequestID()
rw := &responseWriter{ResponseWriter: w, statusCode: http.StatusOK} rw := &responseWriter{ResponseWriter: w, statusCode: http.StatusOK}
// Set request ID header for downstream correlation.
w.Header().Set("X-Request-ID", requestID)
next.ServeHTTP(rw, r) next.ServeHTTP(rw, r)
duration := time.Since(start)
slog.Info("http request", slog.Info("http request",
"method", r.Method, "method", r.Method,
"path", r.URL.Path, "path", r.URL.Path,
"status", rw.statusCode, "status", rw.statusCode,
"duration_ms", duration.Milliseconds(), "duration", time.Since(start).String(),
"duration", duration.String(),
"request_id", requestID,
"remote", r.RemoteAddr, "remote", r.RemoteAddr,
"user_agent", r.UserAgent(),
) )
}) })
} }