@@ -88,60 +88,54 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
88
88
if List. is_empty matched_channel_names then default else matched_channel_names
89
89
90
90
let partition_status (ctx : Context.t ) (n : status_notification ) =
91
- match ctx.config with
92
- | None -> action_error " missing configuration file"
93
- | Some cfg ->
94
- let pipeline = n.context in
95
- let current_status = n.state in
96
- let updated_at = n.updated_at in
97
- let get_commit_info () =
98
- let default = Option. to_list cfg.prefix_rules.default_channel in
99
- let () =
100
- Context. refresh_pipeline_status ~pipeline ~branches: n.branches ~status: current_status ~updated_at ctx
101
- in
102
- match List. is_empty n.branches with
103
- | true -> Lwt. return []
104
- | false ->
105
- match cfg.main_branch_name with
106
- | None -> Lwt. return default
107
- | Some main_branch_name ->
108
- (* non-main branch build notifications go to default channel to reduce spam in topic channels *)
109
- match List. exists n.branches ~f: (fun { name } -> String. equal name main_branch_name) with
110
- | false -> Lwt. return default
111
- | true ->
112
- let sha = n.commit.sha in
113
- let repo = n.repository in
114
- ( match % lwt Github_api. get_api_commit ~ctx ~repo ~sha with
115
- | Error e -> action_error e
116
- | Ok commit -> Lwt. return @@ partition_commit cfg commit.files
117
- )
118
- in
119
- let res =
120
- match
121
- List. exists cfg.status_rules.status ~f: (fun x ->
122
- match x with
123
- | State s -> Poly. equal s n.state
124
- | HideConsecutiveSuccess -> Poly. equal Success n.state
125
- | _ -> false )
126
- with
127
- | false -> Lwt. return []
128
- | true ->
129
- match List. exists ~f: id [ Rule.Status. hide_cancelled n cfg; Rule.Status. hide_success n ctx ] with
130
- | true -> Lwt. return []
131
- | false ->
132
- match cfg.status_rules.title with
133
- | None -> get_commit_info ()
134
- | Some status_filter ->
135
- match List. exists status_filter ~f: (String. equal n.context) with
136
- | false -> Lwt. return []
137
- | true -> get_commit_info ()
138
- in
139
- res
91
+ let cfg = Context. get_config_exn ctx in
92
+ let pipeline = n.context in
93
+ let current_status = n.state in
94
+ let updated_at = n.updated_at in
95
+ let get_commit_info () =
96
+ let default = Option. to_list cfg.prefix_rules.default_channel in
97
+ let () = Context. refresh_pipeline_status ~pipeline ~branches: n.branches ~status: current_status ~updated_at ctx in
98
+ match List. is_empty n.branches with
99
+ | true -> Lwt. return []
100
+ | false ->
101
+ match cfg.main_branch_name with
102
+ | None -> Lwt. return default
103
+ | Some main_branch_name ->
104
+ (* non-main branch build notifications go to default channel to reduce spam in topic channels *)
105
+ match List. exists n.branches ~f: (fun { name } -> String. equal name main_branch_name) with
106
+ | false -> Lwt. return default
107
+ | true ->
108
+ let sha = n.commit.sha in
109
+ let repo = n.repository in
110
+ ( match % lwt Github_api. get_api_commit ~ctx ~repo ~sha with
111
+ | Error e -> action_error e
112
+ | Ok commit -> Lwt. return @@ partition_commit cfg commit.files
113
+ )
114
+ in
115
+ let res =
116
+ match
117
+ List. exists cfg.status_rules.status ~f: (fun x ->
118
+ match x with
119
+ | State s -> Poly. equal s n.state
120
+ | HideConsecutiveSuccess -> Poly. equal Success n.state
121
+ | _ -> false )
122
+ with
123
+ | false -> Lwt. return []
124
+ | true ->
125
+ match List. exists ~f: id [ Rule.Status. hide_cancelled n cfg; Rule.Status. hide_success n ctx ] with
126
+ | true -> Lwt. return []
127
+ | false ->
128
+ match cfg.status_rules.title with
129
+ | None -> get_commit_info ()
130
+ | Some status_filter ->
131
+ match List. exists status_filter ~f: (String. equal n.context) with
132
+ | false -> Lwt. return []
133
+ | true -> get_commit_info ()
134
+ in
135
+ res
140
136
141
137
let partition_commit_comment (ctx : Context.t ) n =
142
- match ctx.config with
143
- | None -> action_error " missing configuration file"
144
- | Some cfg ->
138
+ let cfg = Context. get_config_exn ctx in
145
139
match n.comment.commit_id with
146
140
| None -> action_error " unable to find commit id for this commit comment event"
147
141
| Some sha ->
@@ -160,9 +154,7 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
160
154
)
161
155
162
156
let generate_notifications (ctx : Context.t ) req =
163
- match ctx.config with
164
- | None -> action_error " missing configuration file"
165
- | Some cfg ->
157
+ let cfg = Context. get_config_exn ctx in
166
158
match req with
167
159
| Github. Push n ->
168
160
partition_push cfg n |> List. map ~f: (fun (webhook , n ) -> webhook, generate_push_notification n) |> Lwt. return
@@ -231,7 +223,8 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
231
223
232
224
let process_github_notification (ctx : Context.t ) headers body =
233
225
try % lwt
234
- match Github. parse_exn ~secret: ctx.gh_hook_token headers body with
226
+ let secrets = Context. get_secrets_exn ctx in
227
+ match Github. parse_exn ~secret: secrets.gh_hook_token headers body with
235
228
| exception exn -> Exn_lwt. fail ~exn " failed to parse payload"
236
229
| payload ->
237
230
( match % lwt refresh_config_of_context ctx payload with
@@ -251,4 +244,7 @@ module Action (Github_api : Api.Github) (Slack_api : Api.Slack) = struct
251
244
| Action_error msg ->
252
245
log#error " %s" msg;
253
246
Lwt. return_unit
247
+ | Context. Context_error msg ->
248
+ log#error " %s" msg;
249
+ Lwt. return_unit
254
250
end
0 commit comments