Skip to content

Commit

Permalink
96 early detection for git pr conflicts via slack (#99)
Browse files Browse the repository at this point in the history
Co-authored-by: muhammad-asghar-ali <[email protected]>
Co-authored-by: Yousuf Jawwad <[email protected]>
  • Loading branch information
3 people authored Mar 21, 2024
1 parent ddd055f commit ba3669d
Show file tree
Hide file tree
Showing 18 changed files with 824 additions and 8 deletions.
7 changes: 7 additions & 0 deletions .env.debug
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ SECRET=YWQwNTU5ZTk4Yzc1OTg3MjVjZjc4NDA3ZGRkY2E2NTc0YWNlNDkxY2IyNmVhMzc5
# CASSANDRA_HOSTS=database
TEMPORAL_HOST=localhost
CASSANDRA_HOSTS=localhost

SLACK_BOT_TOKEN=xoxb-5594604795991-6721158311090-3aogehiOS78zbG5pVg0dDYkO
SLACK_APP_TOKEN=xapp-1-A06M46RRELD-6733809040737-48fa7183f6979b8701cf6edf70c0e9283e8a8f6b899067fb5c9ce64c03c9604d
SLACK_USER_TOKEN=xoxp-5594604795991-5609144010130-6718241703781-593f496e508199f6b3b9cbc4157154d2
SLACK_CLIENT_ID=5594604795991.6718229864693
SLACK_CLIENT_SECRET=10f065a36367d8f3b10fc7ca3322b242
SLACK_REDIRECT_URL=https://slack.com/oauth/v2/authorize
2 changes: 1 addition & 1 deletion api
Submodule api updated from bc0724 to 886463
13 changes: 13 additions & 0 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"go.breu.io/quantm/internal/core"
"go.breu.io/quantm/internal/db"
"go.breu.io/quantm/internal/providers/github"
"go.breu.io/quantm/internal/providers/slack"
"go.breu.io/quantm/internal/shared"
"go.breu.io/quantm/internal/shared/logger"
)
Expand Down Expand Up @@ -99,6 +100,18 @@ func main() {

go _run(_serve(web, HTTPPort), errs)
go _run(_serve(metrics, PrometheusPort), errs)

// Call slack events and handle potential error.
go func() {
message := "API started."
if err := slack.NotifyOnSlack(message); err != nil {
slog.Error("event error:", slog.Any("error", err.Error()))
errs <- err

return
}
}()

slog.Info("registering quit signals")
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM) // setting up the signals to listen to.

Expand Down
2 changes: 2 additions & 0 deletions cmd/workers/mothership/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func main() {
providerWrkr.RegisterWorkflow(ghwfs.OnLabelEvent)
providerWrkr.RegisterWorkflow(ghwfs.PollMergeQueue)
providerWrkr.RegisterWorkflow(ghwfs.OnGithubActionResult)
providerWrkr.RegisterWorkflow(ghwfs.EarlyDetection)
providerWrkr.RegisterWorkflow(ghwfs.StaleBranchDetection)

// provider activities
providerWrkr.RegisterActivity(&github.Activities{})
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ require (
olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3 // indirect
)

require (
github.com/gorilla/websocket v1.4.2 // indirect
github.com/slack-go/slack v0.12.5 // indirect
)

replace github.com/Guilospanck/igocqlx v1.0.0 => github.com/debuggerpk/igocqlx v1.0.3

replace github.com/deepmap/oapi-codegen/v2 v2.0.0 => github.com/breuHQ/oapi-codegen/v2 v2.0.0-breu
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91
github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4=
github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
Expand Down Expand Up @@ -1131,6 +1132,10 @@ github.com/googleapis/gax-go/v2 v2.12.2/go.mod h1:61M8vcyyXR2kqKFxKrfA22jaA8JGF7
github.com/googleapis/go-type-adapters v1.0.0/go.mod h1:zHW75FOG2aur7gAO2B+MLby+cLsWGBF62rFAi7WjWO4=
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gosimple/slug v1.13.1 h1:bQ+kpX9Qa6tHRaK+fZR0A0M2Kd7Pa5eHPPsb1JpHD+Q=
github.com/gosimple/slug v1.13.1/go.mod h1:UiRaFH+GEilHstLUmcBgWcI42viBN7mAb818JrYOeFQ=
github.com/gosimple/slug v1.14.0 h1:RtTL/71mJNDfpUbCOmnf/XFkzKRtD6wL6Uy+3akm4Es=
github.com/gosimple/slug v1.14.0/go.mod h1:UiRaFH+GEilHstLUmcBgWcI42viBN7mAb818JrYOeFQ=
github.com/gosimple/unidecode v1.0.1 h1:hZzFTMMqSswvf0LBJZCZgThIZrpDHFXux9KeGmn6T/o=
Expand Down Expand Up @@ -1346,6 +1351,8 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2AQ=
github.com/skeema/knownhosts v1.2.1/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo=
github.com/slack-go/slack v0.12.5 h1:ddZ6uz6XVaB+3MTDhoW04gG+Vc/M/X1ctC+wssy2cqs=
github.com/slack-go/slack v0.12.5/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw=
github.com/smallstep/assert v0.0.0-20200723003110-82e2b9b3b262 h1:unQFBIznI+VYD1/1fApl1A+9VcBk+9dcqGfnePY87LY=
github.com/smallstep/assert v0.0.0-20200723003110-82e2b9b3b262/go.mod h1:MyOHs9Po2fbM1LHej6sBUT8ozbxmMOFG+E+rx/GSGuc=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
Expand Down
29 changes: 25 additions & 4 deletions internal/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ type (
RepoProvider(RepoProvider) RepoProviderActivities
CloudProvider(CloudProvider) CloudProviderActivities
ResourceConstructor(CloudProvider, Driver) ResourceConstructor

ResgiterMessageProvider(MessageProvider, MessageProviderActivities)
MessageProvider(MessageProvider) MessageProviderActivities
}

Option func(Core)
Expand All @@ -60,9 +63,14 @@ type (
FillMe()
}

MessageProviderActivities interface {
SendChannelMessage(ctx context.Context, msg string) error // TODO: figure out the signature
}

Providers struct {
repos map[RepoProvider]RepoProviderActivities
cloud map[CloudProvider]CloudProviderActivities
repos map[RepoProvider]RepoProviderActivities
cloud map[CloudProvider]CloudProviderActivities
message map[MessageProvider]MessageProviderActivities
}

CloudResource interface {
Expand Down Expand Up @@ -148,6 +156,18 @@ func (c *core) CloudProvider(name CloudProvider) CloudProviderActivities {
panic(NewProviderNotFoundError(name.String()))
}

func (c *core) ResgiterMessageProvider(provider MessageProvider, activities MessageProviderActivities) {
c.providers.message[provider] = activities
}

func (c *core) MessageProvider(name MessageProvider) MessageProviderActivities {
if p, ok := c.providers.message[name]; ok {
return p
}

panic(NewProviderNotFoundError(name.String()))
}

// WithRepoProvider registers a repo provider with the core.
func WithRepoProvider(name RepoProvider, provider RepoProviderActivities) Option {
return func(c Core) {
Expand Down Expand Up @@ -180,8 +200,9 @@ func Instance(opts ...Option) Core {
once.Do(func() {
instance = &core{
providers: Providers{
repos: make(map[RepoProvider]RepoProviderActivities),
cloud: make(map[CloudProvider]CloudProviderActivities),
repos: make(map[RepoProvider]RepoProviderActivities),
cloud: make(map[CloudProvider]CloudProviderActivities),
message: make(map[MessageProvider]MessageProviderActivities),
},

resources: make(map[CloudProvider]map[Driver]ResourceConstructor),
Expand Down
4 changes: 4 additions & 0 deletions internal/core/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,7 @@ func (s *ServerHandler) GetRepo(ctx echo.Context) error {

return ctx.JSON(http.StatusOK, repo)
}

func (s *ServerHandler) SlackNotify(ctx echo.Context) error {
return ctx.JSON(http.StatusNotImplemented, nil)
}
Loading

0 comments on commit ba3669d

Please sign in to comment.