chore: ensure consistent import aliasing for services and models (#10253)

To make sure that the code stays maintainable, I added the `importas` linter to ensure that the imports for models and services stay consistent.

I realised that this might be needed after finding some discrepancies between singular/plural naming, and, especially in the case of the `forgejo.org/services/context` package, multiple different aliases like `gitea_ctx`, `app_context` and `forgejo_context`. I decided for `app_context`, as that seems to be the most commonly used naming.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10253
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: nachtjasmin <nachtjasmin@posteo.de>
Co-committed-by: nachtjasmin <nachtjasmin@posteo.de>
This commit is contained in:
nachtjasmin 2025-11-30 17:00:57 +01:00 committed by Gusted
parent 993da59ad4
commit 8ee4a7d658
51 changed files with 396 additions and 359 deletions

View file

@ -1,3 +1,4 @@
---
version: "2"
output:
sort-order:
@ -12,6 +13,7 @@ linters:
- forbidigo
- gocritic
- govet
- importas
- ineffassign
- nakedret
- nolintlint
@ -45,6 +47,41 @@ linters:
gocritic:
disabled-checks:
- ifElseChain
importas:
alias:
# Specific overrides that would violate the default rules further below.
- pkg: forgejo.org/models/actions
alias: actions_model
- pkg: forgejo.org/models/activities
alias: activities_model
- pkg: forgejo.org/models/db
alias: ""
- pkg: forgejo.org/models/issues
alias: issues_model
- pkg: forgejo.org/models/organization
alias: org_model
- pkg: forgejo.org/models/packages
alias: packages_model
- pkg: forgejo.org/services/actions
alias: actions_service
- pkg: forgejo.org/services/context
alias: app_context
- pkg: forgejo.org/services/doctor
alias: doctor
- pkg: forgejo.org/services/packages
alias: packages_service
- pkg: forgejo.org/services/repository
alias: repo_service
# Make sure that we follow a consistent naming for model and service aliases.
# The \w+? syntax is the RE2 syntax for: one or more \w, prefer fewer
#
# It's used to make sure that if the model has a plural name, e.g. "issues", it's imported with the singular
# name (e.g. "issue") nonetheless.
- pkg: 'forgejo.org/(model|service)s/(\w+?)s?'
alias: '${2}_${1}'
revive:
severity: error
rules:

View file

@ -10,7 +10,7 @@ import (
activities_model "forgejo.org/models/activities"
"forgejo.org/models/db"
issue_model "forgejo.org/models/issues"
issues_model "forgejo.org/models/issues"
repo_model "forgejo.org/models/repo"
"forgejo.org/models/unittest"
user_model "forgejo.org/models/user"
@ -32,7 +32,7 @@ func TestAction_GetRepoLink(t *testing.T) {
require.NoError(t, unittest.PrepareTestDatabase())
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
comment := unittest.AssertExistsAndLoadBean(t, &issue_model.Comment{ID: 2})
comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 2})
action := &activities_model.Action{RepoID: repo.ID, CommentID: comment.ID}
setting.AppSubURL = "/suburl"
expected := path.Join(setting.AppSubURL, owner.Name, repo.Name)
@ -288,13 +288,13 @@ func TestDeleteIssueActions(t *testing.T) {
require.NoError(t, unittest.PrepareTestDatabase())
// load an issue
issue := unittest.AssertExistsAndLoadBean(t, &issue_model.Issue{ID: 4})
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 4})
assert.NotEqual(t, issue.ID, issue.Index) // it needs to use different ID/Index to test the DeleteIssueActions to delete some actions by IssueIndex
// insert a comment
err := db.Insert(db.DefaultContext, &issue_model.Comment{Type: issue_model.CommentTypeComment, IssueID: issue.ID})
err := db.Insert(db.DefaultContext, &issues_model.Comment{Type: issues_model.CommentTypeComment, IssueID: issue.ID})
require.NoError(t, err)
comment := unittest.AssertExistsAndLoadBean(t, &issue_model.Comment{Type: issue_model.CommentTypeComment, IssueID: issue.ID})
comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{Type: issues_model.CommentTypeComment, IssueID: issue.ID})
// truncate action table and insert some actions
err = db.TruncateBeans(db.DefaultContext, &activities_model.Action{})

View file

@ -6,7 +6,7 @@ package avatars_test
import (
"testing"
avatars_model "forgejo.org/models/avatars"
avatar_model "forgejo.org/models/avatars"
"forgejo.org/models/db"
system_model "forgejo.org/models/system"
"forgejo.org/modules/setting"
@ -34,11 +34,11 @@ func enableGravatar(t *testing.T) {
func TestHashEmail(t *testing.T) {
assert.Equal(t,
"d41d8cd98f00b204e9800998ecf8427e",
avatars_model.HashEmail(""),
avatar_model.HashEmail(""),
)
assert.Equal(t,
"353cbad9b58e69c96154ad99f92bedc7",
avatars_model.HashEmail("gitea@example.com"),
avatar_model.HashEmail("gitea@example.com"),
)
}
@ -48,12 +48,12 @@ func TestSizedAvatarLink(t *testing.T) {
disableGravatar(t)
config.GetDynGetter().InvalidateCache()
assert.Equal(t, "/testsuburl/assets/img/avatar_default.png",
avatars_model.GenerateEmailAvatarFastLink(db.DefaultContext, "gitea@example.com", 100))
avatar_model.GenerateEmailAvatarFastLink(db.DefaultContext, "gitea@example.com", 100))
enableGravatar(t)
config.GetDynGetter().InvalidateCache()
assert.Equal(t,
"https://secure.gravatar.com/avatar/353cbad9b58e69c96154ad99f92bedc7?d=identicon&s=100",
avatars_model.GenerateEmailAvatarFastLink(db.DefaultContext, "gitea@example.com", 100),
avatar_model.GenerateEmailAvatarFastLink(db.DefaultContext, "gitea@example.com", 100),
)
}

View file

@ -4,7 +4,7 @@
package forgejo_migrations
import (
activity_model "forgejo.org/models/activities"
activities_model "forgejo.org/models/activities"
"forgejo.org/modules/setting"
"xorm.io/xorm"
@ -19,8 +19,8 @@ func init() {
func reworkNotification(x *xorm.Engine) error {
type Notification struct {
UserID int64 `xorm:"NOT NULL INDEX(s)"`
Status activity_model.NotificationStatus `xorm:"SMALLINT NOT NULL INDEX(s)"`
UserID int64 `xorm:"NOT NULL INDEX(s)"`
Status activities_model.NotificationStatus `xorm:"SMALLINT NOT NULL INDEX(s)"`
}
if err := dropIndexIfExists(x, "notification", "IDX_notification_user_id"); err != nil {

View file

@ -32,7 +32,7 @@ import (
"forgejo.org/modules/git"
"forgejo.org/modules/log"
"forgejo.org/modules/setting"
forgejo_services "forgejo.org/services/forgejo"
forgejo_service "forgejo.org/services/forgejo"
"xorm.io/xorm"
"xorm.io/xorm/names"
@ -502,7 +502,7 @@ Please try upgrading to a lower version first (suggested v1.6.4), then upgrade t
}
}
if err := forgejo_services.PreMigrationSanityChecks(x, previousVersion, setting.CfgProvider); err != nil {
if err := forgejo_service.PreMigrationSanityChecks(x, previousVersion, setting.CfgProvider); err != nil {
return err
}

View file

@ -7,7 +7,7 @@ import (
"context"
"forgejo.org/models/db"
organization_model "forgejo.org/models/organization"
org_model "forgejo.org/models/organization"
user_model "forgejo.org/models/user"
"forgejo.org/modules/container"
"forgejo.org/modules/optional"
@ -47,9 +47,9 @@ func (reviews ReviewList) LoadReviewersTeams(ctx context.Context) error {
}
}
teamsMap := make(map[int64]*organization_model.Team, 0)
teamsMap := make(map[int64]*org_model.Team, 0)
for _, teamID := range reviewersTeamsIDs {
team, err := organization_model.GetTeamByID(ctx, teamID)
team, err := org_model.GetTeamByID(ctx, teamID)
if err != nil {
return err
}

View file

@ -8,7 +8,7 @@ import (
"forgejo.org/models/db"
issues_model "forgejo.org/models/issues"
organization_model "forgejo.org/models/organization"
org_model "forgejo.org/models/organization"
repo_model "forgejo.org/models/repo"
"forgejo.org/models/unittest"
user_model "forgejo.org/models/user"
@ -336,7 +336,7 @@ func TestAddTeamReviewRequest(t *testing.T) {
t.Run("Protected branch, not official team", func(t *testing.T) {
issue, doer := setupForProtectedBranch()
// Team 2 is not part of the whitelist for this protected branch
team := unittest.AssertExistsAndLoadBean(t, &organization_model.Team{ID: 2})
team := unittest.AssertExistsAndLoadBean(t, &org_model.Team{ID: 2})
comment, err := issues_model.AddTeamReviewRequest(db.DefaultContext, issue, team, doer)
require.NoError(t, err)
@ -355,7 +355,7 @@ func TestAddTeamReviewRequest(t *testing.T) {
t.Run("Protected branch, official team", func(t *testing.T) {
issue, doer := setupForProtectedBranch()
// Team 1 is part of the whitelist for this protected branch
team := unittest.AssertExistsAndLoadBean(t, &organization_model.Team{ID: 1})
team := unittest.AssertExistsAndLoadBean(t, &org_model.Team{ID: 1})
comment, err := issues_model.AddTeamReviewRequest(db.DefaultContext, issue, team, doer)
require.NoError(t, err)
@ -376,7 +376,7 @@ func TestAddTeamReviewRequest(t *testing.T) {
require.NoError(t, issue.LoadRepo(db.DefaultContext))
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
// team is a team that has write perms against the repo
team := unittest.AssertExistsAndLoadBean(t, &organization_model.Team{ID: 1})
team := unittest.AssertExistsAndLoadBean(t, &org_model.Team{ID: 1})
comment, err := issues_model.AddTeamReviewRequest(db.DefaultContext, issue, team, doer)
require.NoError(t, err)

View file

@ -6,9 +6,9 @@ package quota
import (
"context"
action_model "forgejo.org/models/actions"
actions_model "forgejo.org/models/actions"
"forgejo.org/models/db"
package_model "forgejo.org/models/packages"
packages_model "forgejo.org/models/packages"
repo_model "forgejo.org/models/repo"
"xorm.io/builder"
@ -132,7 +132,7 @@ func createQueryFor(ctx context.Context, userID int64, q string) db.Engine {
session = session.
Table("action_artifact").
Join("INNER", "`repository`", "`action_artifact`.repo_id = `repository`.id").
Where("`action_artifact`.status != ?", action_model.ArtifactStatusExpired)
Where("`action_artifact`.status != ?", actions_model.ArtifactStatusExpired)
case "packages":
session = session.
Table("package_version").
@ -161,8 +161,8 @@ func GetQuotaAttachmentsForUser(ctx context.Context, userID int64, opts db.ListO
return count, &attachments, nil
}
func GetQuotaPackagesForUser(ctx context.Context, userID int64, opts db.ListOptions) (int64, *[]*package_model.PackageVersion, error) {
var pkgs []*package_model.PackageVersion
func GetQuotaPackagesForUser(ctx context.Context, userID int64, opts db.ListOptions) (int64, *[]*packages_model.PackageVersion, error) {
var pkgs []*packages_model.PackageVersion
sess := createQueryFor(ctx, userID, "packages").
OrderBy("`package_blob`.size DESC")
@ -177,8 +177,8 @@ func GetQuotaPackagesForUser(ctx context.Context, userID int64, opts db.ListOpti
return count, &pkgs, nil
}
func GetQuotaArtifactsForUser(ctx context.Context, userID int64, opts db.ListOptions) (int64, *[]*action_model.ActionArtifact, error) {
var artifacts []*action_model.ActionArtifact
func GetQuotaArtifactsForUser(ctx context.Context, userID int64, opts db.ListOptions) (int64, *[]*actions_model.ActionArtifact, error) {
var artifacts []*actions_model.ActionArtifact
sess := createQueryFor(ctx, userID, "artifacts").
OrderBy("`action_artifact`.file_compressed_size DESC")

View file

@ -7,7 +7,7 @@ import (
"context"
"forgejo.org/models/db"
issue_model "forgejo.org/models/issues"
issues_model "forgejo.org/models/issues"
indexer_internal "forgejo.org/modules/indexer/internal"
inner_db "forgejo.org/modules/indexer/internal/db"
"forgejo.org/modules/indexer/issues/internal"
@ -67,7 +67,7 @@ func (i *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
builder.In("issue.id", builder.Select("issue_id").
From("comment").
Where(builder.And(
builder.Eq{"type": issue_model.CommentTypeComment},
builder.Eq{"type": issues_model.CommentTypeComment},
builder.In("issue_id", subQuery),
db.BuildCaseInsensitiveLike("content", token.Term),
)),
@ -92,7 +92,7 @@ func (i *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
// If pagesize == 0, return total count only. It's a special case for search count.
if options.Paginator != nil && options.Paginator.PageSize == 0 {
total, err := issue_model.CountIssues(ctx, opt, cond)
total, err := issues_model.CountIssues(ctx, opt, cond)
if err != nil {
return nil, err
}
@ -101,7 +101,7 @@ func (i *Indexer) Search(ctx context.Context, options *internal.SearchOptions) (
}, nil
}
ids, total, err := issue_model.IssueIDs(ctx, opt, cond)
ids, total, err := issues_model.IssueIDs(ctx, opt, cond)
if err != nil {
return nil, err
}

View file

@ -8,13 +8,13 @@ import (
"fmt"
"forgejo.org/models/db"
issue_model "forgejo.org/models/issues"
issues_model "forgejo.org/models/issues"
"forgejo.org/modules/container"
"forgejo.org/modules/indexer/issues/internal"
"forgejo.org/modules/optional"
)
func ToDBOptions(ctx context.Context, options *internal.SearchOptions) (*issue_model.IssuesOptions, error) {
func ToDBOptions(ctx context.Context, options *internal.SearchOptions) (*issues_model.IssuesOptions, error) {
var sortType string
switch options.SortBy {
case internal.SortByCreatedAsc:
@ -49,7 +49,7 @@ func ToDBOptions(ctx context.Context, options *internal.SearchOptions) (*issue_m
return value
}
opts := &issue_model.IssuesOptions{
opts := &issues_model.IssuesOptions{
Paginator: options.Paginator,
RepoIDs: options.RepoIDs,
AllPublic: options.AllPublic,
@ -99,7 +99,7 @@ func ToDBOptions(ctx context.Context, options *internal.SearchOptions) (*issue_m
}
if len(options.IncludedLabelIDs) == 0 && len(options.IncludedAnyLabelIDs) > 0 {
labels, err := issue_model.GetLabelsByIDs(ctx, options.IncludedAnyLabelIDs, "name")
labels, err := issues_model.GetLabelsByIDs(ctx, options.IncludedAnyLabelIDs, "name")
if err != nil {
return nil, fmt.Errorf("GetLabelsByIDs: %v", err)
}

View file

@ -12,11 +12,11 @@ import (
"sync/atomic"
"time"
db_model "forgejo.org/models/db"
"forgejo.org/models/db"
repo_model "forgejo.org/models/repo"
"forgejo.org/modules/graceful"
"forgejo.org/modules/indexer/issues/bleve"
"forgejo.org/modules/indexer/issues/db"
db_index "forgejo.org/modules/indexer/issues/db"
"forgejo.org/modules/indexer/issues/elasticsearch"
"forgejo.org/modules/indexer/issues/internal"
"forgejo.org/modules/indexer/issues/meilisearch"
@ -103,7 +103,7 @@ func InitIssueIndexer(syncReindex bool) {
log.Fatal("Unable to issueIndexer.Init with connection %s Error: %v", setting.Indexer.IssueConnStr, err)
}
case "db":
issueIndexer = db.NewIndexer()
issueIndexer = db_index.NewIndexer()
case "meilisearch":
issueIndexer = meilisearch.NewIndexer(setting.Indexer.IssueConnStr, setting.Indexer.IssueConnAuth, setting.Indexer.IssueIndexerName)
existed, err = issueIndexer.Init(ctx)
@ -218,8 +218,8 @@ func PopulateIssueIndexer(ctx context.Context) error {
default:
}
repos, _, err := repo_model.SearchRepositoryByName(ctx, &repo_model.SearchRepoOptions{
ListOptions: db_model.ListOptions{Page: page, PageSize: repo_model.RepositoryListDefaultPageSize},
OrderBy: db_model.SearchOrderByID,
ListOptions: db.ListOptions{Page: page, PageSize: repo_model.RepositoryListDefaultPageSize},
OrderBy: db.SearchOrderByID,
Private: true,
Collaborate: optional.Some(false),
})
@ -319,7 +319,7 @@ func SearchIssues(ctx context.Context, opts *SearchOptions) ([]int64, int64, err
// So if the user creates an issue and list issues immediately, the issue may not be listed because the indexer needs time to index the issue.
// Even worse, the external indexer like elastic search may not be available for a while,
// and the user may not be able to list issues completely until it is available again.
indexer = db.NewIndexer()
indexer = db_index.NewIndexer()
}
result, err := indexer.Search(ctx, opts)
@ -337,7 +337,7 @@ func SearchIssues(ctx context.Context, opts *SearchOptions) ([]int64, int64, err
// CountIssues counts issues by options. It is a shortcut of SearchIssues(ctx, opts) but only returns the total count.
func CountIssues(ctx context.Context, opts *SearchOptions) (int64, error) {
opts = opts.Copy(func(options *SearchOptions) { options.Paginator = &db_model.ListOptions{PageSize: 0} })
opts = opts.Copy(func(options *SearchOptions) { options.Paginator = &db.ListOptions{PageSize: 0} })
_, total, err := SearchIssues(ctx, opts)
return total, err

View file

@ -9,7 +9,7 @@ import (
"fmt"
"forgejo.org/models/db"
issue_model "forgejo.org/models/issues"
issues_model "forgejo.org/models/issues"
"forgejo.org/modules/container"
"forgejo.org/modules/indexer/issues/internal"
"forgejo.org/modules/log"
@ -18,9 +18,9 @@ import (
// getIssueIndexerData returns the indexer data of an issue and a bool value indicating whether the issue exists.
func getIssueIndexerData(ctx context.Context, issueID int64) (*internal.IndexerData, bool, error) {
issue, err := issue_model.GetIssueByID(ctx, issueID)
issue, err := issues_model.GetIssueByID(ctx, issueID)
if err != nil {
if issue_model.IsErrIssueNotExist(err) {
if issues_model.IsErrIssueNotExist(err) {
return nil, false, nil
}
return nil, false, err
@ -50,7 +50,7 @@ func getIssueIndexerData(ctx context.Context, issueID int64) (*internal.IndexerD
labels = append(labels, label.ID)
}
mentionIDs, err := issue_model.GetIssueMentionIDs(ctx, issueID)
mentionIDs, err := issues_model.GetIssueMentionIDs(ctx, issueID)
if err != nil {
return nil, false, err
}
@ -60,7 +60,7 @@ func getIssueIndexerData(ctx context.Context, issueID int64) (*internal.IndexerD
reviewRequestedIDs []int64
)
{
reviews, err := issue_model.FindReviews(ctx, issue_model.FindReviewOptions{
reviews, err := issues_model.FindReviews(ctx, issues_model.FindReviewOptions{
ListOptions: db.ListOptionsAll,
IssueID: issueID,
OfficialOnly: false,
@ -72,7 +72,7 @@ func getIssueIndexerData(ctx context.Context, issueID int64) (*internal.IndexerD
reviewedIDsSet := make(container.Set[int64], len(reviews))
reviewRequestedIDsSet := make(container.Set[int64], len(reviews))
for _, review := range reviews {
if review.Type == issue_model.ReviewTypeRequest {
if review.Type == issues_model.ReviewTypeRequest {
reviewRequestedIDsSet.Add(review.ReviewerID)
} else {
reviewedIDsSet.Add(review.ReviewerID)
@ -82,7 +82,7 @@ func getIssueIndexerData(ctx context.Context, issueID int64) (*internal.IndexerD
reviewRequestedIDs = reviewRequestedIDsSet.Values()
}
subscriberIDs, err := issue_model.GetIssueWatchersIDs(ctx, issue.ID, true)
subscriberIDs, err := issues_model.GetIssueWatchersIDs(ctx, issue.ID, true)
if err != nil {
return nil, false, err
}
@ -121,7 +121,7 @@ func getIssueIndexerData(ctx context.Context, issueID int64) (*internal.IndexerD
}
func updateRepoIndexer(ctx context.Context, repoID int64) error {
ids, err := issue_model.GetIssueIDsByRepoID(ctx, repoID)
ids, err := issues_model.GetIssueIDsByRepoID(ctx, repoID)
if err != nil {
return fmt.Errorf("issue_model.GetIssueIDsByRepoID: %w", err)
}
@ -139,7 +139,7 @@ func updateIssueIndexer(ctx context.Context, issueID int64) error {
func deleteRepoIssueIndexer(ctx context.Context, repoID int64) error {
var ids []int64
ids, err := issue_model.GetIssueIDsByRepoID(ctx, repoID)
ids, err := issues_model.GetIssueIDsByRepoID(ctx, repoID)
if err != nil {
return fmt.Errorf("issue_model.GetIssueIDsByRepoID: %w", err)
}

View file

@ -8,13 +8,13 @@ import (
"forgejo.org/modules/log"
"forgejo.org/modules/setting"
services_context "forgejo.org/services/context"
app_context "forgejo.org/services/context"
"forgejo.org/services/federation"
"github.com/42wim/httpsig"
)
func verifyHTTPUserOrInstanceSignature(ctx services_context.APIContext) (authenticated bool, err error) {
func verifyHTTPUserOrInstanceSignature(ctx app_context.APIContext) (authenticated bool, err error) {
if !setting.Federation.SignatureEnforced {
return true, nil
}
@ -43,7 +43,7 @@ func verifyHTTPUserOrInstanceSignature(ctx services_context.APIContext) (authent
return true, nil
}
func verifyHTTPUserSignature(ctx services_context.APIContext) (authenticated bool, err error) {
func verifyHTTPUserSignature(ctx app_context.APIContext) (authenticated bool, err error) {
if !setting.Federation.SignatureEnforced {
return true, nil
}
@ -70,8 +70,8 @@ func verifyHTTPUserSignature(ctx services_context.APIContext) (authenticated boo
}
// ReqHTTPSignature function
func ReqHTTPUserOrInstanceSignature() func(ctx *services_context.APIContext) {
return func(ctx *services_context.APIContext) {
func ReqHTTPUserOrInstanceSignature() func(ctx *app_context.APIContext) {
return func(ctx *app_context.APIContext) {
if authenticated, err := verifyHTTPUserOrInstanceSignature(*ctx); err != nil {
log.Warn("verifyHttpSignatures failed: %v", err)
ctx.Error(http.StatusBadRequest, "reqSignature", "request signature verification failed")
@ -82,8 +82,8 @@ func ReqHTTPUserOrInstanceSignature() func(ctx *services_context.APIContext) {
}
// ReqHTTPUserSignature function
func ReqHTTPUserSignature() func(ctx *services_context.APIContext) {
return func(ctx *services_context.APIContext) {
func ReqHTTPUserSignature() func(ctx *app_context.APIContext) {
return func(ctx *app_context.APIContext) {
if authenticated, err := verifyHTTPUserSignature(*ctx); err != nil {
log.Warn("verifyHttpSignatures failed: %v", err)
ctx.Error(http.StatusBadRequest, "reqSignature", "request signature verification failed")

View file

@ -11,7 +11,7 @@ import (
unit_model "forgejo.org/models/unit"
"forgejo.org/services/context"
"forgejo.org/services/convert"
releaseservice "forgejo.org/services/release"
release_service "forgejo.org/services/release"
)
// GetReleaseByTag get a single release of a repository by tag name
@ -120,7 +120,7 @@ func DeleteReleaseByTag(ctx *context.APIContext) {
return
}
if err = releaseservice.DeleteReleaseByID(ctx, ctx.Repo.Repository, release, ctx.Doer, false); err != nil {
if err = release_service.DeleteReleaseByID(ctx, ctx.Repo.Repository, release, ctx.Doer, false); err != nil {
if models.IsErrProtectedTagName(err) {
ctx.Error(http.StatusUnprocessableEntity, "delTag", "user not allowed to delete protected tag")
return

View file

@ -19,7 +19,7 @@ import (
"forgejo.org/routers/api/v1/utils"
"forgejo.org/services/context"
"forgejo.org/services/convert"
releaseservice "forgejo.org/services/release"
release_service "forgejo.org/services/release"
)
// ListTags list all the tags of a repository
@ -227,7 +227,7 @@ func CreateTag(ctx *context.APIContext) {
return
}
if err := releaseservice.CreateNewTag(ctx, ctx.Doer, ctx.Repo.Repository, commit.ID.String(), form.TagName, form.Message); err != nil {
if err := release_service.CreateNewTag(ctx, ctx.Doer, ctx.Repo.Repository, commit.ID.String(), form.TagName, form.Message); err != nil {
if models.IsErrTagAlreadyExists(err) {
ctx.Error(http.StatusConflict, "tag exist", err)
return
@ -309,7 +309,7 @@ func DeleteTag(ctx *context.APIContext) {
return
}
if err = releaseservice.DeleteReleaseByID(ctx, ctx.Repo.Repository, tag, ctx.Doer, true); err != nil {
if err = release_service.DeleteReleaseByID(ctx, ctx.Repo.Repository, tag, ctx.Doer, true); err != nil {
if models.IsErrProtectedTagName(err) {
ctx.Error(http.StatusUnprocessableEntity, "delTag", "user not allowed to delete protected tag")
return

View file

@ -10,7 +10,7 @@ import (
"forgejo.org/models"
asymkey_model "forgejo.org/models/asymkey"
authmodel "forgejo.org/models/auth"
auth_model "forgejo.org/models/auth"
"forgejo.org/modules/cache"
"forgejo.org/modules/eventsource"
"forgejo.org/modules/git"
@ -44,7 +44,7 @@ import (
"forgejo.org/services/mailer"
mailer_incoming "forgejo.org/services/mailer/incoming"
markup_service "forgejo.org/services/markup"
repo_migrations "forgejo.org/services/migrations"
migration_service "forgejo.org/services/migrations"
mirror_service "forgejo.org/services/mirror"
pull_service "forgejo.org/services/pull"
release_service "forgejo.org/services/release"
@ -146,7 +146,7 @@ func InitWebInstalled(ctx context.Context) {
mustInit(release_service.Init)
mustInitCtx(ctx, models.Init)
mustInitCtx(ctx, authmodel.Init)
mustInitCtx(ctx, auth_model.Init)
mustInitCtx(ctx, repo_service.Init)
// Booting long running goroutines.
@ -157,7 +157,7 @@ func InitWebInstalled(ctx context.Context) {
mustInit(pull_service.Init)
mustInit(automerge.Init)
mustInit(task.Init)
mustInit(repo_migrations.Init)
mustInit(migration_service.Init)
eventsource.GetManager().Init()
mustInitCtx(ctx, mailer_incoming.Init)

View file

@ -9,12 +9,12 @@ import (
"forgejo.org/modules/json"
"forgejo.org/modules/private"
myCtx "forgejo.org/services/context"
app_context "forgejo.org/services/context"
"forgejo.org/services/migrations"
)
// RestoreRepo restore a repository from data
func RestoreRepo(ctx *myCtx.PrivateContext) {
func RestoreRepo(ctx *app_context.PrivateContext) {
bs, err := io.ReadAll(ctx.Req.Body)
if err != nil {
ctx.JSON(http.StatusInternalServerError, private.Response{

View file

@ -12,7 +12,7 @@ import (
"forgejo.org/models/db"
issues_model "forgejo.org/models/issues"
project_model "forgejo.org/models/project"
attachment_model "forgejo.org/models/repo"
repo_model "forgejo.org/models/repo"
"forgejo.org/models/unit"
"forgejo.org/modules/base"
"forgejo.org/modules/json"
@ -352,10 +352,10 @@ func ViewProject(ctx *context.Context) {
}
if project.CardType != project_model.CardTypeTextOnly {
issuesAttachmentMap := make(map[int64][]*attachment_model.Attachment)
issuesAttachmentMap := make(map[int64][]*repo_model.Attachment)
for _, issuesList := range issuesMap {
for _, issue := range issuesList {
if issueAttachment, err := attachment_model.GetAttachmentsByIssueIDImagesLatest(ctx, issue.ID); err == nil {
if issueAttachment, err := repo_model.GetAttachmentsByIssueIDImagesLatest(ctx, issue.ID); err == nil {
issuesAttachmentMap[issue.ID] = issueAttachment
}
}

View file

@ -7,7 +7,7 @@ import (
"strings"
"testing"
issue_model "forgejo.org/models/issues"
issues_model "forgejo.org/models/issues"
"forgejo.org/models/organization"
user_model "forgejo.org/models/user"
"forgejo.org/modules/timeutil"
@ -17,8 +17,8 @@ import (
// *************** Helper functions for the tests ***************
func testComment(t int64) *issue_model.Comment {
return &issue_model.Comment{PosterID: 1, CreatedUnix: timeutil.TimeStamp(t)}
func testComment(t int64) *issues_model.Comment {
return &issues_model.Comment{PosterID: 1, CreatedUnix: timeutil.TimeStamp(t)}
}
func nameToID(name string) int64 {
@ -29,13 +29,13 @@ func nameToID(name string) int64 {
return id
}
func createReqReviewTarget(name string) issue_model.RequestReviewTarget {
func createReqReviewTarget(name string) issues_model.RequestReviewTarget {
if strings.HasSuffix(name, "-team") {
team := createTeam(name)
return issue_model.RequestReviewTarget{Team: &team}
return issues_model.RequestReviewTarget{Team: &team}
}
user := createUser(name)
return issue_model.RequestReviewTarget{User: &user}
return issues_model.RequestReviewTarget{User: &user}
}
func createUser(name string) user_model.User {
@ -46,21 +46,21 @@ func createTeam(name string) organization.Team {
return organization.Team{Name: name, ID: nameToID(name)}
}
func createLabel(name string) issue_model.Label {
return issue_model.Label{Name: name, ID: nameToID(name)}
func createLabel(name string) issues_model.Label {
return issues_model.Label{Name: name, ID: nameToID(name)}
}
func addLabel(t int64, name string) *issue_model.Comment {
func addLabel(t int64, name string) *issues_model.Comment {
c := testComment(t)
c.Type = issue_model.CommentTypeLabel
c.Type = issues_model.CommentTypeLabel
c.Content = "1"
lbl := createLabel(name)
c.Label = &lbl
c.AddedLabels = []*issue_model.Label{&lbl}
c.AddedLabels = []*issues_model.Label{&lbl}
return c
}
func delLabel(t int64, name string) *issue_model.Comment {
func delLabel(t int64, name string) *issues_model.Comment {
c := addLabel(t, name)
c.Content = ""
c.RemovedLabels = c.AddedLabels
@ -68,19 +68,19 @@ func delLabel(t int64, name string) *issue_model.Comment {
return c
}
func openOrClose(t int64, close bool) *issue_model.Comment {
func openOrClose(t int64, close bool) *issues_model.Comment {
c := testComment(t)
if close {
c.Type = issue_model.CommentTypeClose
c.Type = issues_model.CommentTypeClose
} else {
c.Type = issue_model.CommentTypeReopen
c.Type = issues_model.CommentTypeReopen
}
return c
}
func reqReview(t int64, name string, delReq bool) *issue_model.Comment {
func reqReview(t int64, name string, delReq bool) *issues_model.Comment {
c := testComment(t)
c.Type = issue_model.CommentTypeReviewRequest
c.Type = issues_model.CommentTypeReviewRequest
if strings.HasSuffix(name, "-team") {
team := createTeam(name)
c.AssigneeTeam = &team
@ -94,21 +94,21 @@ func reqReview(t int64, name string, delReq bool) *issue_model.Comment {
return c
}
func ghostReqReview(t, id int64) *issue_model.Comment {
func ghostReqReview(t, id int64) *issues_model.Comment {
c := testComment(t)
c.Type = issue_model.CommentTypeReviewRequest
c.Type = issues_model.CommentTypeReviewRequest
c.AssigneeTeam = organization.NewGhostTeam()
c.AssigneeTeamID = id
return c
}
func reqReviewList(t int64, del bool, names ...string) *issue_model.Comment {
req := []issue_model.RequestReviewTarget{}
func reqReviewList(t int64, del bool, names ...string) *issues_model.Comment {
req := []issues_model.RequestReviewTarget{}
for _, name := range names {
req = append(req, createReqReviewTarget(name))
}
cmnt := testComment(t)
cmnt.Type = issue_model.CommentTypeReviewRequest
cmnt.Type = issues_model.CommentTypeReviewRequest
if del {
cmnt.RemovedRequestReview = req
} else {
@ -119,14 +119,14 @@ func reqReviewList(t int64, del bool, names ...string) *issue_model.Comment {
func aggregatedComment(t int64,
closed bool,
addLabels []*issue_model.Label,
delLabels []*issue_model.Label,
addReqReview []issue_model.RequestReviewTarget,
delReqReview []issue_model.RequestReviewTarget,
) *issue_model.Comment {
addLabels []*issues_model.Label,
delLabels []*issues_model.Label,
addReqReview []issues_model.RequestReviewTarget,
delReqReview []issues_model.RequestReviewTarget,
) *issues_model.Comment {
cmnt := testComment(t)
cmnt.Type = issue_model.CommentTypeAggregator
cmnt.Aggregator = &issue_model.ActionAggregator{
cmnt.Type = issues_model.CommentTypeAggregator
cmnt.Aggregator = &issues_model.ActionAggregator{
IsClosed: closed,
AddedLabels: addLabels,
RemovedLabels: delLabels,
@ -148,9 +148,9 @@ func aggregatedComment(t int64,
return cmnt
}
func commentText(t int64, text string) *issue_model.Comment {
func commentText(t int64, text string) *issues_model.Comment {
c := testComment(t)
c.Type = issue_model.CommentTypeComment
c.Type = issues_model.CommentTypeComment
c.Content = text
return c
}
@ -159,14 +159,14 @@ func commentText(t int64, text string) *issue_model.Comment {
type testCase struct {
name string
beforeCombined []*issue_model.Comment
afterCombined []*issue_model.Comment
beforeCombined []*issues_model.Comment
afterCombined []*issues_model.Comment
sameAfter bool
timestampCombination int64
}
func (kase *testCase) doTest(t *testing.T) {
issue := issue_model.Issue{Comments: kase.beforeCombined}
issue := issues_model.Issue{Comments: kase.beforeCombined}
var now int64 = -9223372036854775808
for c := 0; c < len(kase.beforeCombined); c++ {
@ -178,7 +178,7 @@ func (kase *testCase) doTest(t *testing.T) {
now = kase.timestampCombination
}
issue_model.CombineCommentsHistory(&issue, now)
issues_model.CombineCommentsHistory(&issue, now)
after := kase.afterCombined
if kase.sameAfter {
@ -202,7 +202,7 @@ func (kase *testCase) doTest(t *testing.T) {
r := issue.Comments[c]
// Ignore some inner data of the aggregator to facilitate testing
if l.Type == issue_model.CommentTypeAggregator {
if l.Type == issues_model.CommentTypeAggregator {
r.Aggregator.StartUnix = 0
r.Aggregator.PrevClosed = false
r.Aggregator.PosterID = 0
@ -212,10 +212,10 @@ func (kase *testCase) doTest(t *testing.T) {
}
// We can safely ignore this if the rest matches
if l.Type == issue_model.CommentTypeLabel {
if l.Type == issues_model.CommentTypeLabel {
l.Label = nil
l.Content = ""
} else if l.Type == issue_model.CommentTypeReviewRequest {
} else if l.Type == issues_model.CommentTypeReviewRequest {
l.Assignee = nil
l.AssigneeID = 0
l.AssigneeTeam = nil
@ -238,7 +238,7 @@ func TestCombineLabelComments(t *testing.T) {
// ADD single = normal label comment
{
name: "add_single_label",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
addLabel(0, "a"),
commentText(10, "I'm a salmon"),
},
@ -248,12 +248,12 @@ func TestCombineLabelComments(t *testing.T) {
// ADD then REMOVE = Nothing
{
name: "add_label_then_remove",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
addLabel(0, "a"),
delLabel(1, "a"),
commentText(65, "I'm a salmon"),
},
afterCombined: []*issue_model.Comment{
afterCombined: []*issues_model.Comment{
commentText(65, "I'm a salmon"),
},
},
@ -261,7 +261,7 @@ func TestCombineLabelComments(t *testing.T) {
// ADD 1 then comment then REMOVE = separate comments
{
name: "add_label_then_comment_then_remove",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
addLabel(0, "a"),
commentText(10, "I'm a salmon"),
delLabel(20, "a"),
@ -272,7 +272,7 @@ func TestCombineLabelComments(t *testing.T) {
// ADD 2 = Combined labels
{
name: "combine_labels",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
addLabel(0, "a"),
addLabel(10, "b"),
commentText(20, "I'm a salmon"),
@ -281,12 +281,12 @@ func TestCombineLabelComments(t *testing.T) {
addLabel(85, "e"),
delLabel(90, "c"),
},
afterCombined: []*issue_model.Comment{
afterCombined: []*issues_model.Comment{
{
PosterID: 1,
Type: issue_model.CommentTypeLabel,
Type: issues_model.CommentTypeLabel,
CreatedUnix: timeutil.TimeStamp(0),
AddedLabels: []*issue_model.Label{
AddedLabels: []*issues_model.Label{
{Name: "a", ID: nameToID("a")},
{Name: "b", ID: nameToID("b")},
},
@ -294,9 +294,9 @@ func TestCombineLabelComments(t *testing.T) {
commentText(20, "I'm a salmon"),
{
PosterID: 1,
Type: issue_model.CommentTypeLabel,
Type: issues_model.CommentTypeLabel,
CreatedUnix: timeutil.TimeStamp(30),
AddedLabels: []*issue_model.Label{
AddedLabels: []*issues_model.Label{
{Name: "d", ID: nameToID("d")},
{Name: "e", ID: nameToID("e")},
},
@ -307,17 +307,17 @@ func TestCombineLabelComments(t *testing.T) {
// ADD 1, then 1 later = 2 separate comments
{
name: "add_then_later_label",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
addLabel(0, "a"),
addLabel(60, "b"),
addLabel(121, "c"),
},
afterCombined: []*issue_model.Comment{
afterCombined: []*issues_model.Comment{
{
PosterID: 1,
Type: issue_model.CommentTypeLabel,
Type: issues_model.CommentTypeLabel,
CreatedUnix: timeutil.TimeStamp(0),
AddedLabels: []*issue_model.Label{
AddedLabels: []*issues_model.Label{
{Name: "a", ID: nameToID("a")},
{Name: "b", ID: nameToID("b")},
},
@ -329,12 +329,12 @@ func TestCombineLabelComments(t *testing.T) {
// ADD 2 then REMOVE 1 = label
{
name: "add_2_remove_1",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
addLabel(0, "a"),
addLabel(10, "b"),
delLabel(20, "a"),
},
afterCombined: []*issue_model.Comment{
afterCombined: []*issues_model.Comment{
// The timestamp will be the one of the first aggregated comment
addLabel(0, "b"),
},
@ -343,7 +343,7 @@ func TestCombineLabelComments(t *testing.T) {
// ADD then REMOVE multiple = nothing
{
name: "add_multiple_remove_all",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
addLabel(0, "a"),
addLabel(1, "b"),
addLabel(2, "c"),
@ -361,27 +361,27 @@ func TestCombineLabelComments(t *testing.T) {
// ADD 2, wait, REMOVE 2 = +2 then -2 comments
{
name: "add2_wait_rm2_labels",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
addLabel(0, "a"),
addLabel(1, "b"),
delLabel(120, "a"),
delLabel(121, "b"),
},
afterCombined: []*issue_model.Comment{
afterCombined: []*issues_model.Comment{
{
PosterID: 1,
Type: issue_model.CommentTypeLabel,
Type: issues_model.CommentTypeLabel,
CreatedUnix: timeutil.TimeStamp(0),
AddedLabels: []*issue_model.Label{
AddedLabels: []*issues_model.Label{
{Name: "a", ID: nameToID("a")},
{Name: "b", ID: nameToID("b")},
},
},
{
PosterID: 1,
Type: issue_model.CommentTypeLabel,
Type: issues_model.CommentTypeLabel,
CreatedUnix: timeutil.TimeStamp(120),
RemovedLabels: []*issue_model.Label{
RemovedLabels: []*issues_model.Label{
{Name: "a", ID: nameToID("a")},
{Name: "b", ID: nameToID("b")},
},
@ -392,7 +392,7 @@ func TestCombineLabelComments(t *testing.T) {
// Regression check on edge case
{
name: "regression_edgecase_finalagg",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
commentText(0, "hey"),
commentText(1, "ho"),
addLabel(2, "a"),
@ -409,15 +409,15 @@ func TestCombineLabelComments(t *testing.T) {
delLabel(400, "a"),
},
afterCombined: []*issue_model.Comment{
afterCombined: []*issues_model.Comment{
commentText(0, "hey"),
commentText(1, "ho"),
addLabel(120, "a"),
{
PosterID: 1,
Type: issue_model.CommentTypeLabel,
Type: issues_model.CommentTypeLabel,
CreatedUnix: timeutil.TimeStamp(220),
AddedLabels: []*issue_model.Label{
AddedLabels: []*issues_model.Label{
{Name: "c", ID: nameToID("c")},
{Name: "e", ID: nameToID("e")},
},
@ -429,7 +429,7 @@ func TestCombineLabelComments(t *testing.T) {
{
name: "combine_label_high_timestamp_separated",
timestampCombination: tmon + 1,
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
// 1 month old, comments separated by 1 Day + 1 sec (not agg)
addLabel(0, "d"),
delLabel(tday+1, "d"),
@ -453,7 +453,7 @@ func TestCombineLabelComments(t *testing.T) {
{
name: "combine_label_high_timestamp_merged",
timestampCombination: tmon + 1,
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
// 1 month old, comments separated by 1 Day (aggregated)
addLabel(0, "d"),
delLabel(tday, "d"),
@ -482,7 +482,7 @@ func TestCombineReviewRequests(t *testing.T) {
// ADD single = normal request review comment
{
name: "add_single_review",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
reqReview(0, "toto", false),
commentText(10, "I'm a salmon"),
reqReview(20, "toto-team", false),
@ -493,12 +493,12 @@ func TestCombineReviewRequests(t *testing.T) {
// ADD then REMOVE = Nothing
{
name: "add_then_remove_review",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
reqReview(0, "toto", false),
reqReview(5, "toto", true),
commentText(10, "I'm a salmon"),
},
afterCombined: []*issue_model.Comment{
afterCombined: []*issues_model.Comment{
commentText(10, "I'm a salmon"),
},
},
@ -506,7 +506,7 @@ func TestCombineReviewRequests(t *testing.T) {
// ADD 1 then comment then REMOVE = separate comments
{
name: "add_comment_del_review",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
reqReview(0, "toto", false),
commentText(5, "I'm a salmon"),
reqReview(10, "toto", true),
@ -517,7 +517,7 @@ func TestCombineReviewRequests(t *testing.T) {
// ADD 2 = Combined request reviews
{
name: "combine_reviews",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
reqReview(0, "toto", false),
reqReview(10, "tutu-team", false),
commentText(20, "I'm a salmon"),
@ -526,7 +526,7 @@ func TestCombineReviewRequests(t *testing.T) {
reqReview(85, "tyty-team", false),
reqReview(90, "titi", true),
},
afterCombined: []*issue_model.Comment{
afterCombined: []*issues_model.Comment{
reqReviewList(0, false, "toto", "tutu-team"),
commentText(20, "I'm a salmon"),
reqReviewList(30, false, "tata", "tyty-team"),
@ -536,12 +536,12 @@ func TestCombineReviewRequests(t *testing.T) {
// ADD 1, then 1 later = 2 separate comments
{
name: "add_then_later_review",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
reqReview(0, "titi", false),
reqReview(60, "toto-team", false),
reqReview(121, "tutu", false),
},
afterCombined: []*issue_model.Comment{
afterCombined: []*issues_model.Comment{
reqReviewList(0, false, "titi", "toto-team"),
reqReviewList(121, false, "tutu"),
},
@ -550,12 +550,12 @@ func TestCombineReviewRequests(t *testing.T) {
// ADD 2 then REMOVE 1 = single request review
{
name: "add_2_then_remove_review",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
reqReview(0, "titi-team", false),
reqReview(59, "toto", false),
reqReview(60, "titi-team", true),
},
afterCombined: []*issue_model.Comment{
afterCombined: []*issues_model.Comment{
reqReviewList(0, false, "toto"),
},
},
@ -563,7 +563,7 @@ func TestCombineReviewRequests(t *testing.T) {
// ADD then REMOVE multiple = nothing
{
name: "add_multiple_then_remove_all_review",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
reqReview(0, "titi0-team", false),
reqReview(1, "toto1", false),
reqReview(2, "titi2", false),
@ -585,13 +585,13 @@ func TestCombineReviewRequests(t *testing.T) {
// ADD 2, wait, REMOVE 2 = +2 then -2 comments
{
name: "add2_wait_rm2_requests",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
reqReview(1, "titi", false),
reqReview(2, "toto-team", false),
reqReview(121, "titi", true),
reqReview(122, "toto-team", true),
},
afterCombined: []*issue_model.Comment{
afterCombined: []*issues_model.Comment{
reqReviewList(1, false, "titi", "toto-team"),
reqReviewList(121, true, "titi", "toto-team"),
},
@ -600,18 +600,18 @@ func TestCombineReviewRequests(t *testing.T) {
// Ghost.
{
name: "ghost reviews",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
reqReview(1, "titi", false),
ghostReqReview(2, 50),
ghostReqReview(3, 51),
ghostReqReview(4, 50),
},
afterCombined: []*issue_model.Comment{
afterCombined: []*issues_model.Comment{
{
PosterID: 1,
Type: issue_model.CommentTypeReviewRequest,
Type: issues_model.CommentTypeReviewRequest,
CreatedUnix: timeutil.TimeStamp(1),
AddedRequestReview: []issue_model.RequestReviewTarget{
AddedRequestReview: []issues_model.RequestReviewTarget{
createReqReviewTarget("titi"), {Team: organization.NewGhostTeam()},
},
},
@ -629,7 +629,7 @@ func TestCombineOpenClose(t *testing.T) {
// Close then open = nullified
{
name: "close_open_nullified",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
openOrClose(0, true),
openOrClose(10, false),
},
@ -639,7 +639,7 @@ func TestCombineOpenClose(t *testing.T) {
// Close then open later = separate comments
{
name: "close_open_later",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
openOrClose(0, true),
openOrClose(61, false),
},
@ -649,7 +649,7 @@ func TestCombineOpenClose(t *testing.T) {
// Close then comment then open = separate comments
{
name: "close_comment_open",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
openOrClose(0, true),
commentText(1, "I'm a salmon"),
openOrClose(2, false),
@ -669,7 +669,7 @@ func TestCombineMultipleDifferentComments(t *testing.T) {
// Add Label + Close + ReqReview = Combined
{
name: "label_close_reqreview_combined",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
reqReview(1, "toto", false),
addLabel(2, "a"),
openOrClose(3, true),
@ -678,20 +678,20 @@ func TestCombineMultipleDifferentComments(t *testing.T) {
openOrClose(102, false),
delLabel(103, "a"),
},
afterCombined: []*issue_model.Comment{
afterCombined: []*issues_model.Comment{
aggregatedComment(1,
true,
[]*issue_model.Label{&lblA},
[]*issue_model.Label{},
[]issue_model.RequestReviewTarget{createReqReviewTarget("toto")},
[]issue_model.RequestReviewTarget{},
[]*issues_model.Label{&lblA},
[]*issues_model.Label{},
[]issues_model.RequestReviewTarget{createReqReviewTarget("toto")},
[]issues_model.RequestReviewTarget{},
),
aggregatedComment(101,
false,
[]*issue_model.Label{},
[]*issue_model.Label{&lblA},
[]issue_model.RequestReviewTarget{},
[]issue_model.RequestReviewTarget{createReqReviewTarget("toto")},
[]*issues_model.Label{},
[]*issues_model.Label{&lblA},
[]issues_model.RequestReviewTarget{},
[]issues_model.RequestReviewTarget{createReqReviewTarget("toto")},
),
},
},
@ -699,14 +699,14 @@ func TestCombineMultipleDifferentComments(t *testing.T) {
// Add Req + Add Label + Close + Del Req + Del Label = Close only
{
name: "req_label_close_dellabel_delreq",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
addLabel(2, "a"),
reqReview(3, "titi", false),
openOrClose(4, true),
delLabel(5, "a"),
reqReview(6, "titi", true),
},
afterCombined: []*issue_model.Comment{
afterCombined: []*issues_model.Comment{
openOrClose(2, true),
},
},
@ -714,14 +714,14 @@ func TestCombineMultipleDifferentComments(t *testing.T) {
// Close + Add Req + Add Label + Del Req + Open = Label only
{
name: "close_req_label_open_delreq",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
openOrClose(2, true),
reqReview(4, "titi", false),
addLabel(5, "a"),
reqReview(6, "titi", true),
openOrClose(8, false),
},
afterCombined: []*issue_model.Comment{
afterCombined: []*issues_model.Comment{
addLabel(2, "a"),
},
},
@ -729,14 +729,14 @@ func TestCombineMultipleDifferentComments(t *testing.T) {
// Add Label + Close + Add ReqReview + Del Label + Open = ReqReview only
{
name: "label_close_req_dellabel_open",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
addLabel(1, "a"),
openOrClose(2, true),
reqReview(4, "titi", false),
openOrClose(7, false),
delLabel(8, "a"),
},
afterCombined: []*issue_model.Comment{
afterCombined: []*issues_model.Comment{
reqReviewList(1, false, "titi"),
},
},
@ -744,7 +744,7 @@ func TestCombineMultipleDifferentComments(t *testing.T) {
// Add Label + Close + ReqReview, then delete everything = nothing
{
name: "add_multiple_delete_everything",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
addLabel(1, "a"),
openOrClose(2, true),
reqReview(4, "titi", false),
@ -758,7 +758,7 @@ func TestCombineMultipleDifferentComments(t *testing.T) {
// Add multiple, then comment, then delete everything = separate aggregation
{
name: "add_multiple_comment_delete_everything",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
addLabel(1, "a"),
openOrClose(2, true),
reqReview(4, "titi", false),
@ -769,28 +769,28 @@ func TestCombineMultipleDifferentComments(t *testing.T) {
delLabel(8, "a"),
reqReview(10, "titi", true),
},
afterCombined: []*issue_model.Comment{
afterCombined: []*issues_model.Comment{
aggregatedComment(1,
true,
[]*issue_model.Label{&lblA},
[]*issue_model.Label{},
[]issue_model.RequestReviewTarget{createReqReviewTarget("titi")},
[]issue_model.RequestReviewTarget{},
[]*issues_model.Label{&lblA},
[]*issues_model.Label{},
[]issues_model.RequestReviewTarget{createReqReviewTarget("titi")},
[]issues_model.RequestReviewTarget{},
),
commentText(6, "I'm a salmon"),
aggregatedComment(7,
false,
[]*issue_model.Label{},
[]*issue_model.Label{&lblA},
[]issue_model.RequestReviewTarget{},
[]issue_model.RequestReviewTarget{createReqReviewTarget("titi")},
[]*issues_model.Label{},
[]*issues_model.Label{&lblA},
[]issues_model.RequestReviewTarget{},
[]issues_model.RequestReviewTarget{createReqReviewTarget("titi")},
),
},
},
{
name: "regression_edgecase_finalagg",
beforeCombined: []*issue_model.Comment{
beforeCombined: []*issues_model.Comment{
commentText(0, "hey"),
commentText(1, "ho"),
addLabel(2, "a"),
@ -807,16 +807,16 @@ func TestCombineMultipleDifferentComments(t *testing.T) {
delLabel(400, "a"),
},
afterCombined: []*issue_model.Comment{
afterCombined: []*issues_model.Comment{
commentText(0, "hey"),
commentText(1, "ho"),
addLabel(120, "a"),
aggregatedComment(220,
true,
[]*issue_model.Label{},
[]*issue_model.Label{},
[]issue_model.RequestReviewTarget{createReqReviewTarget("toto-team")},
[]issue_model.RequestReviewTarget{},
[]*issues_model.Label{},
[]*issues_model.Label{},
[]issues_model.RequestReviewTarget{createReqReviewTarget("toto-team")},
[]issues_model.RequestReviewTarget{},
),
delLabel(400, "a"),
},

View file

@ -8,14 +8,14 @@ import (
actions_model "forgejo.org/models/actions"
"forgejo.org/models/db"
unittest "forgejo.org/models/unittest"
unittest_model "forgejo.org/models/unittest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_loadIsRefDeleted(t *testing.T) {
unittest.PrepareTestEnv(t)
unittest_model.PrepareTestEnv(t)
runs, total, err := db.FindAndCount[actions_model.ActionRun](db.DefaultContext,
actions_model.FindRunOptions{RepoID: 4, Ref: "refs/heads/test"})

View file

@ -7,10 +7,10 @@ import (
"net/url"
actions_service "forgejo.org/services/actions"
context_module "forgejo.org/services/context"
app_context "forgejo.org/services/context"
)
func ManualRunWorkflow(ctx *context_module.Context) {
func ManualRunWorkflow(ctx *app_context.Context) {
workflowID := ctx.FormString("workflow")
if len(workflowID) == 0 {
ctx.ServerError("workflow", nil)

View file

@ -36,12 +36,12 @@ import (
"forgejo.org/modules/web"
"forgejo.org/routers/common"
actions_service "forgejo.org/services/actions"
context_module "forgejo.org/services/context"
app_context "forgejo.org/services/context"
"xorm.io/builder"
)
func RedirectToLatestAttempt(ctx *context_module.Context) {
func RedirectToLatestAttempt(ctx *app_context.Context) {
runIndex := ctx.ParamsInt64("run")
jobIndex := ctx.ParamsInt64("job")
@ -59,7 +59,7 @@ func RedirectToLatestAttempt(ctx *context_module.Context) {
ctx.Redirect(jobURL, http.StatusTemporaryRedirect)
}
func View(ctx *context_module.Context) {
func View(ctx *app_context.Context) {
ctx.Data["PageIsActions"] = true
runIndex := ctx.ParamsInt64("run")
jobIndex := ctx.ParamsInt64("job")
@ -107,7 +107,7 @@ func View(ctx *context_module.Context) {
ctx.HTML(http.StatusOK, tplViewActions)
}
func ViewLatest(ctx *context_module.Context) {
func ViewLatest(ctx *app_context.Context) {
run, err := actions_model.GetLatestRun(ctx, ctx.Repo.Repository.ID)
if err != nil {
ctx.NotFound("GetLatestRun", err)
@ -121,7 +121,7 @@ func ViewLatest(ctx *context_module.Context) {
ctx.Redirect(run.HTMLURL(), http.StatusTemporaryRedirect)
}
func ViewLatestWorkflowRun(ctx *context_module.Context) {
func ViewLatestWorkflowRun(ctx *app_context.Context) {
branch := ctx.FormString("branch")
if branch == "" {
branch = ctx.Repo.Repository.DefaultBranch
@ -246,7 +246,7 @@ type TaskAttempt struct {
Status string `json:"status"`
}
func ViewPost(ctx *context_module.Context) {
func ViewPost(ctx *app_context.Context) {
req := web.GetForm(ctx).(*ViewRequest)
runIndex := ctx.ParamsInt64("run")
jobIndex := ctx.ParamsInt64("job")
@ -262,7 +262,7 @@ func ViewPost(ctx *context_module.Context) {
ctx.JSON(http.StatusOK, resp)
}
func getViewResponse(ctx *context_module.Context, req *ViewRequest, runIndex, jobIndex, attemptNumber int64) *ViewResponse {
func getViewResponse(ctx *app_context.Context, req *ViewRequest, runIndex, jobIndex, attemptNumber int64) *ViewResponse {
current, jobs := getRunJobs(ctx, runIndex, jobIndex)
if ctx.Written() {
return nil
@ -466,7 +466,7 @@ type redirectObject struct {
// Rerun will rerun jobs in the given run
// If jobIndexStr is a blank string, it means rerun all jobs
func Rerun(ctx *context_module.Context) {
func Rerun(ctx *app_context.Context) {
runIndex := ctx.ParamsInt64("run")
jobIndexStr := ctx.Params("job")
var jobIndex int64
@ -563,7 +563,7 @@ func Rerun(ctx *context_module.Context) {
}
}
func rerunJob(ctx *context_module.Context, job *actions_model.ActionRunJob, shouldBlock bool) error {
func rerunJob(ctx *app_context.Context, job *actions_model.ActionRunJob, shouldBlock bool) error {
status := job.Status
if !status.IsDone() {
return nil
@ -588,7 +588,7 @@ func rerunJob(ctx *context_module.Context, job *actions_model.ActionRunJob, shou
return nil
}
func Logs(ctx *context_module.Context) {
func Logs(ctx *app_context.Context) {
runIndex := ctx.ParamsInt64("run")
jobIndex := ctx.ParamsInt64("job")
attemptNumber := ctx.ParamsInt64("attempt")
@ -629,7 +629,7 @@ func Logs(ctx *context_module.Context) {
if p := strings.Index(workflowName, "."); p > 0 {
workflowName = workflowName[0:p]
}
ctx.ServeContent(reader, &context_module.ServeHeaderOptions{
ctx.ServeContent(reader, &app_context.ServeHeaderOptions{
Filename: fmt.Sprintf("%v-%v-%v.log", workflowName, job.Name, task.ID),
ContentLength: &task.LogSize,
ContentType: "text/plain",
@ -638,7 +638,7 @@ func Logs(ctx *context_module.Context) {
})
}
func Cancel(ctx *context_module.Context) {
func Cancel(ctx *app_context.Context) {
runIndex := ctx.ParamsInt64("run")
_, jobs := getRunJobs(ctx, runIndex, -1)
@ -682,7 +682,7 @@ func Cancel(ctx *context_module.Context) {
// getRunJobs gets the jobs of runIndex, and returns jobs[jobIndex], jobs.
// Any error will be written to the ctx.
// It never returns a nil job of an empty jobs, if the jobIndex is out of range, it will be treated as 0.
func getRunJobs(ctx *context_module.Context, runIndex, jobIndex int64) (*actions_model.ActionRunJob, []*actions_model.ActionRunJob) {
func getRunJobs(ctx *app_context.Context, runIndex, jobIndex int64) (*actions_model.ActionRunJob, []*actions_model.ActionRunJob) {
run, err := actions_model.GetRunByIndex(ctx, ctx.Repo.Repository.ID, runIndex)
if err != nil {
if errors.Is(err, util.ErrNotExist) {
@ -724,7 +724,7 @@ type ArtifactsViewItem struct {
Status string `json:"status"`
}
func ArtifactsView(ctx *context_module.Context) {
func ArtifactsView(ctx *app_context.Context) {
runIndex := ctx.ParamsInt64("run")
artifactsResponse := getArtifactsViewResponse(ctx, runIndex)
if ctx.Written() {
@ -733,7 +733,7 @@ func ArtifactsView(ctx *context_module.Context) {
ctx.JSON(http.StatusOK, artifactsResponse)
}
func getArtifactsViewResponse(ctx *context_module.Context, runIndex int64) *ArtifactsViewResponse {
func getArtifactsViewResponse(ctx *app_context.Context, runIndex int64) *ArtifactsViewResponse {
run, err := actions_model.GetRunByIndex(ctx, ctx.Repo.Repository.ID, runIndex)
if err != nil {
if errors.Is(err, util.ErrNotExist) {
@ -765,7 +765,7 @@ func getArtifactsViewResponse(ctx *context_module.Context, runIndex int64) *Arti
return &artifactsResponse
}
func ArtifactsDeleteView(ctx *context_module.Context) {
func ArtifactsDeleteView(ctx *app_context.Context) {
runIndex := ctx.ParamsInt64("run")
artifactName := ctx.Params("artifact_name")
@ -783,7 +783,7 @@ func ArtifactsDeleteView(ctx *context_module.Context) {
ctx.JSON(http.StatusOK, struct{}{})
}
func getRunByID(ctx *context_module.Context, runID int64) *actions_model.ActionRun {
func getRunByID(ctx *app_context.Context, runID int64) *actions_model.ActionRun {
if runID == 0 {
log.Debug("Requested runID is zero.")
ctx.Error(http.StatusNotFound, "zero is not a valid run ID")
@ -808,7 +808,7 @@ func getRunByID(ctx *context_module.Context, runID int64) *actions_model.ActionR
return run
}
func artifactsFind(ctx *context_module.Context, opts actions_model.FindArtifactsOptions) []*actions_model.ActionArtifact {
func artifactsFind(ctx *app_context.Context, opts actions_model.FindArtifactsOptions) []*actions_model.ActionArtifact {
artifacts, err := db.Find[actions_model.ActionArtifact](ctx, opts)
if err != nil {
ctx.Error(http.StatusInternalServerError, err.Error())
@ -820,7 +820,7 @@ func artifactsFind(ctx *context_module.Context, opts actions_model.FindArtifacts
return artifacts
}
func artifactsFindByNameOrID(ctx *context_module.Context, runID int64, nameOrID string) []*actions_model.ActionArtifact {
func artifactsFindByNameOrID(ctx *app_context.Context, runID int64, nameOrID string) []*actions_model.ActionArtifact {
artifacts := artifactsFind(ctx, actions_model.FindArtifactsOptions{
RunID: runID,
ArtifactName: nameOrID,
@ -850,7 +850,7 @@ func artifactsFindByNameOrID(ctx *context_module.Context, runID int64, nameOrID
return artifacts
}
func ArtifactsDownloadView(ctx *context_module.Context) {
func ArtifactsDownloadView(ctx *app_context.Context) {
run := getRunByID(ctx, ctx.ParamsInt64("run"))
if ctx.Written() {
return
@ -929,15 +929,15 @@ func ArtifactsDownloadView(ctx *context_module.Context) {
}
}
func DisableWorkflowFile(ctx *context_module.Context) {
func DisableWorkflowFile(ctx *app_context.Context) {
disableOrEnableWorkflowFile(ctx, false)
}
func EnableWorkflowFile(ctx *context_module.Context) {
func EnableWorkflowFile(ctx *app_context.Context) {
disableOrEnableWorkflowFile(ctx, true)
}
func disableOrEnableWorkflowFile(ctx *context_module.Context, isEnable bool) {
func disableOrEnableWorkflowFile(ctx *app_context.Context, isEnable bool) {
workflow := ctx.FormString("workflow")
if len(workflow) == 0 {
ctx.ServerError("workflow", nil)

View file

@ -11,7 +11,7 @@ import (
actions_model "forgejo.org/models/actions"
repo_model "forgejo.org/models/repo"
unittest "forgejo.org/models/unittest"
unittest_model "forgejo.org/models/unittest"
"forgejo.org/modules/json"
"forgejo.org/modules/web"
"forgejo.org/services/contexttest"
@ -21,9 +21,9 @@ import (
)
func Test_getRunByID(t *testing.T) {
unittest.PrepareTestEnv(t)
unittest_model.PrepareTestEnv(t)
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: 5, ID: 4})
repo := unittest_model.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: 5, ID: 4})
for _, testCase := range []struct {
name string
@ -62,7 +62,7 @@ func Test_getRunByID(t *testing.T) {
}
func Test_artifactsFind(t *testing.T) {
unittest.PrepareTestEnv(t)
unittest_model.PrepareTestEnv(t)
for _, testCase := range []struct {
name string
@ -94,7 +94,7 @@ func Test_artifactsFind(t *testing.T) {
}
func Test_artifactsFindByNameOrID(t *testing.T) {
unittest.PrepareTestEnv(t)
unittest_model.PrepareTestEnv(t)
for _, testCase := range []struct {
name string
@ -219,7 +219,7 @@ func baseExpectedViewResponse() *ViewResponse {
}
func TestActionsViewViewPost(t *testing.T) {
unittest.PrepareTestEnv(t)
unittest_model.PrepareTestEnv(t)
tests := []struct {
name string
@ -378,7 +378,7 @@ func TestActionsViewViewPost(t *testing.T) {
}
func TestActionsViewRedirectToLatestAttempt(t *testing.T) {
unittest.PrepareTestEnv(t)
unittest_model.PrepareTestEnv(t)
tests := []struct {
name string

View file

@ -12,10 +12,10 @@ import (
repo_model "forgejo.org/models/repo"
"forgejo.org/models/unit"
"forgejo.org/modules/setting"
context_module "forgejo.org/services/context"
app_context "forgejo.org/services/context"
)
func getBadgeURL(ctx *context_module.Context, label, text, color string) string {
func getBadgeURL(ctx *app_context.Context, label, text, color string) string {
sb := &strings.Builder{}
_ = setting.Badges.GeneratorURLTemplateTemplate.Execute(sb, map[string]string{
"label": url.PathEscape(strings.ReplaceAll(label, "-", "--")),
@ -35,15 +35,15 @@ func getBadgeURL(ctx *context_module.Context, label, text, color string) string
return badgeURL
}
func redirectToBadge(ctx *context_module.Context, label, text, color string) {
func redirectToBadge(ctx *app_context.Context, label, text, color string) {
ctx.Redirect(getBadgeURL(ctx, label, text, color))
}
func errorBadge(ctx *context_module.Context, label, text string) { //nolint:unparam
func errorBadge(ctx *app_context.Context, label, text string) { //nolint:unparam
ctx.Redirect(getBadgeURL(ctx, label, text, "crimson"))
}
func GetWorkflowBadge(ctx *context_module.Context) {
func GetWorkflowBadge(ctx *app_context.Context) {
branch := ctx.Req.URL.Query().Get("branch")
if branch != "" {
branch = fmt.Sprintf("refs/heads/%s", branch)
@ -82,7 +82,7 @@ func GetWorkflowBadge(ctx *context_module.Context) {
redirectToBadge(ctx, workflowFile, run.Status.String(), color)
}
func getIssueOrPullBadge(ctx *context_module.Context, label, variant string, num int) {
func getIssueOrPullBadge(ctx *app_context.Context, label, variant string, num int) {
var text string
if len(variant) > 0 {
text = fmt.Sprintf("%d %s", num, variant)
@ -92,7 +92,7 @@ func getIssueOrPullBadge(ctx *context_module.Context, label, variant string, num
redirectToBadge(ctx, label, text, "blue")
}
func getIssueBadge(ctx *context_module.Context, variant string, num int) {
func getIssueBadge(ctx *app_context.Context, variant string, num int) {
if !ctx.Repo.CanRead(unit.TypeIssues) &&
!ctx.Repo.CanRead(unit.TypeExternalTracker) {
errorBadge(ctx, "issues", "Not found")
@ -108,7 +108,7 @@ func getIssueBadge(ctx *context_module.Context, variant string, num int) {
getIssueOrPullBadge(ctx, "issues", variant, num)
}
func getPullBadge(ctx *context_module.Context, variant string, num int) {
func getPullBadge(ctx *app_context.Context, variant string, num int) {
if !ctx.Repo.Repository.CanEnablePulls() || !ctx.Repo.CanRead(unit.TypePullRequests) {
errorBadge(ctx, "pulls", "Not found")
return
@ -117,35 +117,35 @@ func getPullBadge(ctx *context_module.Context, variant string, num int) {
getIssueOrPullBadge(ctx, "pulls", variant, num)
}
func GetOpenIssuesBadge(ctx *context_module.Context) {
func GetOpenIssuesBadge(ctx *app_context.Context) {
getIssueBadge(ctx, "open", ctx.Repo.Repository.NumOpenIssues(ctx))
}
func GetClosedIssuesBadge(ctx *context_module.Context) {
func GetClosedIssuesBadge(ctx *app_context.Context) {
getIssueBadge(ctx, "closed", ctx.Repo.Repository.NumClosedIssues(ctx))
}
func GetTotalIssuesBadge(ctx *context_module.Context) {
func GetTotalIssuesBadge(ctx *app_context.Context) {
getIssueBadge(ctx, "", ctx.Repo.Repository.NumIssues(ctx))
}
func GetOpenPullsBadge(ctx *context_module.Context) {
func GetOpenPullsBadge(ctx *app_context.Context) {
getPullBadge(ctx, "open", ctx.Repo.Repository.NumOpenPulls(ctx))
}
func GetClosedPullsBadge(ctx *context_module.Context) {
func GetClosedPullsBadge(ctx *app_context.Context) {
getPullBadge(ctx, "closed", ctx.Repo.Repository.NumClosedPulls(ctx))
}
func GetTotalPullsBadge(ctx *context_module.Context) {
func GetTotalPullsBadge(ctx *app_context.Context) {
getPullBadge(ctx, "", ctx.Repo.Repository.NumPulls(ctx))
}
func GetStarsBadge(ctx *context_module.Context) {
func GetStarsBadge(ctx *app_context.Context) {
redirectToBadge(ctx, "stars", fmt.Sprintf("%d", ctx.Repo.Repository.NumStars), "blue")
}
func GetLatestReleaseBadge(ctx *context_module.Context) {
func GetLatestReleaseBadge(ctx *app_context.Context) {
release, err := repo_model.GetLatestReleaseByRepoID(ctx, ctx.Repo.Repository.ID)
if err != nil {
if repo_model.IsErrReleaseNotExist(err) {

View file

@ -16,7 +16,7 @@ import (
"time"
"forgejo.org/models/db"
issue_model "forgejo.org/models/issues"
issues_model "forgejo.org/models/issues"
repo_model "forgejo.org/models/repo"
unit_model "forgejo.org/models/unit"
user_model "forgejo.org/models/user"
@ -228,7 +228,7 @@ func drawRepoSummaryCard(ctx *context.Context, repo *repo_model.Repository) (*ca
return mainCard, nil
}
func drawIssueSummaryCard(ctx *context.Context, issue *issue_model.Issue) (*card.Card, error) {
func drawIssueSummaryCard(ctx *context.Context, issue *issues_model.Issue) (*card.Card, error) {
width, height := card.DefaultSize()
mainCard, err := card.NewCard(width, height)
if err != nil {
@ -457,9 +457,9 @@ func DrawRepoSummaryCard(ctx *context.Context) {
}
func DrawIssueSummaryCard(ctx *context.Context) {
issue, err := issue_model.GetIssueWithAttrsByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
issue, err := issues_model.GetIssueWithAttrsByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
if issue_model.IsErrIssueNotExist(err) {
if issues_model.IsErrIssueNotExist(err) {
ctx.Error(http.StatusNotFound)
} else {
ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err.Error())

View file

@ -9,7 +9,7 @@ import (
"forgejo.org/modules/base"
"forgejo.org/services/context"
contributors_service "forgejo.org/services/repository"
repo_service "forgejo.org/services/repository"
)
const (
@ -29,8 +29,8 @@ func CodeFrequency(ctx *context.Context) {
// CodeFrequencyData returns JSON of code frequency data
func CodeFrequencyData(ctx *context.Context) {
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.CommitID); err != nil {
if errors.Is(err, contributors_service.ErrAwaitGeneration) {
if contributorStats, err := repo_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.CommitID); err != nil {
if errors.Is(err, repo_service.ErrAwaitGeneration) {
ctx.Status(http.StatusAccepted)
return
}

View file

@ -30,7 +30,7 @@ import (
"forgejo.org/services/context"
"forgejo.org/services/forms"
"forgejo.org/services/gitdiff"
git_service "forgejo.org/services/repository"
repo_service "forgejo.org/services/repository"
"forgejo.org/services/repository/gitgraph"
)
@ -293,7 +293,7 @@ func FileHistory(ctx *context.Context) {
}
func LoadBranchesAndTags(ctx *context.Context) {
response, err := git_service.LoadBranchesAndTags(ctx, ctx.Repo, ctx.Params("sha"))
response, err := repo_service.LoadBranchesAndTags(ctx, ctx.Repo, ctx.Params("sha"))
if err == nil {
ctx.JSON(http.StatusOK, response)
return

View file

@ -9,7 +9,7 @@ import (
"forgejo.org/modules/base"
"forgejo.org/services/context"
contributors_service "forgejo.org/services/repository"
repo_service "forgejo.org/services/repository"
)
const (
@ -26,8 +26,8 @@ func Contributors(ctx *context.Context) {
// ContributorsData renders JSON of contributors along with their weekly commit statistics
func ContributorsData(ctx *context.Context) {
if contributorStats, err := contributors_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.CommitID); err != nil {
if errors.Is(err, contributors_service.ErrAwaitGeneration) {
if contributorStats, err := repo_service.GetContributorStats(ctx, ctx.Cache, ctx.Repo.Repository, ctx.Repo.CommitID); err != nil {
if errors.Is(err, repo_service.ErrAwaitGeneration) {
ctx.Status(http.StatusAccepted)
return
}

View file

@ -13,7 +13,7 @@ import (
issues_model "forgejo.org/models/issues"
"forgejo.org/models/perm"
project_model "forgejo.org/models/project"
attachment_model "forgejo.org/models/repo"
repo_model "forgejo.org/models/repo"
"forgejo.org/models/unit"
"forgejo.org/modules/base"
"forgejo.org/modules/json"
@ -330,10 +330,10 @@ func ViewProject(ctx *context.Context) {
}
if project.CardType != project_model.CardTypeTextOnly {
issuesAttachmentMap := make(map[int64][]*attachment_model.Attachment)
issuesAttachmentMap := make(map[int64][]*repo_model.Attachment)
for _, issuesList := range issuesMap {
for _, issue := range issuesList {
if issueAttachment, err := attachment_model.GetAttachmentsByIssueIDImagesLatest(ctx, issue.ID); err == nil {
if issueAttachment, err := repo_model.GetAttachmentsByIssueIDImagesLatest(ctx, issue.ID); err == nil {
issuesAttachmentMap[issue.ID] = issueAttachment
}
}

View file

@ -33,7 +33,7 @@ import (
"forgejo.org/services/context"
"forgejo.org/services/context/upload"
"forgejo.org/services/forms"
releaseservice "forgejo.org/services/release"
release_service "forgejo.org/services/release"
)
const (
@ -506,12 +506,12 @@ func NewReleasePost(ctx *context.Context) {
return
}
attachmentChanges := make(container.Set[*releaseservice.AttachmentChange])
attachmentChangesByID := make(map[string]*releaseservice.AttachmentChange)
attachmentChanges := make(container.Set[*release_service.AttachmentChange])
attachmentChangesByID := make(map[string]*release_service.AttachmentChange)
if setting.Attachment.Enabled {
for _, uuid := range form.Files {
attachmentChanges.Add(&releaseservice.AttachmentChange{
attachmentChanges.Add(&release_service.AttachmentChange{
Action: "add",
Type: "attachment",
UUID: uuid,
@ -531,7 +531,7 @@ func NewReleasePost(ctx *context.Context) {
id = k[len(exturlPrefix):]
}
if _, ok := attachmentChangesByID[id]; !ok {
attachmentChangesByID[id] = &releaseservice.AttachmentChange{
attachmentChangesByID[id] = &release_service.AttachmentChange{
Action: "add",
Type: "external",
}
@ -559,7 +559,7 @@ func NewReleasePost(ctx *context.Context) {
}
if len(form.TagOnly) > 0 {
if err = releaseservice.CreateNewTag(ctx, ctx.Doer, ctx.Repo.Repository, form.Target, form.TagName, msg); err != nil {
if err = release_service.CreateNewTag(ctx, ctx.Doer, ctx.Repo.Repository, form.Target, form.TagName, msg); err != nil {
if models.IsErrTagAlreadyExists(err) {
e := err.(models.ErrTagAlreadyExists)
ctx.Flash.Error(ctx.Tr("repo.branch.tag_collision", e.TagName))
@ -603,7 +603,7 @@ func NewReleasePost(ctx *context.Context) {
IsTag: false,
}
if err = releaseservice.CreateRelease(ctx.Repo.GitRepo, rel, msg, attachmentChanges.Values()); err != nil {
if err = release_service.CreateRelease(ctx.Repo.GitRepo, rel, msg, attachmentChanges.Values()); err != nil {
ctx.Data["Err_TagName"] = true
switch {
case repo_model.IsErrReleaseAlreadyExist(err):
@ -635,7 +635,7 @@ func NewReleasePost(ctx *context.Context) {
rel.HideArchiveLinks = form.HideArchiveLinks
rel.IsTag = false
if err = releaseservice.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, true, attachmentChanges.Values()); err != nil {
if err = release_service.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, true, attachmentChanges.Values()); err != nil {
ctx.Data["Err_TagName"] = true
switch {
case repo_model.IsErrInvalidExternalURL(err):
@ -743,12 +743,12 @@ func EditReleasePost(ctx *context.Context) {
const newPrefix = "attachment-new-"
const namePrefix = "name-"
const exturlPrefix = "exturl-"
attachmentChanges := make(container.Set[*releaseservice.AttachmentChange])
attachmentChangesByID := make(map[string]*releaseservice.AttachmentChange)
attachmentChanges := make(container.Set[*release_service.AttachmentChange])
attachmentChangesByID := make(map[string]*release_service.AttachmentChange)
if setting.Attachment.Enabled {
for _, uuid := range form.Files {
attachmentChanges.Add(&releaseservice.AttachmentChange{
attachmentChanges.Add(&release_service.AttachmentChange{
Action: "add",
Type: "attachment",
UUID: uuid,
@ -757,7 +757,7 @@ func EditReleasePost(ctx *context.Context) {
for k, v := range ctx.Req.Form {
if strings.HasPrefix(k, delPrefix) && v[0] == "true" {
attachmentChanges.Add(&releaseservice.AttachmentChange{
attachmentChanges.Add(&release_service.AttachmentChange{
Action: "delete",
UUID: k[len(delPrefix):],
})
@ -781,7 +781,7 @@ func EditReleasePost(ctx *context.Context) {
}
if _, ok := attachmentChangesByID[uuid]; !ok {
attachmentChangesByID[uuid] = &releaseservice.AttachmentChange{
attachmentChangesByID[uuid] = &release_service.AttachmentChange{
Type: "attachment",
UUID: uuid,
}
@ -810,7 +810,7 @@ func EditReleasePost(ctx *context.Context) {
rel.IsDraft = len(form.Draft) > 0
rel.IsPrerelease = form.Prerelease
rel.HideArchiveLinks = form.HideArchiveLinks
if err = releaseservice.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, false, attachmentChanges.Values()); err != nil {
if err = release_service.UpdateRelease(ctx, ctx.Doer, ctx.Repo.GitRepo, rel, false, attachmentChanges.Values()); err != nil {
switch {
case repo_model.IsErrInvalidExternalURL(err):
ctx.RenderWithErr(ctx.Tr("repo.release.invalid_external_url", err.(repo_model.ErrInvalidExternalURL).ExternalURL), tplReleaseNew, &form)
@ -853,7 +853,7 @@ func deleteReleaseOrTag(ctx *context.Context, isDelTag bool) {
return
}
if err := releaseservice.DeleteReleaseByID(ctx, ctx.Repo.Repository, rel, ctx.Doer, isDelTag); err != nil {
if err := release_service.DeleteReleaseByID(ctx, ctx.Repo.Repository, rel, ctx.Doer, isDelTag); err != nil {
if models.IsErrProtectedTagName(err) {
ctx.Flash.Error(ctx.Tr("repo.release.tag_name_protected"))
} else {

View file

@ -30,7 +30,7 @@ import (
asymkey_model "forgejo.org/models/asymkey"
"forgejo.org/models/db"
git_model "forgejo.org/models/git"
issue_model "forgejo.org/models/issues"
issues_model "forgejo.org/models/issues"
repo_model "forgejo.org/models/repo"
unit_model "forgejo.org/models/unit"
user_model "forgejo.org/models/user"
@ -440,7 +440,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry) {
}
} else if slices.Contains([]string{"CODEOWNERS", "docs/CODEOWNERS", ".gitea/CODEOWNERS", ".forgejo/CODEOWNERS"}, ctx.Repo.TreePath) {
if rc, size, err := blob.NewTruncatedReader(setting.UI.MaxDisplayFileSize); err == nil {
_, warnings := issue_model.GetCodeOwnersFromReader(ctx, rc, size > setting.UI.MaxDisplayFileSize)
_, warnings := issues_model.GetCodeOwnersFromReader(ctx, rc, size > setting.UI.MaxDisplayFileSize)
if len(warnings) > 0 {
ctx.Data["FileWarning"] = strings.Join(warnings, "\n")
}

View file

@ -8,7 +8,7 @@ import (
"time"
actions_model "forgejo.org/models/actions"
dbfs_model "forgejo.org/models/dbfs"
dbf_model "forgejo.org/models/dbfs"
"forgejo.org/models/unittest"
"forgejo.org/modules/test"
"forgejo.org/modules/timeutil"
@ -50,19 +50,19 @@ func TestServicesActions_transferLingeringLogs(t *testing.T) {
}
lingeringLogIDs := []int64{1, 4, 5}
assert.True(t, unittest.BeanExists(t, &dbfs_model.DbfsMeta{}, builder.In("id", []any{lingeringLogIDs}...)))
assert.True(t, unittest.BeanExists(t, &dbf_model.DbfsMeta{}, builder.In("id", []any{lingeringLogIDs}...)))
// first pass transfer logs for transferLingeringLogsMax tasks
require.NoError(t, transferLingeringLogs(t.Context(), transferLingeringLogsOpts(now)))
assert.True(t, unittest.BeanExists(t, &dbfs_model.DbfsMeta{}, builder.In("id", []any{lingeringLogIDs[transferLingeringLogsMax:]}...)))
assert.True(t, unittest.BeanExists(t, &dbf_model.DbfsMeta{}, builder.In("id", []any{lingeringLogIDs[transferLingeringLogsMax:]}...)))
for _, lingeringLogID := range lingeringLogIDs[:transferLingeringLogsMax] {
unittest.AssertNotExistsBean(t, &dbfs_model.DbfsMeta{ID: lingeringLogID})
unittest.AssertNotExistsBean(t, &dbf_model.DbfsMeta{ID: lingeringLogID})
}
// second pass transfer logs for the remainder tasks and there are none left
require.NoError(t, transferLingeringLogs(t.Context(), transferLingeringLogsOpts(now)))
for _, lingeringLogID := range lingeringLogIDs {
unittest.AssertNotExistsBean(t, &dbfs_model.DbfsMeta{ID: lingeringLogID})
unittest.AssertNotExistsBean(t, &dbf_model.DbfsMeta{ID: lingeringLogID})
}
// third pass is happilly doing nothing

View file

@ -14,7 +14,7 @@ import (
"forgejo.org/modules/log"
api "forgejo.org/modules/structs"
"forgejo.org/modules/util"
ctx "forgejo.org/services/context"
app_context "forgejo.org/services/context"
)
// ToCommitUser convert a git.Signature to an api.CommitUser
@ -78,7 +78,7 @@ type ToCommitOptions struct {
Files bool
}
func ParseCommitOptions(ctx *ctx.APIContext) ToCommitOptions {
func ParseCommitOptions(ctx *app_context.APIContext) ToCommitOptions {
return ToCommitOptions{
Stat: ctx.FormString("stat") == "" || ctx.FormBool("stat"),
Files: ctx.FormString("files") == "" || ctx.FormBool("files"),

View file

@ -7,9 +7,9 @@ import (
"context"
"strconv"
action_model "forgejo.org/models/actions"
issue_model "forgejo.org/models/issues"
package_model "forgejo.org/models/packages"
actions_model "forgejo.org/models/actions"
issues_model "forgejo.org/models/issues"
packages_model "forgejo.org/models/packages"
quota_model "forgejo.org/models/quota"
repo_model "forgejo.org/models/repo"
api "forgejo.org/modules/structs"
@ -102,14 +102,14 @@ func ToQuotaUsedAttachmentList(ctx context.Context, attachments []*repo_model.At
return release.APIURL(), release.HTMLURL(), nil
}
if a.CommentID != 0 {
comment, err := issue_model.GetCommentByID(ctx, a.CommentID)
comment, err := issues_model.GetCommentByID(ctx, a.CommentID)
if err != nil {
return "", "", err
}
return comment.APIURL(ctx), comment.HTMLURL(ctx), nil
}
if a.IssueID != 0 {
issue, err := issue_model.GetIssueByID(ctx, a.IssueID)
issue, err := issues_model.GetIssueByID(ctx, a.IssueID)
if err != nil {
return "", "", err
}
@ -141,10 +141,10 @@ func ToQuotaUsedAttachmentList(ctx context.Context, attachments []*repo_model.At
return &result, nil
}
func ToQuotaUsedPackageList(ctx context.Context, packages []*package_model.PackageVersion) (*api.QuotaUsedPackageList, error) {
func ToQuotaUsedPackageList(ctx context.Context, packages []*packages_model.PackageVersion) (*api.QuotaUsedPackageList, error) {
result := make(api.QuotaUsedPackageList, len(packages))
for i, pv := range packages {
d, err := package_model.GetPackageDescriptor(ctx, pv)
d, err := packages_model.GetPackageDescriptor(ctx, pv)
if err != nil {
return nil, err
}
@ -166,10 +166,10 @@ func ToQuotaUsedPackageList(ctx context.Context, packages []*package_model.Packa
return &result, nil
}
func ToQuotaUsedArtifactList(ctx context.Context, artifacts []*action_model.ActionArtifact) (*api.QuotaUsedArtifactList, error) {
func ToQuotaUsedArtifactList(ctx context.Context, artifacts []*actions_model.ActionArtifact) (*api.QuotaUsedArtifactList, error) {
result := make(api.QuotaUsedArtifactList, len(artifacts))
for i, a := range artifacts {
run, err := action_model.GetRunByID(ctx, a.RunID)
run, err := actions_model.GetRunByID(ctx, a.RunID)
if err != nil {
return nil, err
}

View file

@ -17,7 +17,7 @@ import (
user_model "forgejo.org/models/user"
"forgejo.org/modules/storage"
"forgejo.org/modules/timeutil"
forgejo_attachment "forgejo.org/services/attachment"
attachment_service "forgejo.org/services/attachment"
"code.forgejo.org/f3/gof3/v3/f3"
f3_id "code.forgejo.org/f3/gof3/v3/id"
@ -162,7 +162,7 @@ func (o *attachment) Put(ctx context.Context) f3_id.NodeID {
download := o.downloadFunc()
defer download.Close()
_, err = forgejo_attachment.NewAttachment(ctx, o.forgejoAttachment, download, o.forgejoAttachment.Size)
_, err = attachment_service.NewAttachment(ctx, o.forgejoAttachment, download, o.forgejoAttachment.Size)
if err != nil {
panic(err)
}

View file

@ -10,7 +10,7 @@ import (
"forgejo.org/models/user"
"forgejo.org/modules/forgefed"
"forgejo.org/modules/log"
context_service "forgejo.org/services/context"
app_context "forgejo.org/services/context"
ap "github.com/go-ap/activitypub"
"github.com/go-ap/jsonld"
@ -32,7 +32,7 @@ func ProcessPersonInbox(ctx context.Context, user *user.User, activity *ap.Activ
return ServiceResult{}, NewErrNotAcceptablef("unsupported activity: %v", activity.Type)
}
func FollowRemoteActor(ctx *context_service.APIContext, localUser *user.User, actorURI string) error {
func FollowRemoteActor(ctx *app_context.APIContext, localUser *user.User, actorURI string) error {
_, federatedUser, federationHost, err := FindOrCreateFederatedUser(ctx.Base, actorURI)
if err != nil {
log.Error("Federated user not found (%s): %v", actorURI, err)

View file

@ -16,7 +16,7 @@ import (
fm "forgejo.org/modules/forgefed"
"forgejo.org/modules/log"
"forgejo.org/modules/validation"
context_service "forgejo.org/services/context"
app_context "forgejo.org/services/context"
ap "github.com/go-ap/activitypub"
)
@ -75,7 +75,7 @@ func ProcessLikeActivity(ctx context.Context, activity *ap.Activity, repositoryI
}
// Create or update a list of FollowingRepo structs
func StoreFollowingRepoList(ctx *context_service.Context, localRepoID int64, followingRepoList []string) (int, string, error) {
func StoreFollowingRepoList(ctx *app_context.Context, localRepoID int64, followingRepoList []string) (int, string, error) {
followingRepos := make([]*repo.FollowingRepo, 0, len(followingRepoList))
for _, uri := range followingRepoList {
federationHost, err := FindOrCreateFederationHost(ctx.Base, uri)

View file

@ -9,7 +9,7 @@ import (
actions_model "forgejo.org/models/actions"
"forgejo.org/models/db"
organization_model "forgejo.org/models/organization"
org_model "forgejo.org/models/organization"
repo_model "forgejo.org/models/repo"
user_model "forgejo.org/models/user"
"forgejo.org/modules/optional"
@ -40,7 +40,7 @@ func getActionsNowDoneTestUser(t *testing.T, name, email, notifications string)
func getActionsNowDoneTestOrg(t *testing.T, name, email string, owner *user_model.User) *user_model.User {
t.Helper()
org := new(organization_model.Organization)
org := new(org_model.Organization)
org.Name = name
org.Language = "en_US"
org.IsAdmin = false
@ -49,7 +49,7 @@ func getActionsNowDoneTestOrg(t *testing.T, name, email string, owner *user_mode
org.LastLoginUnix = 1693648327
org.CreatedUnix = 1693648027
org.Email = email
require.NoError(t, organization_model.CreateOrganization(db.DefaultContext, org, owner))
require.NoError(t, org_model.CreateOrganization(db.DefaultContext, org, owner))
return (*user_model.User)(org)
}

View file

@ -8,7 +8,7 @@ import (
"testing"
"forgejo.org/models/db"
organization_model "forgejo.org/models/organization"
org_model "forgejo.org/models/organization"
"forgejo.org/models/unittest"
user_model "forgejo.org/models/user"
"forgejo.org/modules/setting"
@ -53,7 +53,7 @@ func MockMailSettings(send func(msgs ...*Message)) func() {
func CleanUpUsers(ctx context.Context, users []*user_model.User) {
for _, u := range users {
if u.IsOrganization() {
organization_model.DeleteOrganization(ctx, (*organization_model.Organization)(u))
org_model.DeleteOrganization(ctx, (*org_model.Organization)(u))
} else {
db.DeleteByID[user_model.User](ctx, u.ID)
db.DeleteByBean(ctx, &user_model.EmailAddress{UID: u.ID})

View file

@ -8,7 +8,7 @@ import (
"time"
"forgejo.org/models/db"
report_model "forgejo.org/models/moderation"
moderation_model "forgejo.org/models/moderation"
"forgejo.org/models/unittest"
"forgejo.org/modules/timeutil"
@ -19,10 +19,10 @@ func TestRemoveResolvedReportsWhenNoTimeSet(t *testing.T) {
require.NoError(t, unittest.PrepareTestDatabase())
// reportAge needs to be an int64 to match what timeutil.Day expects so we cast the value
reportAge := int64(20)
resolvedReport := &report_model.AbuseReport{
Status: report_model.ReportStatusTypeHandled,
ReporterID: 1, ContentType: report_model.ReportedContentTypeRepository,
ContentID: 2, Category: report_model.AbuseCategoryTypeOther,
resolvedReport := &moderation_model.AbuseReport{
Status: moderation_model.ReportStatusTypeHandled,
ReporterID: 1, ContentType: moderation_model.ReportedContentTypeRepository,
ContentID: 2, Category: moderation_model.AbuseCategoryTypeOther,
CreatedUnix: timeutil.TimeStampNow(),
ResolvedUnix: timeutil.TimeStamp(time.Now().Unix() - timeutil.Day*reportAge),
}
@ -39,10 +39,10 @@ func TestRemoveResolvedReportsWhenMatchTimeSet(t *testing.T) {
require.NoError(t, unittest.PrepareTestDatabase())
// keepReportsFor needs to an int64 to match what timeutil.Day expects so we cast the value
keepReportsFor := int64(4)
resolvedReport := &report_model.AbuseReport{
Status: report_model.ReportStatusTypeHandled,
ReporterID: 1, ContentType: report_model.ReportedContentTypeRepository,
ContentID: 2, Category: report_model.AbuseCategoryTypeOther,
resolvedReport := &moderation_model.AbuseReport{
Status: moderation_model.ReportStatusTypeHandled,
ReporterID: 1, ContentType: moderation_model.ReportedContentTypeRepository,
ContentID: 2, Category: moderation_model.AbuseCategoryTypeOther,
CreatedUnix: timeutil.TimeStampNow(),
ResolvedUnix: timeutil.TimeStamp(time.Now().Unix() - timeutil.Day*keepReportsFor),
}
@ -58,10 +58,10 @@ func TestRemoveResolvedReportsWhenMatchTimeSet(t *testing.T) {
func TestRemoveResolvedReportsWhenTimeSetButReportNew(t *testing.T) {
require.NoError(t, unittest.PrepareTestDatabase())
resolvedReport := &report_model.AbuseReport{
Status: report_model.ReportStatusTypeHandled,
ReporterID: 1, ContentType: report_model.ReportedContentTypeRepository,
ContentID: 2, Category: report_model.AbuseCategoryTypeOther,
resolvedReport := &moderation_model.AbuseReport{
Status: moderation_model.ReportStatusTypeHandled,
ReporterID: 1, ContentType: moderation_model.ReportedContentTypeRepository,
ContentID: 2, Category: moderation_model.AbuseCategoryTypeOther,
CreatedUnix: timeutil.TimeStampNow(),
ResolvedUnix: timeutil.TimeStampNow(),
}
@ -78,10 +78,10 @@ func TestDoesNotRemoveOpenReports(t *testing.T) {
require.NoError(t, unittest.PrepareTestDatabase())
// keepReportsFor needs to an int64 to match what timeutil.Day expects so we cast the value
keepReportsFor := int64(4)
resolvedReport := &report_model.AbuseReport{
Status: report_model.ReportStatusTypeOpen,
ReporterID: 1, ContentType: report_model.ReportedContentTypeRepository,
ContentID: 2, Category: report_model.AbuseCategoryTypeOther,
resolvedReport := &moderation_model.AbuseReport{
Status: moderation_model.ReportStatusTypeOpen,
ReporterID: 1, ContentType: moderation_model.ReportedContentTypeRepository,
ContentID: 2, Category: moderation_model.AbuseCategoryTypeOther,
CreatedUnix: timeutil.TimeStampNow(),
ResolvedUnix: timeutil.TimeStamp(time.Now().Unix() - timeutil.Day*keepReportsFor),
}

View file

@ -8,7 +8,7 @@ import (
"fmt"
"forgejo.org/modules/util"
gitea_ctx "forgejo.org/services/context"
app_context "forgejo.org/services/context"
)
type ContainedLinks struct { // TODO: better name?
@ -23,7 +23,7 @@ type namedLink struct { // TODO: better name?
}
// LoadBranchesAndTags creates a new repository branch
func LoadBranchesAndTags(ctx context.Context, baseRepo *gitea_ctx.Repository, commitSHA string) (*ContainedLinks, error) {
func LoadBranchesAndTags(ctx context.Context, baseRepo *app_context.Repository, commitSHA string) (*ContainedLinks, error) {
containedTags, err := baseRepo.GitRepo.ListOccurrences(ctx, "tag", commitSHA)
if err != nil {
return nil, fmt.Errorf("encountered a problem while querying %s: %w", "tags", err)

View file

@ -8,7 +8,7 @@ import (
auth_model "forgejo.org/models/auth"
"forgejo.org/models/db"
organization_model "forgejo.org/models/organization"
org_model "forgejo.org/models/organization"
"forgejo.org/models/unittest"
user_model "forgejo.org/models/user"
"forgejo.org/modules/setting"
@ -97,7 +97,7 @@ func TestReplacePrimaryEmailAddress(t *testing.T) {
})
t.Run("Organization", func(t *testing.T) {
org := unittest.AssertExistsAndLoadBean(t, &organization_model.Organization{ID: 3})
org := unittest.AssertExistsAndLoadBean(t, &org_model.Organization{ID: 3})
assert.Equal(t, "org3@example.com", org.Email)

View file

@ -12,7 +12,7 @@ import (
repo_model "forgejo.org/models/repo"
"forgejo.org/models/unittest"
user_model "forgejo.org/models/user"
forgejo_context "forgejo.org/services/context"
app_context "forgejo.org/services/context"
"forgejo.org/tests"
"github.com/stretchr/testify/assert"
@ -62,7 +62,7 @@ func TestActionsVariablesModification(t *testing.T) {
assert.Equal(t, "Failed to find the variable.", error.Error)
} else {
sess.MakeRequest(t, req, http.StatusOK)
flashCookie := sess.GetCookie(forgejo_context.CookieNameFlash)
flashCookie := sess.GetCookie(app_context.CookieNameFlash)
assert.NotNil(t, flashCookie)
assert.Equal(t, "success%3DThe%2Bvariable%2Bhas%2Bbeen%2Bedited.", flashCookie.Value)
}
@ -75,7 +75,7 @@ func TestActionsVariablesModification(t *testing.T) {
assert.Equal(t, "Failed to find the variable.", error.Error)
} else {
sess.MakeRequest(t, req, http.StatusOK)
flashCookie := sess.GetCookie(forgejo_context.CookieNameFlash)
flashCookie := sess.GetCookie(app_context.CookieNameFlash)
assert.NotNil(t, flashCookie)
assert.Equal(t, "success%3DThe%2Bvariable%2Bhas%2Bbeen%2Bremoved.", flashCookie.Value)
}

View file

@ -13,12 +13,12 @@ import (
"forgejo.org/models/activities"
"forgejo.org/models/db"
issue_model "forgejo.org/models/issues"
issues_model "forgejo.org/models/issues"
repo_model "forgejo.org/models/repo"
"forgejo.org/models/unittest"
user_model "forgejo.org/models/user"
"forgejo.org/modules/translation"
forgejo_context "forgejo.org/services/context"
app_context "forgejo.org/services/context"
"forgejo.org/tests"
"github.com/stretchr/testify/assert"
@ -148,7 +148,7 @@ func TestBlockUserFromOrganization(t *testing.T) {
})
session.MakeRequest(t, req, http.StatusSeeOther)
assert.False(t, unittest.BeanExists(t, &user_model.BlockedUser{BlockID: doer.ID, UserID: org.ID}))
flashCookie := session.GetCookie(forgejo_context.CookieNameFlash)
flashCookie := session.GetCookie(app_context.CookieNameFlash)
assert.NotNil(t, flashCookie)
assert.Equal(t, "error%3DYou%2Bcannot%2Bblock%2Byourself.", flashCookie.Value)
})
@ -167,10 +167,10 @@ func TestBlockActions(t *testing.T) {
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1, OwnerID: doer.ID})
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2, OwnerID: doer.ID})
repo7 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 7, OwnerID: blockedUser2.ID})
issue4 := unittest.AssertExistsAndLoadBean(t, &issue_model.Issue{ID: 4, RepoID: repo2.ID})
issue4 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 4, RepoID: repo2.ID})
issue4URL := fmt.Sprintf("/%s/issues/%d", repo2.FullName(), issue4.Index)
repo42 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 42, OwnerID: doer.ID})
issue10 := unittest.AssertExistsAndLoadBean(t, &issue_model.Issue{ID: 10, RepoID: repo42.ID}, unittest.Cond("poster_id != ?", doer.ID))
issue10 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 10, RepoID: repo42.ID}, unittest.Cond("poster_id != ?", doer.ID))
issue10URL := fmt.Sprintf("/%s/issues/%d", repo42.FullName(), issue10.Index)
// NOTE: Sessions shouldn't be shared, because in some situations flash
// messages are persistent and that would interfere with accurate test
@ -253,7 +253,7 @@ func TestBlockActions(t *testing.T) {
defer tests.PrintCurrentTest(t)()
repo5 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 5})
issue15 := unittest.AssertExistsAndLoadBean(t, &issue_model.Issue{ID: 15, RepoID: repo5.ID, PosterID: doer.ID})
issue15 := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 15, RepoID: repo5.ID, PosterID: doer.ID})
session := loginUser(t, blockedUser.Name)
issueURL := fmt.Sprintf("/%s/%s/issues/%d", url.PathEscape(repo5.OwnerName), url.PathEscape(repo5.Name), issue15.Index)
@ -302,7 +302,7 @@ func TestBlockActions(t *testing.T) {
t.Run("On a comment", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
comment := unittest.AssertExistsAndLoadBean(t, &issue_model.Comment{ID: 1008, PosterID: doer.ID, IssueID: issue4.ID})
comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 1008, PosterID: doer.ID, IssueID: issue4.ID})
session := loginUser(t, blockedUser.Name)
@ -373,7 +373,7 @@ func TestBlockActions(t *testing.T) {
})
session.MakeRequest(t, req, http.StatusSeeOther)
flashCookie := session.GetCookie(forgejo_context.CookieNameFlash)
flashCookie := session.GetCookie(app_context.CookieNameFlash)
assert.NotNil(t, flashCookie)
assert.Equal(t, "error%3DCannot%2Badd%2Bthe%2Bcollaborator%252C%2Bbecause%2Bthe%2Brepository%2Bowner%2Bhas%2Bblocked%2Bthem.", flashCookie.Value)
})
@ -389,7 +389,7 @@ func TestBlockActions(t *testing.T) {
})
session.MakeRequest(t, req, http.StatusSeeOther)
flashCookie := session.GetCookie(forgejo_context.CookieNameFlash)
flashCookie := session.GetCookie(app_context.CookieNameFlash)
assert.NotNil(t, flashCookie)
assert.Equal(t, "error%3DCannot%2Badd%2Bthe%2Bcollaborator%252C%2Bbecause%2Bthey%2Bhave%2Bblocked%2Bthe%2Brepository%2Bowner.", flashCookie.Value)
})
@ -424,7 +424,7 @@ func TestBlockedNotification(t *testing.T) {
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
normalUser := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
blockedUser := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 10})
issue := unittest.AssertExistsAndLoadBean(t, &issue_model.Issue{ID: 1000})
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1000})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID})
issueURL := fmt.Sprintf("%s/issues/%d", repo.FullName(), issue.Index)
notificationBean := &activities.Notification{UserID: doer.ID, RepoID: repo.ID, IssueID: issue.ID}

View file

@ -10,7 +10,7 @@ import (
issues_model "forgejo.org/models/issues"
"forgejo.org/models/unittest"
user_model "forgejo.org/models/user"
forgejo_context "forgejo.org/services/context"
app_context "forgejo.org/services/context"
"forgejo.org/tests"
"github.com/stretchr/testify/assert"
@ -30,7 +30,7 @@ func TestIssueAddTimeManually(t *testing.T) {
session.MakeRequest(t, NewRequest(t, "POST", issue2.Link()+"/times/add"), http.StatusSeeOther)
flashCookie := session.GetCookie(forgejo_context.CookieNameFlash)
flashCookie := session.GetCookie(app_context.CookieNameFlash)
assert.NotNil(t, flashCookie)
assert.Contains(t, flashCookie.Value, "error%3DNo%2Btime%2Bwas%2Bentered.")
})
@ -42,7 +42,7 @@ func TestIssueAddTimeManually(t *testing.T) {
"hours": "-1",
}), http.StatusSeeOther)
flashCookie := session.GetCookie(forgejo_context.CookieNameFlash)
flashCookie := session.GetCookie(app_context.CookieNameFlash)
assert.NotNil(t, flashCookie)
assert.Contains(t, flashCookie.Value, "error%3DHours%2Bmust%2Bbe%2Ba%2Bnumber%2Bbetween%2B0%2Band%2B1%252C000.")
})
@ -54,7 +54,7 @@ func TestIssueAddTimeManually(t *testing.T) {
"minutes": "-1",
}), http.StatusSeeOther)
flashCookie := session.GetCookie(forgejo_context.CookieNameFlash)
flashCookie := session.GetCookie(app_context.CookieNameFlash)
assert.NotNil(t, flashCookie)
assert.Contains(t, flashCookie.Value, "error%3DMinutes%2Bmust%2Bbe%2Ba%2Bnumber%2Bbetween%2B0%2Band%2B1%252C000.")
})

View file

@ -15,7 +15,7 @@ import (
"forgejo.org/modules/git"
"forgejo.org/modules/gitrepo"
"forgejo.org/modules/migration"
forgejo_context "forgejo.org/services/context"
app_context "forgejo.org/services/context"
mirror_service "forgejo.org/services/mirror"
release_service "forgejo.org/services/release"
repo_service "forgejo.org/services/repository"
@ -114,7 +114,7 @@ func TestPullMirrorRedactCredentials(t *testing.T) {
"action": "mirror-sync",
}), http.StatusSeeOther)
flashCookie := session.GetCookie(forgejo_context.CookieNameFlash)
flashCookie := session.GetCookie(app_context.CookieNameFlash)
assert.NotNil(t, flashCookie)
assert.Equal(t, "info%3DPulling%2Bchanges%2Bfrom%2Bthe%2Bremote%2Bhttps%253A%252F%252Fexample.com%252Fexample%252Fexample.git%2Bat%2Bthe%2Bmoment.", flashCookie.Value)
}

View file

@ -41,7 +41,7 @@ import (
"forgejo.org/modules/test"
"forgejo.org/modules/translation"
"forgejo.org/services/automerge"
forgejo_context "forgejo.org/services/context"
app_context "forgejo.org/services/context"
"forgejo.org/services/forms"
"forgejo.org/services/pull"
commitstatus_service "forgejo.org/services/repository/commitstatus"
@ -1112,7 +1112,7 @@ func TestPullDeleteBranchPerms(t *testing.T) {
})
user4Session.MakeRequest(t, req, http.StatusOK)
flashCookie := user4Session.GetCookie(forgejo_context.CookieNameFlash)
flashCookie := user4Session.GetCookie(app_context.CookieNameFlash)
assert.NotNil(t, flashCookie)
assert.Equal(t, "error%3DYou%2Bdon%2527t%2Bhave%2Bpermission%2Bto%2Bdelete%2Bthe%2Bhead%2Bbranch.", flashCookie.Value)

View file

@ -25,7 +25,7 @@ import (
api "forgejo.org/modules/structs"
"forgejo.org/modules/test"
"forgejo.org/routers"
forgejo_context "forgejo.org/services/context"
app_context "forgejo.org/services/context"
repo_service "forgejo.org/services/repository"
"forgejo.org/tests"
@ -708,7 +708,7 @@ func (ctx *quotaWebEnvAsContext) ExpectFlashMessageContains(parts ...string) {
func (ctx *quotaWebEnvAsContext) ExpectFlashCookieContains(parts ...string) {
ctx.t.Helper()
flashCookie := ctx.Doer.Session.GetCookie(forgejo_context.CookieNameFlash)
flashCookie := ctx.Doer.Session.GetCookie(app_context.CookieNameFlash)
assert.NotNil(ctx.t, flashCookie)
// Need to decode the cookie twice

View file

@ -12,7 +12,7 @@ import (
repo_model "forgejo.org/models/repo"
"forgejo.org/models/unittest"
user_model "forgejo.org/models/user"
forgejo_context "forgejo.org/services/context"
app_context "forgejo.org/services/context"
"forgejo.org/tests"
"github.com/stretchr/testify/assert"
@ -54,7 +54,7 @@ func TestRunnerModification(t *testing.T) {
sess.MakeRequest(t, req, http.StatusNotFound)
} else {
sess.MakeRequest(t, req, http.StatusSeeOther)
flashCookie := sess.GetCookie(forgejo_context.CookieNameFlash)
flashCookie := sess.GetCookie(app_context.CookieNameFlash)
assert.NotNil(t, flashCookie)
assert.Equal(t, "success%3DRunner%2Bupdated%2Bsuccessfully", flashCookie.Value)
}
@ -64,7 +64,7 @@ func TestRunnerModification(t *testing.T) {
sess.MakeRequest(t, req, http.StatusNotFound)
} else {
sess.MakeRequest(t, req, http.StatusOK)
flashCookie := sess.GetCookie(forgejo_context.CookieNameFlash)
flashCookie := sess.GetCookie(app_context.CookieNameFlash)
assert.NotNil(t, flashCookie)
assert.Equal(t, "success%3DRunner%2Bdeleted%2Bsuccessfully", flashCookie.Value)
}

View file

@ -16,7 +16,7 @@ import (
user_model "forgejo.org/models/user"
"forgejo.org/modules/gitrepo"
issue_service "forgejo.org/services/issue"
pr_service "forgejo.org/services/pull"
pull_service "forgejo.org/services/pull"
files_service "forgejo.org/services/repository/files"
"forgejo.org/tests"
@ -140,10 +140,10 @@ func TestDashboardReviewWorkflows(t *testing.T) {
pr := createPullRequest(t, user4, repo, "testing", "My very first PR!")
review, _, err := pr_service.SubmitReview(t.Context(), user4, gitRepo, pr.Issue, issues.ReviewTypeReject, "This isn't good enough!", "HEAD", []string{})
review, _, err := pull_service.SubmitReview(t.Context(), user4, gitRepo, pr.Issue, issues.ReviewTypeReject, "This isn't good enough!", "HEAD", []string{})
require.NoError(t, err)
_, err = pr_service.DismissReview(t.Context(), review.ID, repo.ID, "Come on, give the newbie a break!", user4, true, true)
_, err = pull_service.DismissReview(t.Context(), review.ID, repo.ID, "Come on, give the newbie a break!", user4, true, true)
require.NoError(t, err)
response := sess.MakeRequest(t, NewRequest(t, "GET", "/"), http.StatusOK)

View file

@ -14,7 +14,7 @@ import (
"forgejo.org/modules/setting"
"forgejo.org/modules/test"
"forgejo.org/modules/timeutil"
forgejo_context "forgejo.org/services/context"
app_context "forgejo.org/services/context"
"forgejo.org/tests"
"github.com/stretchr/testify/assert"
@ -35,7 +35,7 @@ func TestUserRedirect(t *testing.T) {
})
session.MakeRequest(t, req, http.StatusSeeOther)
flashCookie := session.GetCookie(forgejo_context.CookieNameFlash)
flashCookie := session.GetCookie(app_context.CookieNameFlash)
assert.NotNil(t, flashCookie)
assert.Equal(t, "success%3DYour%2Bprofile%2Bhas%2Bbeen%2Bupdated.", flashCookie.Value)
@ -67,7 +67,7 @@ func TestUserRedirect(t *testing.T) {
})
session.MakeRequest(t, req, http.StatusSeeOther)
flashCookie := session.GetCookie(forgejo_context.CookieNameFlash)
flashCookie := session.GetCookie(app_context.CookieNameFlash)
assert.NotNil(t, flashCookie)
assert.Contains(t, flashCookie.Value, "error%3DThe%2Busername%2Bcannot%2Bbe%2Bclaimed%252C%2Bbecause%2Bits%2Bcooldown%2Bperiod%2Bis%2Bnot%2Byet%2Bover.%2BIt%2Bcan%2Bbe%2Bclaimed%2Bon")
})
@ -82,7 +82,7 @@ func TestUserRedirect(t *testing.T) {
"login_type": "0-0",
})
session.MakeRequest(t, req, http.StatusSeeOther)
flashCookie := session.GetCookie(forgejo_context.CookieNameFlash)
flashCookie := session.GetCookie(app_context.CookieNameFlash)
assert.NotNil(t, flashCookie)
assert.Equal(t, "success%3DThe%2Buser%2Baccount%2Bhas%2Bbeen%2Bupdated.", flashCookie.Value)
@ -98,7 +98,7 @@ func TestUserRedirect(t *testing.T) {
})
session.MakeRequest(t, req, http.StatusSeeOther)
flashCookie := session.GetCookie(forgejo_context.CookieNameFlash)
flashCookie := session.GetCookie(app_context.CookieNameFlash)
assert.NotNil(t, flashCookie)
assert.Equal(t, "success%3DYour%2Bprofile%2Bhas%2Bbeen%2Bupdated.", flashCookie.Value)
@ -109,7 +109,7 @@ func TestUserRedirect(t *testing.T) {
})
session.MakeRequest(t, req, http.StatusSeeOther)
flashCookie = session.GetCookie(forgejo_context.CookieNameFlash)
flashCookie = session.GetCookie(app_context.CookieNameFlash)
assert.NotNil(t, flashCookie)
assert.Equal(t, "success%3DYour%2Bprofile%2Bhas%2Bbeen%2Bupdated.", flashCookie.Value)