chore: fix repo watch (#38921)

This commit is contained in:
wxiaoguang
2026-08-16 03:00:59 +00:00
committed by GitHub
parent 56ad4689ad
commit 5e4d21acd5
26 changed files with 156 additions and 137 deletions
+3 -3
View File
@@ -132,7 +132,7 @@ func IsWatching(ctx *context.APIContext) {
// "404":
// description: User is not watching this repo or repo do not exist
if repo_model.IsWatching(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID) {
if repo_model.IsWatchingRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID) {
ctx.JSON(http.StatusOK, api.WatchInfo{
Subscribed: true,
Ignored: false,
@@ -170,7 +170,7 @@ func Watch(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
err := repo_model.WatchRepo(ctx, ctx.Doer, ctx.Repo.Repository, true)
err := repo_model.WatchRepoAuto(ctx, ctx.Doer, ctx.Repo.Repository, true)
if err != nil {
if errors.Is(err, user_model.ErrBlockedUser) {
ctx.APIError(http.StatusForbidden, err.Error())
@@ -211,7 +211,7 @@ func Unwatch(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
err := repo_model.WatchRepo(ctx, ctx.Doer, ctx.Repo.Repository, false)
err := repo_model.WatchRepoAuto(ctx, ctx.Doer, ctx.Repo.Repository, false)
if err != nil {
ctx.APIErrorInternal(err)
return
+1 -1
View File
@@ -284,7 +284,7 @@ func CreatePost(ctx *context.Context) {
handleCreateError(ctx, ctxUser, err, "CreatePost", tplCreate, &form)
}
func handleActionError(ctx *context.Context, err error) {
func handleRepoActionError(ctx *context.Context, err error) {
var errLimitReached repo_service.LimitReachedError
switch {
case errors.Is(err, user_model.ErrBlockedUser):
+1 -1
View File
@@ -16,7 +16,7 @@ const tplStarUnstar templates.TplName = "repo/header/star"
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)
handleRepoActionError(ctx, err)
return
}
+2 -2
View File
@@ -15,7 +15,7 @@ func acceptTransfer(ctx *context.Context) {
ctx.JSONRedirect(ctx.Repo.Repository.Link())
return
}
handleActionError(ctx, err)
handleRepoActionError(ctx, err)
}
func rejectTransfer(ctx *context.Context) {
@@ -25,7 +25,7 @@ func rejectTransfer(ctx *context.Context) {
ctx.JSONRedirect(ctx.Repo.Repository.Link())
return
}
handleActionError(ctx, err)
handleRepoActionError(ctx, err)
}
func ActionTransfer(ctx *context.Context) {
+15 -10
View File
@@ -16,14 +16,18 @@ const tplWatch templates.TplName = "repo/header/watch"
func ActionWatch(ctx *context.Context) {
action := ctx.PathParam("action")
var err error
if action == "ignore" {
err = repo_model.WatchIgnoreRepo(ctx, ctx.Doer, ctx.Repo.Repository)
} else {
all := action == "watch" // "participate" is a watch that subscribes to no event on its own
err = repo_model.WatchRepoWithOptions(ctx, ctx.Doer, ctx.Repo.Repository, repo_model.WatchOptions{PullRequests: all, Issues: all, Releases: all})
switch action {
case "ignore":
err = repo_model.WatchRepoWithOptions(ctx, ctx.Doer, ctx.Repo.Repository, repo_model.WatchOptions{Mode: repo_model.WatchModeDont})
case "participate":
err = repo_model.WatchRepoWithOptions(ctx, ctx.Doer, ctx.Repo.Repository, repo_model.WatchOptions{Mode: repo_model.WatchModeNone})
case "watch":
err = repo_model.WatchRepoWithOptions(ctx, ctx.Doer, ctx.Repo.Repository, repo_model.WatchOptions{Mode: repo_model.WatchModeNormal, WatchPullRequests: true, WatchIssues: true, WatchReleases: true})
default:
return // impossible
}
if err != nil {
handleActionError(ctx, err)
handleRepoActionError(ctx, err)
return
}
@@ -45,12 +49,13 @@ func ActionWatch(ctx *context.Context) {
// ActionWatchOptions watches the repository with a custom selection of events
func ActionWatchOptions(ctx *context.Context) {
opts := repo_model.WatchOptions{ // clearing every event is allowed, it leaves the participating state
PullRequests: ctx.FormBool(string(repo_model.WatchPullRequests)),
Issues: ctx.FormBool(string(repo_model.WatchIssues)),
Releases: ctx.FormBool(string(repo_model.WatchReleases)),
Mode: repo_model.WatchModeNormal,
WatchPullRequests: ctx.FormBool("pull_requests"),
WatchIssues: ctx.FormBool("issues"),
WatchReleases: ctx.FormBool("releases"),
}
if err := repo_model.WatchRepoWithOptions(ctx, ctx.Doer, ctx.Repo.Repository, opts); err != nil {
handleActionError(ctx, err)
handleRepoActionError(ctx, err)
return
}
ctx.JSONRedirect("")