-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add config for failed builds channel
- Loading branch information
1 parent
6c0c4f1
commit 4c48263
Showing
13 changed files
with
245 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
open Devkit | ||
|
||
let fmt_error ?exn fmt = | ||
Printf.ksprintf | ||
(fun s -> | ||
match exn with | ||
| Some exn -> Error (s ^ " : exn " ^ Exn.str exn) | ||
| None -> Error s) | ||
fmt | ||
|
||
let first_line s = | ||
match String.split_on_char '\n' s with | ||
| x :: _ -> x | ||
| [] -> s | ||
|
||
let decode_string_pad s = Stre.rstrip ~chars:"= \n\r\t" s |> Base64.decode_exn ~pad:false | ||
|
||
let http_request ?headers ?body meth path = | ||
let setup h = | ||
Curl.set_followlocation h true; | ||
Curl.set_maxredirs h 1 | ||
in | ||
match%lwt Web.http_request_lwt ~setup ~ua:"monorobot" ~verbose:true ?headers ?body meth path with | ||
| `Ok s -> Lwt.return @@ Ok s | ||
| `Error e -> Lwt.return @@ Error e | ||
|
||
let sign_string_sha256 ~key ~basestring = | ||
Cstruct.of_string basestring |> Nocrypto.Hash.SHA256.hmac ~key:(Cstruct.of_string key) |> Hex.of_cstruct |> Hex.show | ||
|
||
module Build = struct | ||
let buildkite_is_failed_re = Re2.create_exn {|^Build #\d+ failed|} | ||
|
||
let is_failed_build (n : Github_t.status_notification) = | ||
n.state = Failure && Re2.matches buildkite_is_failed_re (Option.default "" n.description) | ||
|
||
let new_failed_steps (n : Github_t.status_notification) (repo_state : State_t.repo_state) pipeline = | ||
let to_failed_steps branch step statuses acc = | ||
(* check if step of an allowed pipeline *) | ||
match step with | ||
| step when step = pipeline -> acc | ||
| step when not @@ Devkit.Stre.starts_with step pipeline -> acc | ||
| _ -> | ||
match Common.StringMap.find_opt branch statuses with | ||
| Some (s : State_t.build_status) when s.status = Failure -> | ||
(match s.current_failed_commit, s.original_failed_commit with | ||
| Some _, _ -> | ||
(* if we have a value for current_failed_commit, this step was already failed and notified *) | ||
acc | ||
| None, Some { build_link = Some build_link; sha; _ } when sha = n.commit.sha -> | ||
(* we need to check the value of the commit sha to avoid false positives *) | ||
(step, build_link) :: acc | ||
| _ -> acc) | ||
| _ -> acc | ||
in | ||
match n.state = Failure, n.branches with | ||
| false, _ -> [] | ||
| true, [ branch ] -> Common.StringMap.fold (to_failed_steps branch.name) repo_state.pipeline_statuses [] | ||
| true, _ -> [] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
{ | ||
"pipeline_statuses": { | ||
"buildkite/pipeline2": { | ||
"master": { | ||
"buildkite/pipeline2/failed-step": { | ||
"author/patches/js-storage": { | ||
"status": "failure", | ||
"original_failed_commit": { | ||
"sha": "7e0a933e9c71b4ca107680ca958ca1888d5e479b", | ||
"author": "[email protected]", | ||
"url": "https://github.com/ahrefs/monorepo/commit/7e0a933e9c71b4ca107680ca958ca1888d5e479b", | ||
"commit_message": "c1 message", | ||
"build_link": [ | ||
"Some", | ||
"https://buildkite.com/ahrefs/monorepo/builds/181732" | ||
"https://buildkite.com/ahrefs/monorepo/builds/181732#0192347d-e4ee-4072-9da4-f441eeb65ed4" | ||
], | ||
"last_updated": "2024-06-02T04:57:47+00:00" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"pipeline_statuses": { | ||
"buildkite/pipeline2": { | ||
"master": { | ||
"status": "failure", | ||
"original_failed_commit": { | ||
"sha": "0d95302addd66c1816bce1b1d495ed1c93ccd478", | ||
"author": "[email protected]", | ||
"url": "https://github.com/ahrefs/monorepo/commit/0d95302addd66c1816bce1b1d495ed1c93ccd478", | ||
"commit_message": "Update README.md", | ||
"build_link": [ | ||
"Some", | ||
"https://buildkite.com/org/pipeline2/builds/2#0192341c-4f46-4bfc-82ab-48415b146f40" | ||
], | ||
"last_updated": "2024-06-02T04:57:47+00:00" | ||
} | ||
} | ||
}, | ||
"buildkite/pipeline2/failed-step": { | ||
"master": { | ||
"status": "failure", | ||
"original_failed_commit": { | ||
"sha": "0d95302addd66c1816bce1b1d495ed1c93ccd478", | ||
"author": "[email protected]", | ||
"url": "https://github.com/ahrefs/monorepo/commit/0d95302addd66c1816bce1b1d495ed1c93ccd478", | ||
"commit_message": "Update README.md", | ||
"build_link": [ | ||
"Some", | ||
"https://buildkite.com/org/pipeline2/builds/2#0192341c-4f46-4bfc-82ab-48415b146f40" | ||
], | ||
"last_updated": "2024-06-02T04:57:47+00:00" | ||
} | ||
} | ||
} | ||
}, | ||
"pipeline_commits": { | ||
"buildkite/pipeline2": { | ||
"s1": ["0d95302addd66c1816bce1b1d495ed1c93ccd478"], | ||
"s2": [] | ||
} | ||
} | ||
} |
Oops, something went wrong.