add a page for tickets from gitea #1
Reference in New Issue
Block a user
No description provided.
Delete Branch "blake/ticket-updates"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
AI Code Review
Code Review
Bugs & Logic Errors
internal/gitea/gitea.go:115– Silent error handling:json.NewDecoder(resp.Body).Decode(&labels)is followed by//nolint:errcheck, which ignores a potential JSON decoding error. If the response body is malformed, the function will proceed as if no labels exist, potentially creating duplicate labels. This should be handled properly.internal/gitea/gitea.go:124– Hardcoded label color:The label color
#e11d48is hardcoded inadminOutagesPost. While theGetOrCreateLabelfunction accepts a color parameter, the caller always passes the same color. This could be made configurable via an environment variable (e.g.,GITEA_LABEL_COLOR) for consistency with other configs.internal/handler/public.go:196– Error logging may expose sensitive info:log.Printf("status: gitea planned outages: %v", err)could log the full error, which might include tokens or internal URLs. Consider logging a sanitized message or using a structured logger that redacts sensitive data.Security
internal/gitea/gitea.go:71– Token exposure in logs:The
newRequestmethod addsAuthorization: token ...to headers. If HTTP request logging is enabled elsewhere (e.g., via middleware), the token could be logged. Ensure no debug logging captures full request headers.templates/admin/outages.html:29– Open redirect risk:The issue
HTMLURLis rendered as a link withtarget="_blank". Whilerel="noopener"is present, the URL comes from an external API (Gitea). If the Gitea instance were compromised, malicious URLs could be injected. This is low risk but worth noting.internal/handler/admin.go:601– Missing CSRF protection:The
adminOutagesPosthandler modifies Gitea issues via POST requests but does not include CSRF tokens. Since the admin area requires authentication, CSRF protection should be added to prevent forged requests.Performance
internal/handler/public.go:193– Unbounded issue limit:ListIssuesByLabelfetches up to 50 issues, but there’s no pagination. If the repo has many labeled issues, only the first 50 will appear. Consider adding pagination or increasing the limit if needed.internal/gitea/gitea.go:113– Inefficient label lookup:GetOrCreateLabelfetches all labels from the repo each time it’s called. For frequent operations, this could be cached (e.g., with a TTL) to reduce API calls.Style & Maintainability
internal/gitea/gitea.go:60-68– Duplicate request creation logic:The
newRequestmethod handlesbody != nilandbody == nilcases separately, buthttp.NewRequestacceptsnilfor the body. The logic can be simplified to a single call.internal/handler/handler.go:48-50– Inconsistent env var handling:GITEA_URLandGITEA_TOKENare read directly viaos.Getenv, while other configs usegetenvwith defaults. Consider usinggetenvconsistently for clarity.internal/handler/admin.go:570– Magic string for label color:The color
#e11d48appears directly in the handler. Define it as a constant or config variable to make it easier to change.internal/gitea/gitea.go:184– HTTP status code check:RemoveLabelchecksresp.StatusCode >= 300 && resp.StatusCode != http.StatusNoContent. The Gitea API may return other success codes (e.g., 200). Consider checking forresp.StatusCode >= 200 && resp.StatusCode < 300instead, unless the API docs specify exact codes.Unfinished / Unclear
Missing error handling for Gitea client initialization:
If
GITEA_URLis set butGITEA_TOKENis empty,gitea.Newwill be called with an empty token, leading to authentication failures. Consider validating required env vars on startup or lazily when first used.No documentation for rate limits or API expectations:
The code assumes Gitea’s API behaves a certain way (e.g., label creation returns the label object). Add comments referencing the Gitea API version or document assumptions.
data/status.jsonanddata/uptime.jsonchanges:These files appear to have test data changes (dates in 2026). Ensure these are intentional and not accidental commits.
Summary
The PR adds a useful Gitea integration for tagging planned outages. The main issues are:
GetOrCreateLabelRecommend addressing the bug in
GetOrCreateLabeland adding CSRF protection before merging. The performance and style issues can be improved in follow-up PRs.Reviewed by deepseek-coder
Pull request closed