forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor web route handler (go-gitea#33488)
- Loading branch information
1 parent
d0f4e92
commit 09a3b07
Showing
8 changed files
with
271 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2025 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package repo | ||
|
||
import ( | ||
"net/http" | ||
|
||
repo_model "code.gitea.io/gitea/models/repo" | ||
"code.gitea.io/gitea/modules/templates" | ||
"code.gitea.io/gitea/services/context" | ||
) | ||
|
||
const tplStarUnstar templates.TplName = "repo/star_unstar" | ||
|
||
func ActionStar(ctx *context.Context) { | ||
err := repo_model.StarRepo(ctx, ctx.Doer, ctx.Repo.Repository, ctx.PathParam("action") == "star") | ||
if err != nil { | ||
handleActionError(ctx, err) | ||
return | ||
} | ||
|
||
ctx.Data["IsStaringRepo"] = repo_model.IsStaring(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID) | ||
ctx.Data["Repository"], err = repo_model.GetRepositoryByName(ctx, ctx.Repo.Repository.OwnerID, ctx.Repo.Repository.Name) | ||
if err != nil { | ||
ctx.ServerError("GetRepositoryByName", err) | ||
return | ||
} | ||
ctx.RespHeader().Add("hx-trigger", "refreshUserCards") // see the `hx-trigger="refreshUserCards ..."` comments in tmpl | ||
ctx.HTML(http.StatusOK, tplStarUnstar) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2025 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package repo | ||
|
||
import ( | ||
"code.gitea.io/gitea/services/context" | ||
repo_service "code.gitea.io/gitea/services/repository" | ||
) | ||
|
||
func acceptTransfer(ctx *context.Context) { | ||
err := repo_service.AcceptTransferOwnership(ctx, ctx.Repo.Repository, ctx.Doer) | ||
if err == nil { | ||
ctx.Flash.Success(ctx.Tr("repo.settings.transfer.success")) | ||
ctx.Redirect(ctx.Repo.Repository.Link()) | ||
return | ||
} | ||
handleActionError(ctx, err) | ||
} | ||
|
||
func rejectTransfer(ctx *context.Context) { | ||
err := repo_service.RejectRepositoryTransfer(ctx, ctx.Repo.Repository, ctx.Doer) | ||
if err == nil { | ||
ctx.Flash.Success(ctx.Tr("repo.settings.transfer.rejected")) | ||
ctx.Redirect(ctx.Repo.Repository.Link()) | ||
return | ||
} | ||
handleActionError(ctx, err) | ||
} | ||
|
||
func ActionTransfer(ctx *context.Context) { | ||
switch ctx.PathParam("action") { | ||
case "accept_transfer": | ||
acceptTransfer(ctx) | ||
case "reject_transfer": | ||
rejectTransfer(ctx) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2025 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package repo | ||
|
||
import ( | ||
"net/http" | ||
|
||
repo_model "code.gitea.io/gitea/models/repo" | ||
"code.gitea.io/gitea/modules/templates" | ||
"code.gitea.io/gitea/services/context" | ||
) | ||
|
||
const tplWatchUnwatch templates.TplName = "repo/watch_unwatch" | ||
|
||
func ActionWatch(ctx *context.Context) { | ||
err := repo_model.WatchRepo(ctx, ctx.Doer, ctx.Repo.Repository, ctx.PathParam("action") == "watch") | ||
if err != nil { | ||
handleActionError(ctx, err) | ||
return | ||
} | ||
|
||
ctx.Data["IsWatchingRepo"] = repo_model.IsWatching(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID) | ||
ctx.Data["Repository"], err = repo_model.GetRepositoryByName(ctx, ctx.Repo.Repository.OwnerID, ctx.Repo.Repository.Name) | ||
if err != nil { | ||
ctx.ServerError("GetRepositoryByName", err) | ||
return | ||
} | ||
ctx.RespHeader().Add("hx-trigger", "refreshUserCards") // see the `hx-trigger="refreshUserCards ..."` comments in tmpl | ||
ctx.HTML(http.StatusOK, tplWatchUnwatch) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.