mirror of https://github.com/go-gitea/gitea.git
parent
88352e0b25
commit
6ed1b26c58
|
@ -2733,6 +2733,7 @@ branch.restore_success = Branch "%s" has been restored.
|
||||||
branch.restore_failed = Failed to restore branch "%s".
|
branch.restore_failed = Failed to restore branch "%s".
|
||||||
branch.protected_deletion_failed = Branch "%s" is protected. It cannot be deleted.
|
branch.protected_deletion_failed = Branch "%s" is protected. It cannot be deleted.
|
||||||
branch.default_deletion_failed = Branch "%s" is the default branch. It cannot be deleted.
|
branch.default_deletion_failed = Branch "%s" is the default branch. It cannot be deleted.
|
||||||
|
branch.default_branch_not_exist = Default branch "%s" does not exist.
|
||||||
branch.restore = Restore Branch "%s"
|
branch.restore = Restore Branch "%s"
|
||||||
branch.download = Download Branch "%s"
|
branch.download = Download Branch "%s"
|
||||||
branch.rename = Rename Branch "%s"
|
branch.rename = Rename Branch "%s"
|
||||||
|
|
|
@ -6,6 +6,7 @@ package actions
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
stdCtx "context"
|
stdCtx "context"
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -67,7 +68,11 @@ func List(ctx *context.Context) {
|
||||||
ctx.Data["PageIsActions"] = true
|
ctx.Data["PageIsActions"] = true
|
||||||
|
|
||||||
commit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
|
commit, err := ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
|
||||||
if err != nil {
|
if errors.Is(err, util.ErrNotExist) {
|
||||||
|
ctx.Data["NotFoundPrompt"] = ctx.Tr("repo.branch.default_branch_not_exist", ctx.Repo.Repository.DefaultBranch)
|
||||||
|
ctx.NotFound(nil)
|
||||||
|
return
|
||||||
|
} else if err != nil {
|
||||||
ctx.ServerError("GetBranchCommit", err)
|
ctx.ServerError("GetBranchCommit", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
activities_model "code.gitea.io/gitea/models/activities"
|
activities_model "code.gitea.io/gitea/models/activities"
|
||||||
|
"code.gitea.io/gitea/models/git"
|
||||||
"code.gitea.io/gitea/models/unit"
|
"code.gitea.io/gitea/models/unit"
|
||||||
"code.gitea.io/gitea/modules/templates"
|
"code.gitea.io/gitea/modules/templates"
|
||||||
"code.gitea.io/gitea/services/context"
|
"code.gitea.io/gitea/services/context"
|
||||||
|
@ -52,12 +53,26 @@ func Activity(ctx *context.Context) {
|
||||||
ctx.Data["DateUntil"] = timeUntil
|
ctx.Data["DateUntil"] = timeUntil
|
||||||
ctx.Data["PeriodText"] = ctx.Tr("repo.activity.period." + ctx.Data["Period"].(string))
|
ctx.Data["PeriodText"] = ctx.Tr("repo.activity.period." + ctx.Data["Period"].(string))
|
||||||
|
|
||||||
|
canReadCode := ctx.Repo.CanRead(unit.TypeCode)
|
||||||
|
if canReadCode {
|
||||||
|
// GetActivityStats needs to read the default branch to get some information
|
||||||
|
branchExist, _ := git.IsBranchExist(ctx, ctx.Repo.Repository.ID, ctx.Repo.Repository.DefaultBranch)
|
||||||
|
if !branchExist {
|
||||||
|
ctx.Data["NotFoundPrompt"] = ctx.Tr("repo.branch.default_branch_not_exist", ctx.Repo.Repository.DefaultBranch)
|
||||||
|
ctx.NotFound(nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if ctx.Data["Activity"], err = activities_model.GetActivityStats(ctx, ctx.Repo.Repository, timeFrom,
|
// TODO: refactor these arguments to a struct
|
||||||
|
ctx.Data["Activity"], err = activities_model.GetActivityStats(ctx, ctx.Repo.Repository, timeFrom,
|
||||||
ctx.Repo.CanRead(unit.TypeReleases),
|
ctx.Repo.CanRead(unit.TypeReleases),
|
||||||
ctx.Repo.CanRead(unit.TypeIssues),
|
ctx.Repo.CanRead(unit.TypeIssues),
|
||||||
ctx.Repo.CanRead(unit.TypePullRequests),
|
ctx.Repo.CanRead(unit.TypePullRequests),
|
||||||
ctx.Repo.CanRead(unit.TypeCode)); err != nil {
|
canReadCode,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
ctx.ServerError("GetActivityStats", err)
|
ctx.ServerError("GetActivityStats", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,7 +150,7 @@ func (ctx *Context) notFoundInternal(logMsg string, logErr error) {
|
||||||
|
|
||||||
ctx.Data["IsRepo"] = ctx.Repo.Repository != nil
|
ctx.Data["IsRepo"] = ctx.Repo.Repository != nil
|
||||||
ctx.Data["Title"] = "Page Not Found"
|
ctx.Data["Title"] = "Page Not Found"
|
||||||
ctx.HTML(http.StatusNotFound, templates.TplName("status/404"))
|
ctx.HTML(http.StatusNotFound, "status/404")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerError displays a 500 (Internal Server Error) page and prints the given error, if any.
|
// ServerError displays a 500 (Internal Server Error) page and prints the given error, if any.
|
||||||
|
|
|
@ -9,7 +9,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/models/db"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
|
"code.gitea.io/gitea/models/unittest"
|
||||||
"code.gitea.io/gitea/modules/test"
|
"code.gitea.io/gitea/modules/test"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -61,5 +63,14 @@ func TestRepoActivity(t *testing.T) {
|
||||||
// Should be 3 new issues
|
// Should be 3 new issues
|
||||||
list = htmlDoc.doc.Find("#new-issues").Next().Find("p.desc")
|
list = htmlDoc.doc.Find("#new-issues").Next().Find("p.desc")
|
||||||
assert.Len(t, list.Nodes, 3)
|
assert.Len(t, list.Nodes, 3)
|
||||||
|
|
||||||
|
// Non-existing default branch
|
||||||
|
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: "repo1"})
|
||||||
|
repo1.DefaultBranch = "no-such-branch"
|
||||||
|
_, _ = db.GetEngine(t.Context()).Cols("default_branch").Update(repo1)
|
||||||
|
req = NewRequest(t, "GET", "/user2/repo1/activity")
|
||||||
|
req.Header.Add("Accept", "text/html")
|
||||||
|
resp = session.MakeRequest(t, req, http.StatusNotFound)
|
||||||
|
assert.Contains(t, resp.Body.String(), `Default branch "no-such-branch" does not exist.`)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue