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

@ -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")
}