Add a dedicated system API/automation bot account (mokogitea-api) #747
Reference in New Issue
Block a user
Delete Branch "%!s()"
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?
Add a second system bot account for API/automation, distinct from the Actions runner bot — so automation (MCP server, scripts, integrations) acts as a first-class identity that can be allowlisted in branch protection with its own toggle.
Background
Today there is exactly one system bot: the Actions user
mokogitea-actions(id-2,models/user/user_system.go), allow-listed in branch protection via thewhitelist_actions_usertoggle. There is no separate API bot. Requested so an "API bot" can be treated the same way (a fixed system identity + toggle), not just a normal user account.Proposed implementation
mokogitea-api, reserved negative id (e.g.-3), emailmokogitea-api[bot]@mokoconsulting.tech, FullName "MokoGitea API". Add constructor +IsAPIBot()/system-user handling inmodels/user/user_system.goand reserve the name (models/user/user.goreserved list).whitelist_api_user(+ merge/force-push/delete variants), mirroringwhitelist_actions_user. Enforcement inmodels/git/protected_branch.go(user.IsAPIBot() && WhitelistAPIUser).mergeMostRestrictive(org-level branch protection) the same way as the actions-user flag.Open questions
Related: #745 §2 (bots naming), #746 (auto-add bot to team), #732 (email-domain policy), #727 (org-governance). Pairs with the in-progress org-level branch-protection user/email allowlist + actions-bot toggle.
https://claude.ai/code/session_01Wsno14cxE49MstXFs9G5KT
Branch created:
feature/747-add-a-dedicated-system-api-automation-boImplementation reference — mirror the
actions_usertoggleThe API-bot toggle is a near-exact parallel of the existing
whitelist_actions_usermechanism. The org-level actions-user allowlist + toggle is being built now (lands via #733); replicate every touchpoint below withapi/APIUser/IsAPIBotinstead ofactions/ActionsUser/IsActions.System user (the one genuinely new piece):
models/user/user_system.go: defineAPIUserID int64 = -3,APIUserName = "mokogitea-api",APIUserEmail,NewAPIUser()+IsAPIBot()— parallel toActionsUserID = -2/ActionsUserName = "mokogitea-actions"/NewActionsUser()/IsActions().models/user/user.go: addmokogitea-apito the reserved-name list (next tomokogitea-actions, ~line 634).Repo-level branch protection:
models/git/protected_branch.go: addWhitelistAPIUser,MergeWhitelistAPIUser,ForcePushAllowlistAPIUser,DeleteAllowlistAPIUser bool(parallel to*ActionsUser). Enforcement: inIsUserPushWhitelisted/IsUserMergeWhitelistedadduser.IsAPIBot() && protectBranch.WhitelistAPIUsernext to the existinguser.IsActions() && …WhitelistActionsUserchecks (~lines 137 / 246).modules/structs/repo_branch.go: addpush_whitelist_api_user(+ merge/force-push/delete) to Create/Edit/response options.templates/repo/settings/protected_branch.tmpl.Org-level branch protection (copy the actions-user work landing in #733):
models/git/org_protected_branch.go: addWhitelistAPIUseretc. +ToProtectedBranch()mapping.modules/structs/org_branch.go: addpush_whitelist_api_useretc. to Create/Edit/response.routers/api/v1/org/branch_protection.go: set/render the api-user bools (copy the actions-user handling).models/git/protected_branch_merge.go: addmergeAllowFlag(...)lines for the 4 api-user fields — reuse the samemergeAllowFlaghelper introduced for actions-user.Migration: add the
*_api_usercolumns to bothprotected_branchandorg_protected_branchtables (next free migration number at implementation time).Swagger regen + tests: extend the
protected_branch_mergetest with api-user cases.Net: it's the
whitelist_actions_userpattern (proven across repo + org via #733) plus themokogitea-apisystem user. Diff the org-actions-user commits from #733 for the exact shape to copy.https://claude.ai/code/session_01Wsno14cxE49MstXFs9G5KT