appview: add issue_reopen event #707

merged
opened by boltless.me targeting master from boltless.me/core: feat/search

both issue close and reopen are handled by NewIssueState handler. this works because passed issue obj is already holding the newest issue state.

Signed-off-by: Seongmin Lee git@boltless.me

Changed files
+31 -12
appview
indexer
issues
models
notify
pages
templates
notifications
fragments
+1 -1
appview/indexer/notifier.go
···
}
}
-
func (ix *Indexer) NewIssueClosed(ctx context.Context, issue *models.Issue) {
+
func (ix *Indexer) NewIssueState(ctx context.Context, issue *models.Issue) {
l := log.FromContext(ctx).With("notifier", "indexer", "issue", issue)
l.Debug("updating an issue")
err := ix.Issues.Index(ctx, *issue)
+3 -3
appview/issues/issues.go
···
issue.Open = false
// notify about the issue closure
-
rp.notifier.NewIssueClosed(r.Context(), issue)
+
rp.notifier.NewIssueState(r.Context(), issue)
rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", f.OwnerSlashRepo(), issue.IssueId))
return
···
// change the issue state (this will pass down to the notifiers)
issue.Open = true
-
// // notify about the issue reopen
-
// rp.notifier.NewIssueReopen(r.Context(), issue)
+
// notify about the issue reopen
+
rp.notifier.NewIssueState(r.Context(), issue)
rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", f.OwnerSlashRepo(), issue.IssueId))
return
+5
appview/models/notifications.go
···
NotificationTypeFollowed NotificationType = "followed"
NotificationTypePullMerged NotificationType = "pull_merged"
NotificationTypeIssueClosed NotificationType = "issue_closed"
+
NotificationTypeIssueReopen NotificationType = "issue_reopen"
NotificationTypePullClosed NotificationType = "pull_closed"
)
···
return "message-square"
case NotificationTypeIssueClosed:
return "ban"
+
case NotificationTypeIssueReopen:
+
return "circle-dot"
case NotificationTypePullCreated:
return "git-pull-request-create"
case NotificationTypePullCommented:
···
return prefs.IssueCommented
case NotificationTypeIssueClosed:
return prefs.IssueClosed
+
case NotificationTypeIssueReopen:
+
return prefs.IssueCreated // smae pref for now
case NotificationTypePullCreated:
return prefs.PullCreated
case NotificationTypePullCommented:
+8 -2
appview/notify/db/db.go
···
// no-op
}
-
func (n *databaseNotifier) NewIssueClosed(ctx context.Context, issue *models.Issue) {
+
func (n *databaseNotifier) NewIssueState(ctx context.Context, issue *models.Issue) {
// build up the recipients list:
// - repo owner
// - repo collaborators
···
}
actorDid := syntax.DID(issue.Repo.Did)
-
eventType := models.NotificationTypeIssueClosed
entityType := "pull"
entityId := issue.AtUri().String()
repoId := &issue.Repo.Id
issueId := &issue.Id
var pullId *int64
+
var eventType models.NotificationType
+
+
if issue.Open {
+
eventType = models.NotificationTypeIssueReopen
+
} else {
+
eventType = models.NotificationTypeIssueClosed
+
}
n.notifyEvent(
actorDid,
+2 -2
appview/notify/merged_notifier.go
···
m.fanout("NewIssueComment", ctx, comment)
}
-
func (m *mergedNotifier) NewIssueClosed(ctx context.Context, issue *models.Issue) {
-
m.fanout("NewIssueClosed", ctx, issue)
+
func (m *mergedNotifier) NewIssueState(ctx context.Context, issue *models.Issue) {
+
m.fanout("NewIssueState", ctx, issue)
}
func (m *mergedNotifier) DeleteIssue(ctx context.Context, issue *models.Issue) {
+2 -2
appview/notify/notifier.go
···
NewIssue(ctx context.Context, issue *models.Issue)
NewIssueComment(ctx context.Context, comment *models.IssueComment)
-
NewIssueClosed(ctx context.Context, issue *models.Issue)
+
NewIssueState(ctx context.Context, issue *models.Issue)
DeleteIssue(ctx context.Context, issue *models.Issue)
NewFollow(ctx context.Context, follow *models.Follow)
···
func (m *BaseNotifier) NewIssue(ctx context.Context, issue *models.Issue) {}
func (m *BaseNotifier) NewIssueComment(ctx context.Context, comment *models.IssueComment) {}
-
func (m *BaseNotifier) NewIssueClosed(ctx context.Context, issue *models.Issue) {}
+
func (m *BaseNotifier) NewIssueState(ctx context.Context, issue *models.Issue) {}
func (m *BaseNotifier) DeleteIssue(ctx context.Context, issue *models.Issue) {}
func (m *BaseNotifier) NewFollow(ctx context.Context, follow *models.Follow) {}
+8 -2
appview/notify/posthog/notifier.go
···
}
}
-
func (n *posthogNotifier) NewIssueClosed(ctx context.Context, issue *models.Issue) {
+
func (n *posthogNotifier) NewIssueState(ctx context.Context, issue *models.Issue) {
+
var event string
+
if issue.Open {
+
event = "issue_reopen"
+
} else {
+
event = "issue_closed"
+
}
err := n.client.Enqueue(posthog.Capture{
DistinctId: issue.Did,
-
Event: "issue_closed",
+
Event: event,
Properties: posthog.Properties{
"repo_at": issue.RepoAt.String(),
"issue_id": issue.IssueId,
+2
appview/pages/templates/notifications/fragments/item.html
···
commented on an issue
{{ else if eq .Type "issue_closed" }}
closed an issue
+
{{ else if eq .Type "issue_reopen" }}
+
reopened an issue
{{ else if eq .Type "pull_created" }}
created a pull request
{{ else if eq .Type "pull_commented" }}