feat: delivery id, review events, files and commits of PR #24

Merged
lambdajon merged 9 commits from feat/pr-tracking into main 2026-10-09 06:54:22 +00:00
Member

Webhook callback can get X-Forgejo-Delivery through webhookHandlerWith now, and review events are parsed as pull request payload. Events which we don't handle answer 200 instead of 400, so Forgejo doesn't show them as failed.

Also added getPullRequestFiles and getPullRequestCommits (reads all pages, page size is optional) and all pull request hook actions in HookPullRequestAction. Kotiba needs them for PR tracking.

Additional: Separating treefmtPackage due to code style in all our repos.

Webhook callback can get `X-Forgejo-Delivery` through `webhookHandlerWith` now, and review events are parsed as pull request payload. Events which we don't handle answer 200 instead of 400, so Forgejo doesn't show them as failed. Also added `getPullRequestFiles` and `getPullRequestCommits` (reads all pages, page size is optional) and all pull request hook actions in `HookPullRequestAction`. Kotiba needs them for PR tracking. Additional: Separating treefmtPackage due to code style in all our repos.
xfeusw self-assigned this 2026-10-03 01:33:53 +00:00
xfeusw changed title from WIP: [FEATURE]: PR tracking-related features to feat: delivery id, review events, files and commits of PR 2026-10-07 09:36:09 +00:00
lambdajon requested changes 2026-10-08 06:38:10 +00:00
Dismissed
@ -109,3 +124,3 @@
data HookPullRequestAction
= PrOpened
| PrClosed
| PrClosed -- a merged PR is closed with prMerged = True
Member

I think it would also be ergonomic to make the PrMerged action separate.

I think it would also be ergonomic to make the `PrMerged` action separate.
Author
Member

But PrClosed state is works for both: Not merged and merged PRs. It's better to keep merged as separate field via keeping PrClosed state only, 'cause it matches Forgejo's philosophy in point.

But PrClosed state is works for both: Not merged and merged PRs. It's better to keep merged as separate field via keeping PrClosed state only, 'cause it matches Forgejo's philosophy in point.
Member

Hmm, but all VCS hosts have actions corresponding to the "PR merged" event.

Hmm, but all VCS hosts have actions corresponding to the "PR merged" event.
Author
Member

codeberg.org/forgejo/forgejo@085044a2cc/modules/structs/hook.go (L291-L320)

As you can see, here's no PrMerged action because of Forgejo sees pulls and issues same. And developing ergonomics of PrMerged action will create more pain in the neck instead as it doesn't match to Forgejo's source code itself

https://codeberg.org/forgejo/forgejo/src/commit/085044a2cce61245125373fc98bd202075b5f4e7/modules/structs/hook.go#L291-L320 As you can see, here's no PrMerged action because of Forgejo sees pulls and issues same. And developing ergonomics of PrMerged action will create more pain in the neck instead as it doesn't match to Forgejo's source code itself
xfeusw marked this conversation as resolved
@ -0,0 +12,4 @@
-- A commit as listed by GET /repos/{owner}/{repo}/pulls/{index}/commits.
-- Only the fields we use are decoded.
data PullRequestCommit = PullRequestCommit
{ pcSha :: Text
Member

which sha ? you mean sha1 or sha256 ?

which sha ? you mean `sha1` or `sha256` ?
xfeusw marked this conversation as resolved
@ -43,0 +94,4 @@
-> Maybe Text
-> Value
-> m ()
webhookHandlerWith cb (Just (Right event)) mEventType mDeliveryId body =
Member

use LambdaCase

use `LambdaCase`
Author
Member

How?

How?
Member

ah, we have destructors :(

ah, we have destructors :(
lambdajon marked this conversation as resolved
@ -43,0 +98,4 @@
case parseWebhookPayload event body of
Left err -> throwError err400{errBody = BSLC.pack err}
Right Nothing -> pure ()
Right (Just payload) -> cb delivery payload
Member

Is it correct for us to send the parsed payload return as webhook response?

Is it correct for us to send the parsed payload return as webhook response?
Author
Member

cb is our custom function which is passed as argument into webhookHandlerWith

cb is our custom function which is passed as argument into webhookHandlerWith
xfeusw marked this conversation as resolved
Member

I think need to wrap newtype for sha references.

newtype ShaRef = ShaRef { unShaRef :: Text }
instance FromJSON ShaRef where
  parseJSON = withObject "ShaRef" (fmap ShaRef . (.: "sha"))

And we can use like this.

...
    pcParents <- map unShaRef <$> o .:? "parents" .!= []
  pure PullRequestCommit {..}
...
I think need to wrap newtype for sha references. ```hs newtype ShaRef = ShaRef { unShaRef :: Text } instance FromJSON ShaRef where parseJSON = withObject "ShaRef" (fmap ShaRef . (.: "sha")) ``` And we can use like this. ```hs ... pcParents <- map unShaRef <$> o .:? "parents" .!= [] pure PullRequestCommit {..} ...
lambdajon requested changes 2026-10-08 06:46:32 +00:00
Dismissed
@ -50,0 +110,4 @@
TODO: stop on empty page instead, so that a big size can't skip data. It costs one more request per list.
-}
fetchAllPages :: (Monad m) => Int -> (Int -> Int -> m [a]) -> m [a]
Member

maybe good if apis like this take Settgins parameter because fetch APIs can have multiple query parameters, such as page, pageSize, filter etc...

maybe good if apis like this take `Settgins` parameter because fetch APIs can have multiple query parameters, such as `page`, `pageSize`, `filter` etc...
Author
Member

Will create issue for enhancing fetchAllPages

Will create issue for enhancing `fetchAllPages`
xfeusw marked this conversation as resolved
lambdajon requested changes 2026-10-08 06:47:49 +00:00
Dismissed
@ -34,6 +36,7 @@ data PullRequestRoutes route = PullRequestRoutes
'[ WithStatus 201 [PullReviewRequest]
, WithStatus 422 APIValidationError
]
-- ^ POST /repos/:owner/:repo/pulls/:index/requested_reviewers
Member

wrhite paths like this
/repos/{owner}/{repo}/pulls/{index}/requested_reviewers

wrhite paths like this `/repos/{owner}/{repo}/pulls/{index}/requested_reviewers`
xfeusw marked this conversation as resolved
Author
Member

@lambdajon wrote in #24 (comment):

I think need to wrap newtype for sha references.

newtype ShaRef = ShaRef { unShaRef :: Text }
instance FromJSON ShaRef where
  parseJSON = withObject "ShaRef" (fmap ShaRef . (.: "sha"))

And we can use like this.

...
    pcParents <- map unShaRef <$> o .:? "parents" .!= []
  pure PullRequestCommit {..}
...

I think it's better to create separated issue for this task. Because we have countless of sha references in our codebase, so we would avoid increasing offtopic changes in current PR by implementing your idea in separated PR

@lambdajon wrote in https://git.oss.uzinfocom.uz/uzinfocom/forgejo/pulls/24#issuecomment-6257: > I think need to wrap newtype for sha references. > > ```hs > newtype ShaRef = ShaRef { unShaRef :: Text } > instance FromJSON ShaRef where > parseJSON = withObject "ShaRef" (fmap ShaRef . (.: "sha")) > ``` > > And we can use like this. > > ```hs > ... > pcParents <- map unShaRef <$> o .:? "parents" .!= [] > pure PullRequestCommit {..} > ... > ``` I think it's better to create separated issue for this task. Because we have countless of sha references in our codebase, so we would avoid increasing offtopic changes in current PR by implementing your idea in separated PR
lambdajon approved these changes 2026-10-09 06:54:05 +00:00
lambdajon deleted branch feat/pr-tracking 2026-10-09 06:54:22 +00:00
lambdajon referenced this pull request from a commit 2026-10-09 09:30:57 +00:00
Sign in to join this conversation.
No description provided.