Files
gastown/internal/mq/id.go
Steve Yegge 34b5a3bb8d Document intentional error suppressions with comments (gt-zn9m)
All 156 instances of _ = error suppression in non-test code now have
explanatory comments documenting why the error is intentionally ignored.

Categories of intentional suppressions:
- non-fatal: session works without these - tmux environment setup
- non-fatal: theming failure does not affect operation - visual styling
- best-effort cleanup - defer cleanup on failure paths
- best-effort notification - mail/notifications that should not block
- best-effort interrupt - graceful shutdown attempts
- crypto/rand.Read only fails on broken system - random ID generation
- output errors non-actionable - fmt.Fprint to io.Writer

This addresses the silent failure and debugging concerns raised in the
issue by making the intentionality explicit in the code.

Generated with Claude Code https://claude.com/claude-code

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 23:14:29 -08:00

50 lines
1.8 KiB
Go

// Package mq provides merge queue functionality.
package mq
import (
"crypto/rand"
"crypto/sha256"
"encoding/hex"
"fmt"
"time"
)
// GenerateMRID generates a merge request ID following the convention: <prefix>-mr-<hash>
//
// The hash is derived from the branch name + current timestamp + random bytes to ensure uniqueness.
// Example: gt-mr-abc123 for a gastown merge request.
//
// Parameters:
// - prefix: The project prefix (e.g., "gt" for gastown)
// - branch: The source branch name (e.g., "polecat/Nux/gt-xyz")
//
// Returns a string in the format "<prefix>-mr-<6-char-hash>"
func GenerateMRID(prefix, branch string) string {
// Generate 8 random bytes for additional uniqueness
randomBytes := make([]byte, 8)
_, _ = rand.Read(randomBytes) // crypto/rand.Read only fails on broken system
return generateMRIDInternal(prefix, branch, time.Now(), randomBytes)
}
// GenerateMRIDWithTime generates a merge request ID using a specific timestamp.
// This is primarily useful for testing to ensure deterministic output.
// Note: Without randomness, two calls with identical inputs will produce the same ID.
func GenerateMRIDWithTime(prefix, branch string, timestamp time.Time) string {
return generateMRIDInternal(prefix, branch, timestamp, nil)
}
// generateMRIDInternal is the internal implementation that combines all inputs.
func generateMRIDInternal(prefix, branch string, timestamp time.Time, randomBytes []byte) string {
// Combine branch, timestamp, and optional random bytes for uniqueness
input := fmt.Sprintf("%s:%d:%x", branch, timestamp.UnixNano(), randomBytes)
// Generate SHA256 hash
hash := sha256.Sum256([]byte(input))
// Take first 6 characters of hex-encoded hash
hashStr := hex.EncodeToString(hash[:])[:6]
return fmt.Sprintf("%s-mr-%s", prefix, hashStr)
}