Skip to content

Commit f795b85

Browse files
committed
handle incoming PR and issue links and parse them
1 parent 09c8c12 commit f795b85

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/action.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,16 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
239239
| None -> Lwt.return_none
240240
| Some gh_link ->
241241
match gh_link with
242+
| Pull_request (repo, number) ->
243+
( match%lwt Github_api.get_pull_request ~ctx ~repo ~number with
244+
| Error _ -> Lwt.return_none
245+
| Ok pr -> Lwt.return_some @@ (link, Slack_message.populate_pull_request repo pr)
246+
)
247+
| Issue (repo, number) ->
248+
( match%lwt Github_api.get_issue ~ctx ~repo ~number with
249+
| Error _ -> Lwt.return_none
250+
| Ok issue -> Lwt.return_some @@ (link, Slack_message.populate_issue repo issue)
251+
)
242252
| Commit (repo, sha) ->
243253
( match%lwt Github_api.get_api_commit ~ctx ~repo ~sha with
244254
| Error _ -> Lwt.return_none

lib/github.ml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ let parse_exn ~secret headers body =
8787
| "member" | "create" | "delete" | "release" -> Event (event_notification_of_string body)
8888
| event -> failwith @@ sprintf "unsupported event : %s" event
8989

90-
type gh_link = Commit of repository * commit_hash
90+
type gh_link =
91+
| Pull_request of repository * int
92+
| Issue of repository * int
93+
| Commit of repository * commit_hash
9194

9295
(** `gh_link_of_string s` parses a URL string `s` to try to match a supported
9396
GitHub link type, generating repository endpoints if necessary *)
@@ -100,7 +103,7 @@ let gh_link_of_string url_str =
100103
let custom_api_base ?(scheme = "https") base owner name =
101104
sprintf "%s://%s/api/v3/repos/%s/%s" scheme base owner name
102105
in
103-
let re = Re.Str.regexp {|^\(.*\)/\(.+\)/\(.+\)/\(commit\)/\([a-z0-9]+\)/?$|} in
106+
let re = Re.Str.regexp {|^\(.*\)/\(.+\)/\(.+\)/\(commit\|pull\|issues\)/\([a-z0-9]+\)/?$|} in
104107
match Uri.host url with
105108
| None -> None
106109
| Some host ->
@@ -131,6 +134,8 @@ let gh_link_of_string url_str =
131134
begin
132135
try
133136
match link_type with
137+
| "pull" -> Some (Pull_request (repo, Int.of_string item))
138+
| "issues" -> Some (Issue (repo, Int.of_string item))
134139
| "commit" -> Some (Commit (repo, item))
135140
| _ -> None
136141
with _ -> None

0 commit comments

Comments
 (0)