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 5 "encoding/json" 6 6 "errors" 7 7 "fmt" 8 + "slices" 8 9 "time" 9 10 10 11 "tangled.org/core/appview/notify" ··· 85 86 return err 86 87 } 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 + 88 97 logger.Info("processing gitRefUpdate event", 89 98 "repo_did", record.RepoDid, 90 99 "repo_name", record.RepoName, ··· 93 102 "new_sha", record.NewSha) 94 103 95 104 // trigger webhook notifications first (before other ops that might fail) 105 + var errWebhook error 96 106 repos, err := db.GetRepos( 97 107 d, 98 108 0, 99 109 orm.FilterEq("did", record.RepoDid), 100 110 orm.FilterEq("name", record.RepoName), 101 111 ) 102 - if err == nil && len(repos) == 1 { 112 + if err != nil { 113 + errWebhook = fmt.Errorf("failed to lookup repo for webhooks: %w", err) 114 + } else if len(repos) == 1 { 103 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) 104 118 } 105 119 106 - err1 := populatePunchcard(d, record) 107 - err2 := updateRepoLanguages(d, record) 120 + errPunchcard := populatePunchcard(d, record) 121 + errLanguages := updateRepoLanguages(d, record) 108 122 109 - var err3 error 123 + var errPosthog error 110 124 if !dev && record.CommitterDid != "" { 111 - err3 = pc.Enqueue(posthog.Capture{ 125 + errPosthog = pc.Enqueue(posthog.Capture{ 112 126 DistinctId: record.CommitterDid, 113 127 Event: "git_ref_update", 114 128 }) 115 129 } 116 130 117 - return errors.Join(err1, err2, err3) 131 + return errors.Join(errWebhook, errPunchcard, errLanguages, errPosthog) 118 132 } 119 133 120 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