Skip to content

Commit

Permalink
remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
yasunariw committed Dec 19, 2020
1 parent 44d32de commit 9422dac
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 85 deletions.
81 changes: 2 additions & 79 deletions lib/github.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ open Devkit
open Printf
open Github_j

exception Remote_config_error of string

let remote_config_error fmt = ksprintf (fun s -> raise (Remote_config_error s)) fmt

let log = Log.from "github"

type t =
| Push of commit_pushed_notification
| Pull_request of pr_notification
Expand Down Expand Up @@ -38,63 +32,10 @@ let commits_branch_of_ref ref =
| _ -> ref

let event_of_filename filename =
match String.split_on_chars filename ~on:[ '.' ] with
| [ kind; _name; ext ] when String.equal ext "json" -> Some kind
| _ -> None

let api_url_of_repo (repo : repository) =
Option.map ~f:(fun host ->
match host with
| "api.github.com" -> sprintf "https://%s" host
| _ -> sprintf "https://%s/api/v3" host)
@@ Uri.host
@@ Uri.of_string repo.url

let user_of_full_name_parts full_name_parts =
match full_name_parts with
| user :: _ -> Some user
match String.split_on_chars ~on:[ '.' ] filename with
| [ kind; _; "json" ] -> Some kind
| _ -> None

let name_of_full_name_parts full_name_parts =
match full_name_parts with
| _ :: repo_name :: _ -> Some repo_name
| _ -> None

let get_remote_config_json_url filename ?token req =
let repo = repo_of_notification req in
match String.split ~on:'/' repo.full_name with
| full_name_parts ->
match user_of_full_name_parts full_name_parts with
| None -> remote_config_error "unable to resolve repository owner"
| Some owner ->
match name_of_full_name_parts full_name_parts with
| None -> remote_config_error "unable to resolve repository name"
| Some repo_name ->
match api_url_of_repo repo with
| None -> remote_config_error "unable to resolve github api url from repository url"
| Some base_url ->
let url = sprintf "%s/repos/%s/%s/contents/%s" base_url owner repo_name filename in
begin
match token with
| None -> url
| Some token -> sprintf "%s?access_token=%s" url token
end

let config_of_content_api_response response =
try%lwt
match response.encoding with
| "base64" ->
Lwt.return
@@ Config_j.config_of_string
@@ Common.decode_string_pad
@@ String.concat
@@ String.split_lines
@@ response.content
| e -> remote_config_error "unknown encoding format '%s'" e
with
| Base64.Invalid_char -> remote_config_error "unable to decode configuration file from base64"
| Yojson.Json_error msg -> remote_config_error "unable to parse configuration file as valid JSON (%s)" msg

let is_main_merge_message ~msg:message ~branch (cfg : Config.t) =
match cfg.main_branch_name with
| Some main_branch when String.equal branch main_branch ->
Expand Down Expand Up @@ -123,24 +64,6 @@ let is_valid_signature ~secret headers_sig body =
let (`Hex request_hash) = Hex.of_string request_hash in
String.equal headers_sig (sprintf "sha1=%s" request_hash)

let load_config_json url =
let headers = [ "Accept: application/vnd.github.v3+json" ] in
match%lwt Web.http_request_lwt ~headers `GET url with
| `Error e -> remote_config_error "error while querying github api %s: %s" url e
| `Ok s -> config_of_content_api_response @@ Github_j.content_api_response_of_string s

let query_api ?token ~url parse =
let headers = Option.map token ~f:(fun t -> [ sprintf "Authorization: token %s" t ]) in
match%lwt Web.http_request_lwt ~ua:"notabot" ~verbose:true ?headers `GET url with
| `Error e ->
log#error "error while querying github api %s: %s" url e;
Lwt.return_none
| `Ok s ->
try Lwt.return_some (parse s)
with exn ->
log#error ~exn "impossible to parse github api answer to %s" url;
Lwt.return_none

(* Parse a payload. The type of the payload is detected from the headers. *)
let parse_exn ~secret headers body =
begin
Expand Down
6 changes: 0 additions & 6 deletions lib/slack.ml
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,3 @@ let generate_commit_comment_notification api_commit notification =
in
let notifs = { text = None; attachments = Some [ attachment ]; blocks = None } in
Lwt.return notifs

let send_notification webhook_url data =
let body = `Raw ("application/json", data) in
match%lwt Web.http_request_lwt ~verbose:true ~body `POST webhook_url with
| `Ok _ -> Lwt.return_unit
| `Error e -> Exn_lwt.fail "failed to send notification to slack : %s" e

0 comments on commit 9422dac

Please sign in to comment.