fix(project): push SSE update when an issue on a board is closed/reopened
Closing or reopening an issue did not notify project boards that carry it as a card, so board tabs showed stale state until a manual reload. CloseIssue/ReopenIssue only published milestone events and the issue timeline notification — nothing project-scoped. Add a CardStateChanged project event, published per linked project from CloseIssue/ReopenIssue (best-effort; never fails the state change). The board frontend flips the issue-state octicon in place and refetches the affected column so state-filtered boards and counts stay correct. The dispatch check precedes the CardUnlinked branch so a close/reopen is not mistaken for a card removal. Also switch a pre-existing String#match to RegExp#exec in the same file to keep it lint-clean. Closes #19
This commit is contained in:
@@ -12,8 +12,27 @@ import (
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
milestone_events "code.gitea.io/gitea/services/milestone_events"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
project_events "code.gitea.io/gitea/services/project_events"
|
||||
)
|
||||
|
||||
// publishProjectCardStateChanged notifies every project board the issue is a
|
||||
// card on that its open/closed state changed, so subscribed board tabs can
|
||||
// re-render the card live instead of showing stale state until reload.
|
||||
// Best-effort: a failure here must not fail the close/reopen operation.
|
||||
func publishProjectCardStateChanged(ctx context.Context, issue *issues_model.Issue, isClosed bool) {
|
||||
if err := issue.LoadProjects(ctx); err != nil {
|
||||
log.Error("LoadProjects for issue[%d]: %v", issue.ID, err)
|
||||
return
|
||||
}
|
||||
for _, p := range issue.Projects {
|
||||
project_events.PublishCardStateChanged(ctx, project_events.CardStateChanged{
|
||||
ProjectID: p.ID,
|
||||
IssueID: issue.ID,
|
||||
IsClosed: isClosed,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// CloseIssue close an issue.
|
||||
func CloseIssue(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, commitID string) error {
|
||||
var comment *issues_model.Comment
|
||||
@@ -40,6 +59,7 @@ func CloseIssue(ctx context.Context, issue *issues_model.Issue, doer *user_model
|
||||
}
|
||||
|
||||
notify_service.IssueChangeStatus(ctx, doer, commitID, issue, comment, true)
|
||||
publishProjectCardStateChanged(ctx, issue, true)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -57,6 +77,7 @@ func ReopenIssue(ctx context.Context, issue *issues_model.Issue, doer *user_mode
|
||||
}
|
||||
|
||||
notify_service.IssueChangeStatus(ctx, doer, commitID, issue, comment, false)
|
||||
publishProjectCardStateChanged(ctx, issue, false)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -69,6 +69,17 @@ type CardUnlinked struct {
|
||||
SessionTag string `json:"session_tag,omitempty"`
|
||||
}
|
||||
|
||||
// CardStateChanged is emitted when an issue's open/closed state changes
|
||||
// while it is a card on the project. It lets boards re-render the card's
|
||||
// state live (and is the hook state-filtered boards use to correct their
|
||||
// column counts) without a full page reload.
|
||||
type CardStateChanged struct {
|
||||
ProjectID int64 `json:"project_id"`
|
||||
IssueID int64 `json:"issue_id"`
|
||||
IsClosed bool `json:"is_closed"`
|
||||
SessionTag string `json:"session_tag,omitempty"`
|
||||
}
|
||||
|
||||
// ColumnCreated is emitted when a new column is added to a project.
|
||||
type ColumnCreated struct {
|
||||
ProjectID int64 `json:"project_id"`
|
||||
@@ -277,6 +288,14 @@ func PublishCardUnlinked(ctx context.Context, payload CardUnlinked) {
|
||||
go publishEvent(detach(ctx), payload.ProjectID, payload)
|
||||
}
|
||||
|
||||
// PublishCardStateChanged fans out a CardStateChanged event for the given payload.
|
||||
func PublishCardStateChanged(ctx context.Context, payload CardStateChanged) {
|
||||
if payload.SessionTag == "" {
|
||||
payload.SessionTag = SessionTagFromContext(ctx)
|
||||
}
|
||||
go publishEvent(detach(ctx), payload.ProjectID, payload)
|
||||
}
|
||||
|
||||
// PublishColumnCreated fans out a ColumnCreated event for the given payload.
|
||||
func PublishColumnCreated(ctx context.Context, payload ColumnCreated) {
|
||||
go publishEvent(detach(ctx), payload.ProjectID, payload)
|
||||
|
||||
@@ -112,6 +112,14 @@ func TestPublishHelpers_NameAndPayload(t *testing.T) {
|
||||
},
|
||||
wantData: CardUnlinked{ProjectID: 12, IssueID: 8},
|
||||
},
|
||||
{
|
||||
name: "card.state_changed",
|
||||
wantName: "project-board.12",
|
||||
invoke: func(ctx context.Context) {
|
||||
PublishCardStateChanged(ctx, CardStateChanged{ProjectID: 12, IssueID: 8, IsClosed: true})
|
||||
},
|
||||
wantData: CardStateChanged{ProjectID: 12, IssueID: 8, IsClosed: true},
|
||||
},
|
||||
{
|
||||
name: "column.created",
|
||||
wantName: "project-board.13",
|
||||
|
||||
Reference in New Issue
Block a user