1
Fork 0

Merge pull request 'feat: upgrade F3 to v3.7.0' (#5004) from earl-warren/forgejo:wip-f3 into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/5004
Reviewed-by: Otto <otto@codeberg.org>
This commit is contained in:
Earl Warren 2024-08-18 19:30:15 +00:00
commit 90e03e410a
23 changed files with 50 additions and 56 deletions

View file

@ -87,7 +87,7 @@ func (o *asset) Get(ctx context.Context) bool {
node := o.GetNode()
o.Trace("%s", node.GetID())
id := f3_util.ParseInt(string(node.GetID()))
id := node.GetID().Int64()
asset, err := repo_model.GetAttachmentByID(ctx, id)
if repo_model.IsErrAttachmentNotExist(err) {
@ -154,7 +154,7 @@ func (o *asset) Put(ctx context.Context) generic.NodeID {
}
o.Trace("asset created %d", o.forgejoAsset.ID)
return generic.NodeID(fmt.Sprintf("%d", o.forgejoAsset.ID))
return generic.NewNodeID(o.forgejoAsset.ID)
}
func (o *asset) Delete(ctx context.Context) {

View file

@ -72,7 +72,7 @@ func (o *comment) Get(ctx context.Context) bool {
node := o.GetNode()
o.Trace("%s", node.GetID())
id := f3_util.ParseInt(string(node.GetID()))
id := node.GetID().Int64()
comment, err := issues_model.GetCommentByID(ctx, id)
if issues_model.IsErrCommentNotExist(err) {
@ -105,7 +105,7 @@ func (o *comment) Put(ctx context.Context) generic.NodeID {
panic(err)
}
o.Trace("comment created %d", o.forgejoComment.ID)
return generic.NodeID(fmt.Sprintf("%d", o.forgejoComment.ID))
return generic.NewNodeID(o.forgejoComment.ID)
}
func (o *comment) Delete(ctx context.Context) {

View file

@ -39,5 +39,5 @@ func (o *container) Patch(ctx context.Context) {
}
func (o *container) upsert(context.Context) generic.NodeID {
return generic.NodeID(o.getKind())
return generic.NewNodeID(o.getKind())
}

View file

@ -50,7 +50,7 @@ func (o *forge) getOwnersPath(ctx context.Context, id string) f3_tree.Path {
func (o *forge) Equals(context.Context, generic.NodeInterface) bool { return true }
func (o *forge) Get(context.Context) bool { return true }
func (o *forge) Put(context.Context) generic.NodeID { return generic.NodeID("forge") }
func (o *forge) Put(context.Context) generic.NodeID { return generic.NewNodeID("forge") }
func (o *forge) Patch(context.Context) {}
func (o *forge) Delete(context.Context) {}
func (o *forge) NewFormat() f3.Interface { return &f3.Forge{} }

View file

@ -96,7 +96,7 @@ func (o *issue) FromFormat(content f3.Interface) {
},
Content: issue.Content,
Milestone: milestone,
IsClosed: issue.State == "closed",
IsClosed: issue.State == f3.IssueStateClosed,
CreatedUnix: timeutil.TimeStamp(issue.Created.Unix()),
UpdatedUnix: timeutil.TimeStamp(issue.Updated.Unix()),
IsLocked: issue.IsLocked,
@ -124,7 +124,7 @@ func (o *issue) Get(ctx context.Context) bool {
o.Trace("%s", node.GetID())
project := f3_tree.GetProjectID(o.GetNode())
id := f3_util.ParseInt(string(node.GetID()))
id := node.GetID().Int64()
issue, err := issues_model.GetIssueByIndex(ctx, project, id)
if issues_model.IsErrIssueNotExist(err) {
@ -144,9 +144,9 @@ func (o *issue) Get(ctx context.Context) bool {
func (o *issue) Patch(ctx context.Context) {
node := o.GetNode()
project := f3_tree.GetProjectID(o.GetNode())
id := f3_util.ParseInt(string(node.GetID()))
id := node.GetID().Int64()
o.Trace("repo_id = %d, index = %d", project, id)
if _, err := db.GetEngine(ctx).Where("`repo_id` = ? AND `index` = ?", project, id).Cols("name", "content").Update(o.forgejoIssue); err != nil {
if _, err := db.GetEngine(ctx).Where("`repo_id` = ? AND `index` = ?", project, id).Cols("name", "content", "is_closed").Update(o.forgejoIssue); err != nil {
panic(fmt.Errorf("%v %v", o.forgejoIssue, err))
}
}
@ -207,7 +207,7 @@ func (o *issue) Put(ctx context.Context) generic.NodeID {
}
o.Trace("issue created %d/%d", o.forgejoIssue.ID, o.forgejoIssue.Index)
return generic.NodeID(fmt.Sprintf("%d", o.forgejoIssue.Index))
return generic.NewNodeID(o.forgejoIssue.Index)
}
func (o *issue) Delete(ctx context.Context) {

View file

@ -65,7 +65,7 @@ func (o *label) Get(ctx context.Context) bool {
o.Trace("%s", node.GetID())
project := f3_tree.GetProjectID(o.GetNode())
id := f3_util.ParseInt(string(node.GetID()))
id := node.GetID().Int64()
label, err := issues_model.GetLabelInRepoByID(ctx, project, id)
if issues_model.IsErrRepoLabelNotExist(err) {
@ -80,7 +80,7 @@ func (o *label) Get(ctx context.Context) bool {
func (o *label) Patch(ctx context.Context) {
o.Trace("%d", o.forgejoLabel.ID)
if _, err := db.GetEngine(ctx).ID(o.forgejoLabel.ID).Cols("name", "description").Update(o.forgejoLabel); err != nil {
if _, err := db.GetEngine(ctx).ID(o.forgejoLabel.ID).Cols("name", "description", "color").Update(o.forgejoLabel); err != nil {
panic(fmt.Errorf("UpdateLabelCols: %v %v", o.forgejoLabel, err))
}
}
@ -94,7 +94,7 @@ func (o *label) Put(ctx context.Context) generic.NodeID {
panic(err)
}
o.Trace("label created %d", o.forgejoLabel.ID)
return generic.NodeID(fmt.Sprintf("%d", o.forgejoLabel.ID))
return generic.NewNodeID(o.forgejoLabel.ID)
}
func (o *label) Delete(ctx context.Context) {

View file

@ -89,7 +89,7 @@ func (o *milestone) FromFormat(content f3.Interface) {
ID: f3_util.ParseInt(milestone.GetID()),
Name: milestone.Title,
Content: milestone.Description,
IsClosed: milestone.State == "closed",
IsClosed: milestone.State == f3.MilestoneStateClosed,
CreatedUnix: timeutil.TimeStamp(milestone.Created.Unix()),
UpdatedUnix: timeutil.TimeStamp(milestone.Updated.Unix()),
ClosedDateUnix: closed,
@ -102,7 +102,7 @@ func (o *milestone) Get(ctx context.Context) bool {
o.Trace("%s", node.GetID())
project := f3_tree.GetProjectID(o.GetNode())
id := f3_util.ParseInt(string(node.GetID()))
id := node.GetID().Int64()
milestone, err := issues_model.GetMilestoneByRepoID(ctx, project, id)
if issues_model.IsErrMilestoneNotExist(err) {
@ -131,7 +131,7 @@ func (o *milestone) Put(ctx context.Context) generic.NodeID {
panic(err)
}
o.Trace("milestone created %d", o.forgejoMilestone.ID)
return generic.NodeID(fmt.Sprintf("%d", o.forgejoMilestone.ID))
return generic.NewNodeID(o.forgejoMilestone.ID)
}
func (o *milestone) Delete(ctx context.Context) {

View file

@ -62,7 +62,7 @@ func (o *organization) FromFormat(content f3.Interface) {
func (o *organization) Get(ctx context.Context) bool {
node := o.GetNode()
o.Trace("%s", node.GetID())
id := f3_util.ParseInt(string(node.GetID()))
id := node.GetID().Int64()
organization, err := org_model.GetOrgByID(ctx, id)
if user_model.IsErrUserNotExist(err) {
return false
@ -94,7 +94,7 @@ func (o *organization) Put(ctx context.Context) generic.NodeID {
panic(err)
}
return generic.NodeID(fmt.Sprintf("%d", o.forgejoOrganization.ID))
return generic.NewNodeID(o.forgejoOrganization.ID)
}
func (o *organization) Delete(ctx context.Context) {

View file

@ -42,7 +42,7 @@ func (o *organizations) GetIDFromName(ctx context.Context, name string) generic.
panic(fmt.Errorf("GetOrganizationByName: %v", err))
}
return generic.NodeID(fmt.Sprintf("%d", organization.ID))
return generic.NewNodeID(organization.ID)
}
func newOrganizations() generic.NodeDriverInterface {

View file

@ -96,7 +96,7 @@ func (o *project) FromFormat(content f3.Interface) {
func (o *project) Get(ctx context.Context) bool {
node := o.GetNode()
o.Trace("%s", node.GetID())
id := f3_util.ParseInt(string(node.GetID()))
id := node.GetID().Int64()
u, err := repo_model.GetRepositoryByID(ctx, id)
if repo_model.IsErrRepoNotExist(err) {
return false
@ -166,7 +166,7 @@ func (o *project) Put(ctx context.Context) generic.NodeID {
o.forgejoProject = repo
o.Trace("project created %d", o.forgejoProject.ID)
}
return generic.NodeID(fmt.Sprintf("%d", o.forgejoProject.ID))
return generic.NewNodeID(o.forgejoProject.ID)
}
func (o *project) Delete(ctx context.Context) {

View file

@ -13,7 +13,6 @@ import (
f3_tree "code.forgejo.org/f3/gof3/v3/tree/f3"
"code.forgejo.org/f3/gof3/v3/tree/generic"
f3_util "code.forgejo.org/f3/gof3/v3/util"
)
type projects struct {
@ -31,7 +30,7 @@ func (o *projects) GetIDFromName(ctx context.Context, name string) generic.NodeI
panic(fmt.Errorf("error GetRepositoryByOwnerAndName(%s, %s): %v", owner, name, err))
}
return generic.NodeID(fmt.Sprintf("%d", forgejoProject.ID))
return generic.NewNodeID(forgejoProject.ID)
}
func (o *projects) ListPage(ctx context.Context, page int) generic.ChildrenSlice {
@ -41,7 +40,7 @@ func (o *projects) ListPage(ctx context.Context, page int) generic.ChildrenSlice
forgejoProjects, _, err := repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{Page: page, PageSize: pageSize},
OwnerID: f3_util.ParseInt(string(owner.GetID())),
OwnerID: owner.GetID().Int64(),
Private: true,
})
if err != nil {

View file

@ -51,7 +51,7 @@ func (o *pullRequest) repositoryToReference(ctx context.Context, repository *rep
if repository == nil {
panic("unexpected nil repository")
}
forge := o.getTree().GetRoot().GetChild(f3_tree.KindForge).GetDriver().(*forge)
forge := o.getTree().GetRoot().GetChild(generic.NewNodeID(f3_tree.KindForge)).GetDriver().(*forge)
owners := forge.getOwnersPath(ctx, fmt.Sprintf("%d", repository.OwnerID))
return f3_tree.NewRepositoryReference(owners.String(), repository.OwnerID, repository.ID)
}
@ -172,7 +172,7 @@ func (o *pullRequest) FromFormat(content f3.Interface) {
Title: pullRequest.Title,
Content: pullRequest.Content,
Milestone: milestone,
IsClosed: pullRequest.State == "closed",
IsClosed: pullRequest.State == f3.PullRequestStateClosed,
CreatedUnix: timeutil.TimeStamp(pullRequest.Created.Unix()),
UpdatedUnix: timeutil.TimeStamp(pullRequest.Updated.Unix()),
IsLocked: pullRequest.IsLocked,
@ -190,7 +190,7 @@ func (o *pullRequest) Get(ctx context.Context) bool {
o.Trace("%s", node.GetID())
project := f3_tree.GetProjectID(o.GetNode())
id := f3_util.ParseInt(string(node.GetID()))
id := node.GetID().Int64()
issue, err := issues_model.GetIssueByIndex(ctx, project, id)
if issues_model.IsErrIssueNotExist(err) {
@ -219,7 +219,7 @@ func (o *pullRequest) Get(ctx context.Context) bool {
func (o *pullRequest) Patch(ctx context.Context) {
node := o.GetNode()
project := f3_tree.GetProjectID(o.GetNode())
id := f3_util.ParseInt(string(node.GetID()))
id := node.GetID().Int64()
o.Trace("repo_id = %d, index = %d", project, id)
if _, err := db.GetEngine(ctx).Where("`repo_id` = ? AND `index` = ?", project, id).Cols("name", "content").Update(o.forgejoPullRequest); err != nil {
panic(fmt.Errorf("%v %v", o.forgejoPullRequest, err))
@ -289,7 +289,7 @@ func (o *pullRequest) Put(ctx context.Context) generic.NodeID {
}
o.Trace("pullRequest created %d/%d", o.forgejoPullRequest.ID, o.forgejoPullRequest.Index)
return generic.NodeID(fmt.Sprintf("%d", o.forgejoPullRequest.Index))
return generic.NewNodeID(o.forgejoPullRequest.Index)
}
func (o *pullRequest) Delete(ctx context.Context) {

View file

@ -67,7 +67,7 @@ func (o *reaction) Get(ctx context.Context) bool {
node := o.GetNode()
o.Trace("%s", node.GetID())
id := f3_util.ParseInt(string(node.GetID()))
id := node.GetID().Int64()
if has, err := db.GetEngine(ctx).Where("ID = ?", id).Get(o.forgejoReaction); err != nil {
panic(fmt.Errorf("reaction %v %w", id, err))
@ -115,7 +115,7 @@ func (o *reaction) Put(ctx context.Context) generic.NodeID {
panic(err)
}
o.Trace("reaction created %d", o.forgejoReaction.ID)
return generic.NodeID(fmt.Sprintf("%d", o.forgejoReaction.ID))
return generic.NewNodeID(o.forgejoReaction.ID)
}
func (o *reaction) Delete(ctx context.Context) {

View file

@ -85,7 +85,7 @@ func (o *release) Get(ctx context.Context) bool {
node := o.GetNode()
o.Trace("%s", node.GetID())
id := f3_util.ParseInt(string(node.GetID()))
id := node.GetID().Int64()
release, err := repo_model.GetReleaseByID(ctx, id)
if repo_model.IsErrReleaseNotExist(err) {
@ -133,7 +133,7 @@ func (o *release) Put(ctx context.Context) generic.NodeID {
panic(err)
}
o.Trace("release created %d", o.forgejoRelease.ID)
return generic.NodeID(fmt.Sprintf("%d", o.forgejoRelease.ID))
return generic.NewNodeID(o.forgejoRelease.ID)
}
func (o *release) Delete(ctx context.Context) {

View file

@ -68,7 +68,7 @@ func (o *repository) Patch(ctx context.Context) {
func (o *repository) upsert(ctx context.Context) generic.NodeID {
o.Trace("%s", o.GetNativeID())
o.h.Upsert(ctx, o.f)
return generic.NodeID(o.f.Name)
return generic.NewNodeID(o.f.Name)
}
func (o *repository) SetFetchFunc(fetchFunc func(ctx context.Context, destination string)) {

View file

@ -111,7 +111,7 @@ func (o *review) Get(ctx context.Context) bool {
node := o.GetNode()
o.Trace("%s", node.GetID())
id := f3_util.ParseInt(string(node.GetID()))
id := node.GetID().Int64()
review, err := issues_model.GetReviewByID(ctx, id)
if issues_model.IsErrReviewNotExist(err) {
@ -153,7 +153,7 @@ func (o *review) Put(ctx context.Context) generic.NodeID {
panic(err)
}
o.Trace("review created %d", o.forgejoReview.ID)
return generic.NodeID(fmt.Sprintf("%d", o.forgejoReview.ID))
return generic.NewNodeID(o.forgejoReview.ID)
}
func (o *review) Delete(ctx context.Context) {

View file

@ -92,7 +92,7 @@ func (o *reviewComment) Get(ctx context.Context) bool {
node := o.GetNode()
o.Trace("%s", node.GetID())
id := f3_util.ParseInt(string(node.GetID()))
id := node.GetID().Int64()
reviewComment, err := issues_model.GetCommentByID(ctx, id)
if issues_model.IsErrCommentNotExist(err) {
@ -125,7 +125,7 @@ func (o *reviewComment) Put(ctx context.Context) generic.NodeID {
panic(err)
}
o.Trace("reviewComment created %d", o.forgejoReviewComment.ID)
return generic.NodeID(fmt.Sprintf("%d", o.forgejoReviewComment.ID))
return generic.NewNodeID(o.forgejoReviewComment.ID)
}
func (o *reviewComment) Delete(ctx context.Context) {

View file

@ -61,7 +61,7 @@ func (o *topic) Get(ctx context.Context) bool {
node := o.GetNode()
o.Trace("%s", node.GetID())
id := f3_util.ParseInt(string(node.GetID()))
id := node.GetID().Int64()
if has, err := db.GetEngine(ctx).Where("ID = ?", id).Get(o.forgejoTopic); err != nil {
panic(fmt.Errorf("topic %v %w", id, err))
@ -86,7 +86,7 @@ func (o *topic) Put(ctx context.Context) generic.NodeID {
panic(err)
}
o.Trace("topic created %d", o.forgejoTopic.ID)
return generic.NodeID(fmt.Sprintf("%d", o.forgejoTopic.ID))
return generic.NewNodeID(o.forgejoTopic.ID)
}
func (o *topic) Delete(ctx context.Context) {

View file

@ -81,7 +81,7 @@ func (o *user) FromFormat(content f3.Interface) {
func (o *user) Get(ctx context.Context) bool {
node := o.GetNode()
o.Trace("%s", node.GetID())
id := f3_util.ParseInt(string(node.GetID()))
id := node.GetID().Int64()
u, err := user_model.GetPossibleUserByID(ctx, id)
if user_model.IsErrUserNotExist(err) {
return false
@ -98,7 +98,7 @@ func (o *user) Patch(context.Context) {
func (o *user) Put(ctx context.Context) generic.NodeID {
if user := getSystemUserByName(o.forgejoUser.Name); user != nil {
return generic.NodeID(fmt.Sprintf("%d", user.ID))
return generic.NewNodeID(user.ID)
}
o.forgejoUser.LowerName = strings.ToLower(o.forgejoUser.Name)
@ -111,7 +111,7 @@ func (o *user) Put(ctx context.Context) generic.NodeID {
panic(err)
}
return generic.NodeID(fmt.Sprintf("%d", o.forgejoUser.ID))
return generic.NewNodeID(o.forgejoUser.ID)
}
func (o *user) Delete(ctx context.Context) {

View file

@ -40,7 +40,7 @@ func (o *users) GetIDFromName(ctx context.Context, name string) generic.NodeID {
panic(fmt.Errorf("GetUserByName: %v", err))
}
return generic.NodeID(fmt.Sprintf("%d", user.ID))
return generic.NewNodeID(user.ID)
}
func newUsers() generic.NodeDriverInterface {