Skip to content

Commit

Permalink
Revert emitting disabled status for all public repositories
Browse files Browse the repository at this point in the history
This is taking >5s regularly and so causing a lot of 503s.

- This reverts commit f728999.
- This reverts commit 4641f67.
  • Loading branch information
pbrisbin committed Oct 8, 2024
1 parent 1647bf4 commit 0eaddf8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
30 changes: 9 additions & 21 deletions src/Restyled/Disabled.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ newtype Installation = Installation
deriving anyclass (FromJSON, ToJSON)

data PullRequest = PullRequest
{ number :: Int
, base :: Commit
{ base :: Commit
, head :: Commit
}
deriving stock (Generic)
Expand All @@ -44,16 +43,12 @@ data Commit = Commit
deriving anyclass (FromJSON, ToJSON)

data Repo = Repo
{ private :: Bool
, owner :: Owner
{ owner :: Owner
, name :: Text
}
deriving stock (Generic)
deriving anyclass (FromJSON, ToJSON)

repoFullName :: Repo -> Text
repoFullName repo = repo.owner.login <> "/" <> repo.name

newtype Owner = Owner
{ login :: Text
}
Expand All @@ -65,33 +60,26 @@ newtype Owner = Owner
-- Rough plan:
--
-- - [x] Our own testing repositories
-- - [x] All public repositories
-- - [ ] All public repositories
-- - [ ] All except those orgs who are still paying
-- - [ ] Every
shouldEmitDisabledStatus :: Webhook -> Bool
shouldEmitDisabledStatus webhook
| webhook.pull_request.base.repo.owner.login == "restyled-io" = True
| not webhook.pull_request.base.repo.private = True
| otherwise = False
shouldEmitDisabledStatus webhook =
and
[ webhook.pull_request.base.repo.owner.login == "restyled-io"
, webhook.pull_request.base.repo.name == "demo"
]

emitDisabledStatus
:: (MonadIO m, MonadLogger m, MonadReader env m, HasSettings env)
=> BSL.ByteString
-> m (Either String GitHub.Status)
emitDisabledStatus body = runExceptT $ do
webhook <- hoistEither $ eitherDecode body
logDebug $ "Webhook" :# ["contents" .= webhook]
guard $ shouldEmitDisabledStatus webhook

settings <- lift $ view settingsL
token <- generateToken settings webhook

logInfo
$ "Emitted disabled status"
:# [ "repository" .= repoFullName webhook.pull_request.base.repo
, "pullRequest" .= webhook.pull_request.number
, "commitSha" .= webhook.pull_request.head.sha
]

createStatus token webhook

generateToken
Expand Down
11 changes: 6 additions & 5 deletions src/Restyled/Handlers/Webhooks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import Restyled.Yesod

postWebhooksR :: Handler ()
postWebhooksR = do
qs <- view queuesL
body <- runConduit $ rawRequestBody .| sinkLbs

emitDisabledStatus body >>= \case
Left {} -> do
-- Not emitted, proceed normally
qs <- view queuesL
runRedis $ enqueue qs $ toStrict body
Right {} -> pure ()
Left err -> do
logDebug $ "Disabled status not emitted" :# ["reason" .= err]
runRedis $ enqueue qs $ toStrict body -- proceed normally
Right status -> do
logInfo $ "Disabled status emitted" :# ["status" .= show @Text status]

sendResponseStatus @_ @Text status201 ""

0 comments on commit 0eaddf8

Please sign in to comment.