From 1af82412c0d907a4c4b9152fc20d06babe5ffe7f Mon Sep 17 00:00:00 2001 From: Admin Date: Sun, 11 Jan 2026 03:57:14 +0000 Subject: [PATCH] feat: auto-create .profile repo with README and redirect to edit --- options/locale/locale_en-US.json | 4 ++- routers/web/org/home.go | 43 ++++++++++++++++++++++++++++++++ routers/web/web.go | 1 + templates/org/home.tmpl | 4 +-- 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/options/locale/locale_en-US.json b/options/locale/locale_en-US.json index 85f2290390..bacae2b052 100644 --- a/options/locale/locale_en-US.json +++ b/options/locale/locale_en-US.json @@ -3817,5 +3817,7 @@ "settings.show_heatmap_on_profile_popup": "Display your contribution heatmap on your profile overview page", "user.activity_heatmap": "Activity Heatmap", "org.stats": "Stats", - "org.recent_activity": "Recent Activity" + "org.recent_activity": "Recent Activity", + "org.profile_repo_no_permission": "You do not have permission to create repositories in this organization.", + "org.profile_repo_create_failed": "Failed to create the profile repository." } \ No newline at end of file diff --git a/routers/web/org/home.go b/routers/web/org/home.go index c21bc85331..acdab5e16c 100644 --- a/routers/web/org/home.go +++ b/routers/web/org/home.go @@ -22,6 +22,7 @@ import ( shared_user "code.gitea.io/gitea/routers/web/shared/user" "code.gitea.io/gitea/services/context" org_service "code.gitea.io/gitea/services/org" + repo_service "code.gitea.io/gitea/services/repository" ) // RecentRepoActivity holds repo and its latest commit info type RecentRepoActivity struct { @@ -286,3 +287,45 @@ func prepareOrgProfileReadme(ctx *context.Context, prepareResult *shared_user.Pr ctx.Data["IsViewingOrgAsMember"] = viewAsMember return true } + +// CreateProfileRepo creates a .profile repository with README for the organization +func CreateProfileRepo(ctx *context.Context) { + org := ctx.Org.Organization + + // Check if user can create repos in this org + if !ctx.Org.CanCreateOrgRepo { + ctx.Flash.Error(ctx.Tr("org.profile_repo_no_permission")) + ctx.Redirect(org.AsUser().HomeLink()) + return + } + + // Check if .profile repo already exists + exists, err := repo_model.IsRepositoryModelExist(ctx, org.AsUser(), ".profile") + if err != nil { + ctx.ServerError("IsRepositoryExist", err) + return + } + if exists { + ctx.Redirect(org.AsUser().HomeLink() + "/.profile") + return + } + + // Create the .profile repository + repo, err := repo_service.CreateRepository(ctx, ctx.Doer, org.AsUser(), repo_service.CreateRepoOptions{ + Name: ".profile", + Description: "Organization profile", + AutoInit: true, + Readme: "Default", + DefaultBranch: "main", + IsPrivate: false, + }) + if err != nil { + log.Error("CreateProfileRepo: %v", err) + ctx.Flash.Error(ctx.Tr("org.profile_repo_create_failed")) + ctx.Redirect(org.AsUser().HomeLink()) + return + } + + // Redirect to edit the README + ctx.Redirect(repo.Link() + "/_edit/main/README.md") +} diff --git a/routers/web/web.go b/routers/web/web.go index df2f9518fa..09e6865601 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -948,6 +948,7 @@ func registerWebRoutes(m *web.Router) { m.Get("/milestones", reqMilestonesDashboardPageEnabled, user.Milestones) m.Get("/milestones/{team}", reqMilestonesDashboardPageEnabled, user.Milestones) m.Post("/members/action/{action}", org.MembersAction) + m.Post("/create-profile-repo", org.CreateProfileRepo) m.Get("/teams", org.Teams) }, context.OrgAssignment(context.OrgAssignmentOptions{RequireMember: true, RequireTeamMember: true})) diff --git a/templates/org/home.tmpl b/templates/org/home.tmpl index 425adba937..e7f32d6bdd 100644 --- a/templates/org/home.tmpl +++ b/templates/org/home.tmpl @@ -146,9 +146,9 @@
- +
{{.CsrfTokenHtml}}