summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorlimiting-factor <limiting-factor@posteo.com>2024-08-19 17:42:54 +0200
committerEarl Warren <contact@earl-warren.org>2025-01-07 17:13:21 +0100
commitd8f71b513c8b4fbc8136f08b5498e2fb7a011680 (patch)
treebd66c4c7d969ec0f3d429a672356f8c639e4b688 /services
parentfix: f3: support modify milestone (diff)
downloadforgejo-d8f71b513c8b4fbc8136f08b5498e2fb7a011680.tar.xz
forgejo-d8f71b513c8b4fbc8136f08b5498e2fb7a011680.zip
fix: f3: update issue assignees
The ID must be obtained from the repository ID and the index, otherwise it is zero and the assignees are not updated.
Diffstat (limited to 'services')
-rw-r--r--services/f3/driver/issue.go65
1 files changed, 42 insertions, 23 deletions
diff --git a/services/f3/driver/issue.go b/services/f3/driver/issue.go
index aea00bcf05..0d32b90ad1 100644
--- a/services/f3/driver/issue.go
+++ b/services/f3/driver/issue.go
@@ -137,7 +137,7 @@ func (o *issue) Get(ctx context.Context) bool {
panic(fmt.Errorf("issue %v %w", id, err))
}
if err := issue.LoadAttributes(ctx); err != nil {
- panic(err)
+ panic(fmt.Errorf("LoadAttributes %v %w", id, err))
}
o.forgejoIssue = issue
@@ -147,11 +147,47 @@ 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 := 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", "is_closed").Update(o.forgejoIssue); err != nil {
+ index := node.GetID().Int64()
+ id := getIssueID(ctx, project, index)
+ o.Trace("id = %d, repo_id = %d, index = %d, assignees = %v", id, project, index, o.forgejoIssue.Assignees)
+ if _, err := db.GetEngine(ctx).Where("`id` = ?", id).Cols("name", "content", "is_closed", "milestone_id").Update(o.forgejoIssue); err != nil {
panic(fmt.Errorf("%v %v", o.forgejoIssue, err))
}
+
+ updateIssueAssignees(ctx, id, o.forgejoIssue.Assignees)
+}
+
+func getIssueID(ctx context.Context, repoID, index int64) int64 {
+ var id int64
+ if _, err := db.GetEngine(ctx).Select("id").Table("issue").Where("`repo_id` = ? AND `index` = ?", repoID, index).Get(&id); err != nil {
+ panic(fmt.Errorf("%v %v: %w", repoID, index, err))
+ }
+ return id
+}
+
+func updateIssueAssignees(ctx context.Context, issueID int64, assignees []*user_model.User) {
+ sess := db.GetEngine(ctx)
+ makeIssueAssignees := func(issueID int64) []issues_model.IssueAssignees {
+ issueAssignees := make([]issues_model.IssueAssignees, 0, len(assignees))
+ for _, assignee := range assignees {
+ issueAssignees = append(issueAssignees, issues_model.IssueAssignees{
+ IssueID: issueID,
+ AssigneeID: assignee.ID,
+ })
+ }
+ return issueAssignees
+ }
+
+ if _, err := sess.Where("issue_id = ?", issueID).Delete(new(issues_model.IssueAssignees)); err != nil {
+ panic(fmt.Errorf("delete IssueAssignees %v %w", issueID, err))
+ }
+
+ issueAssignees := makeIssueAssignees(issueID)
+ if len(issueAssignees) > 0 {
+ if _, err := sess.Insert(issueAssignees); err != nil {
+ panic(fmt.Errorf("Insert %v %w", issueID, err))
+ }
+ }
}
func (o *issue) Put(ctx context.Context) generic.NodeID {
@@ -183,6 +219,8 @@ func (o *issue) Put(ctx context.Context) generic.NodeID {
panic(err)
}
+ updateIssueAssignees(ctx, o.forgejoIssue.ID, o.forgejoIssue.Assignees)
+
labels := makeLabels(o.forgejoIssue.ID)
if len(labels) > 0 {
if _, err := sess.Insert(labels); err != nil {
@@ -190,25 +228,6 @@ func (o *issue) Put(ctx context.Context) generic.NodeID {
}
}
- makeAssignees := func(issueID int64) []issues_model.IssueAssignees {
- assignees := make([]issues_model.IssueAssignees, 0, len(o.forgejoIssue.Assignees))
- for _, assignee := range o.forgejoIssue.Assignees {
- o.Trace("%d with assignee %d", issueID, assignee.ID)
- assignees = append(assignees, issues_model.IssueAssignees{
- IssueID: issueID,
- AssigneeID: assignee.ID,
- })
- }
- return assignees
- }
-
- assignees := makeAssignees(o.forgejoIssue.ID)
- if len(assignees) > 0 {
- if _, err := sess.Insert(assignees); err != nil {
- panic(err)
- }
- }
-
o.Trace("issue created %d/%d", o.forgejoIssue.ID, o.forgejoIssue.Index)
return generic.NewNodeID(o.forgejoIssue.Index)
}