Monorepo for Tangled tangled.org

appview/state: integrate webhooks with gitRefUpdate events #1068

merged opened by anirudh.fi targeting master from icy/qlyxxp

Trigger webhooks on git push events from knotstream.

Signed-off-by: Anirudh Oppiliappan anirudh@tangled.org

Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:hwevmowznbiukdf6uk5dwrrq/sh.tangled.repo.pull/3menyebs7t622
+20 -6
Interdiff #1 #2
+20 -6
appview/state/knotstream.go
··· 5 "encoding/json" 6 "errors" 7 "fmt" 8 "time" 9 10 "tangled.org/core/appview/notify" ··· 85 return err 86 } 87 88 logger.Info("processing gitRefUpdate event", 89 "repo_did", record.RepoDid, 90 "repo_name", record.RepoName, ··· 93 "new_sha", record.NewSha) 94 95 // trigger webhook notifications first (before other ops that might fail) 96 repos, err := db.GetRepos( 97 d, 98 0, 99 orm.FilterEq("did", record.RepoDid), 100 orm.FilterEq("name", record.RepoName), 101 ) 102 - if err == nil && len(repos) == 1 { 103 notifier.Push(ctx, &repos[0], record.Ref, record.OldSha, record.NewSha, record.CommitterDid) 104 } 105 106 - err1 := populatePunchcard(d, record) 107 - err2 := updateRepoLanguages(d, record) 108 109 - var err3 error 110 if !dev && record.CommitterDid != "" { 111 - err3 = pc.Enqueue(posthog.Capture{ 112 DistinctId: record.CommitterDid, 113 Event: "git_ref_update", 114 }) 115 } 116 117 - return errors.Join(err1, err2, err3) 118 } 119 120 func populatePunchcard(d *db.DB, record tangled.GitRefUpdate) error {
··· 5 "encoding/json" 6 "errors" 7 "fmt" 8 + "slices" 9 "time" 10 11 "tangled.org/core/appview/notify" ··· 86 return err 87 } 88 89 + knownKnots, err := enforcer.GetKnotsForUser(record.CommitterDid) 90 + if err != nil { 91 + return err 92 + } 93 + if !slices.Contains(knownKnots, source.Key()) { 94 + return fmt.Errorf("%s does not belong to %s, something is fishy", record.CommitterDid, source.Key()) 95 + } 96 + 97 logger.Info("processing gitRefUpdate event", 98 "repo_did", record.RepoDid, 99 "repo_name", record.RepoName, ··· 102 "new_sha", record.NewSha) 103 104 // trigger webhook notifications first (before other ops that might fail) 105 + var errWebhook error 106 repos, err := db.GetRepos( 107 d, 108 0, 109 orm.FilterEq("did", record.RepoDid), 110 orm.FilterEq("name", record.RepoName), 111 ) 112 + if err != nil { 113 + errWebhook = fmt.Errorf("failed to lookup repo for webhooks: %w", err) 114 + } else if len(repos) == 1 { 115 notifier.Push(ctx, &repos[0], record.Ref, record.OldSha, record.NewSha, record.CommitterDid) 116 + } else if len(repos) == 0 { 117 + errWebhook = fmt.Errorf("no repo found for webhooks: %s/%s", record.RepoDid, record.RepoName) 118 } 119 120 + errPunchcard := populatePunchcard(d, record) 121 + errLanguages := updateRepoLanguages(d, record) 122 123 + var errPosthog error 124 if !dev && record.CommitterDid != "" { 125 + errPosthog = pc.Enqueue(posthog.Capture{ 126 DistinctId: record.CommitterDid, 127 Event: "git_ref_update", 128 }) 129 } 130 131 + return errors.Join(errWebhook, errPunchcard, errLanguages, errPosthog) 132 } 133 134 func populatePunchcard(d *db.DB, record tangled.GitRefUpdate) error {
appview/state/state.go

This file has not been changed.

History

6 rounds 1 comment
sign up or login to add to the discussion
1 commit
expand
appview/state: integrate webhooks with gitRefUpdate events
3/3 success
expand
expand 0 comments
pull request successfully merged
1 commit
expand
appview/state: integrate webhooks with gitRefUpdate events
3/3 success
expand
expand 0 comments
1 commit
expand
appview/state: integrate webhooks with gitRefUpdate events
3/3 success
expand
expand 0 comments
1 commit
expand
appview/state: integrate webhooks with gitRefUpdate events
3/3 success
expand
expand 0 comments
1 commit
expand
appview/state: integrate webhooks with gitRefUpdate events
3/3 success
expand
expand 1 comment
  • here why was the knownKnots check removed?
  • the other ops can fail, but they are non-returning fails, the errors are Joined, we can do the same here (collect the error and join in the final statement

changeset lgtm otherwise!

1 commit
expand
appview/state: integrate webhooks with gitRefUpdate events
3/3 success
expand
expand 0 comments