appview: add pull_reopen event #710

merged
opened by boltless.me targeting master from boltless.me/core: feat/search
Changed files
+63
appview
models
notify
pages
templates
notifications
fragments
pulls
+5
appview/models/notifications.go
···
NotificationTypeIssueClosed NotificationType = "issue_closed"
NotificationTypeIssueReopen NotificationType = "issue_reopen"
NotificationTypePullClosed NotificationType = "pull_closed"
)
type Notification struct {
···
return "git-merge"
case NotificationTypePullClosed:
return "git-pull-request-closed"
case NotificationTypeFollowed:
return "user-plus"
default:
···
return prefs.PullMerged
case NotificationTypePullClosed:
return prefs.PullMerged // same pref for now
case NotificationTypeFollowed:
return prefs.Followed
default:
···
NotificationTypeIssueClosed NotificationType = "issue_closed"
NotificationTypeIssueReopen NotificationType = "issue_reopen"
NotificationTypePullClosed NotificationType = "pull_closed"
+
NotificationTypePullReopen NotificationType = "pull_reopen"
)
type Notification struct {
···
return "git-merge"
case NotificationTypePullClosed:
return "git-pull-request-closed"
+
case NotificationTypePullReopen:
+
return "git-pull-request-create"
case NotificationTypeFollowed:
return "user-plus"
default:
···
return prefs.PullMerged
case NotificationTypePullClosed:
return prefs.PullMerged // same pref for now
+
case NotificationTypePullReopen:
+
return prefs.PullCreated // same pref for now
case NotificationTypeFollowed:
return prefs.Followed
default:
+46
appview/notify/db/db.go
···
)
}
func (n *databaseNotifier) notifyEvent(
actorDid syntax.DID,
recipients []syntax.DID,
···
)
}
+
func (n *databaseNotifier) NewPullReopen(ctx context.Context, pull *models.Pull) {
+
// Get repo details
+
repo, err := db.GetRepo(n.db, db.FilterEq("at_uri", string(pull.RepoAt)))
+
if err != nil {
+
log.Printf("NewPullMerged: failed to get repos: %v", err)
+
return
+
}
+
+
// build up the recipients list:
+
// - repo owner
+
// - all pull participants
+
var recipients []syntax.DID
+
recipients = append(recipients, syntax.DID(repo.Did))
+
collaborators, err := db.GetCollaborators(n.db, db.FilterEq("repo_at", repo.RepoAt()))
+
if err != nil {
+
log.Printf("failed to fetch collaborators: %v", err)
+
return
+
}
+
for _, c := range collaborators {
+
recipients = append(recipients, c.SubjectDid)
+
}
+
for _, p := range pull.Participants() {
+
recipients = append(recipients, syntax.DID(p))
+
}
+
+
actorDid := syntax.DID(repo.Did)
+
eventType := models.NotificationTypePullReopen
+
entityType := "pull"
+
entityId := pull.PullAt().String()
+
repoId := &repo.Id
+
var issueId *int64
+
p := int64(pull.ID)
+
pullId := &p
+
+
n.notifyEvent(
+
actorDid,
+
recipients,
+
eventType,
+
entityType,
+
entityId,
+
repoId,
+
issueId,
+
pullId,
+
)
+
}
+
func (n *databaseNotifier) notifyEvent(
actorDid syntax.DID,
recipients []syntax.DID,
+4
appview/notify/merged_notifier.go
···
m.fanout("NewPullClosed", ctx, pull)
}
func (m *mergedNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) {
m.fanout("UpdateProfile", ctx, profile)
}
···
m.fanout("NewPullClosed", ctx, pull)
}
+
func (m *mergedNotifier) NewPullReopen(ctx context.Context, pull *models.Pull) {
+
m.fanout("NewPullReopen", ctx, pull)
+
}
+
func (m *mergedNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) {
m.fanout("UpdateProfile", ctx, profile)
}
+2
appview/notify/notifier.go
···
NewPullComment(ctx context.Context, comment *models.PullComment)
NewPullMerged(ctx context.Context, pull *models.Pull)
NewPullClosed(ctx context.Context, pull *models.Pull)
UpdateProfile(ctx context.Context, profile *models.Profile)
···
func (m *BaseNotifier) NewPullComment(ctx context.Context, models *models.PullComment) {}
func (m *BaseNotifier) NewPullMerged(ctx context.Context, pull *models.Pull) {}
func (m *BaseNotifier) NewPullClosed(ctx context.Context, pull *models.Pull) {}
func (m *BaseNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) {}
···
NewPullComment(ctx context.Context, comment *models.PullComment)
NewPullMerged(ctx context.Context, pull *models.Pull)
NewPullClosed(ctx context.Context, pull *models.Pull)
+
NewPullReopen(ctx context.Context, pull *models.Pull)
UpdateProfile(ctx context.Context, profile *models.Profile)
···
func (m *BaseNotifier) NewPullComment(ctx context.Context, models *models.PullComment) {}
func (m *BaseNotifier) NewPullMerged(ctx context.Context, pull *models.Pull) {}
func (m *BaseNotifier) NewPullClosed(ctx context.Context, pull *models.Pull) {}
+
func (m *BaseNotifier) NewPullReopen(ctx context.Context, pull *models.Pull) {}
func (m *BaseNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) {}
+2
appview/pages/templates/notifications/fragments/item.html
···
merged a pull request
{{ else if eq .Type "pull_closed" }}
closed a pull request
{{ else if eq .Type "followed" }}
followed you
{{ else }}
···
merged a pull request
{{ else if eq .Type "pull_closed" }}
closed a pull request
+
{{ else if eq .Type "pull_reopen" }}
+
reopened a pull request
{{ else if eq .Type "followed" }}
followed you
{{ else }}
+4
appview/pulls/pulls.go
···
return
}
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId))
}
···
return
}
+
for _, p := range pullsToReopen {
+
s.notifier.NewPullReopen(r.Context(), p)
+
}
+
s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId))
}