Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#150 REFACTOR VCS Provider matrix #295

Merged
merged 2 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 116 additions & 1 deletion code/pds.conf
Original file line number Diff line number Diff line change
Expand Up @@ -708,23 +708,31 @@ deps = [
"terrat_base_repo_config_v1",
"terrat_change",
"terrat_change_match3",
"terrat_code_idx",
"terrat_comment",
"terrat_commit_check",
"terrat_config",
"terrat_data",
"terrat_dirspace",
"terrat_evaluator3",
"terrat_files",
"terrat_github",
"terrat_github_webhooks",
"terrat_metrics",
"terrat_plan_diff",
"terrat_pull_request",
"terrat_repo_config",
"terrat_session",
"terrat_sql_of_tag_query",
"terrat_storage",
"terrat_tag_query",
"terrat_tag_query_ast",
"terrat_tag_query_lexer",
"terrat_tag_query_parser",
"terrat_tag_set",
"terrat_telemetry",
"terrat_user",
"terrat_vcs_github",
"terrat_vcs_provider",
"terrat_work_manifest3",
"terratc_intf",
Expand Down Expand Up @@ -773,6 +781,12 @@ deps = [
"yojson",
]

[src.terrat_code_idx]
install = false
deps = [
"terrat_api",
]

[src.terrat_code_indexer]
install = false
type = "exec"
Expand Down Expand Up @@ -806,9 +820,21 @@ type = "exec"
install = false
deps = [
"terrat",
"terrat_vcs_github",
"terratc_ee",
]

[src.terrat_evaluator3]
install = false
deps = [
"abb",
"abb_flow",
"abbs",
"containers",
"terrat_storage",
"terrat_vcs_provider",
]

[src.terrat_files]
install = false
extra_makefile_lines = ["include $(SRC_DIR)/files.mk"]
Expand All @@ -822,11 +848,18 @@ install = false
deps = ["cohttp", "containers", "json_schema", "mirage-crypto", "ppx_deriving.eq", "ppx_deriving.make", "ppx_deriving.show", "ppx_deriving_yojson", "yojson"]
extra_makefile_lines = ["DOC_FILES:=$(wildcard $(SRC_DIR)/*.ml)"]

[src.terrat_metrics]
install = false
deps = [
"prmths",
]

[src.terrat_oss]
type = "exec"
install = false
deps = [
"terrat",
"terrat_vcs_github",
"terratc_oss",
]

Expand Down Expand Up @@ -858,6 +891,14 @@ deps = [
"yojson",
]

[src.terrat_storage]
install = false
deps = [
"pgsql_pool",
"prmths",
"terrat_config",
]

[src.terrat_tag_query]
install = false
deps = ["containers", "path_glob", "ppx_deriving", "ppx_deriving.eq", "ppx_deriving.show", "terrat_dirspace", "terrat_tag_query_ast", "terrat_tag_set"]
Expand All @@ -883,6 +924,28 @@ deps = []
install = false
deps = ["containers", "ppx_deriving", "ppx_deriving.show"]

[src.terrat_task]
install = false
deps = [
"abb",
"abbs",
"pgsql_io",
"terrat_storage",
"uuidm",
]

[src.terrat_telemetry]
install = false
deps = [
"abb",
"abb_curl_easy",
"abbs",
"logs",
"terrat_config",
"terrat_work_manifest3",
"uri",
]

[src.terrat_ui]
type = "exec"
install = false
Expand Down Expand Up @@ -943,9 +1006,60 @@ extra_makefile_lines = ["OCAMLC_LINK_OPTS=", "OCAMLOPT_LINK_OPTS=", "all: terrat
[src.terrat_ui_sw.profile]
extra_makefile_lines = ["OCAMLC_LINK_OPTS=", "OCAMLOPT_LINK_OPTS=", "all: terrat_ui_sw.js", "terrat_ui_sw.js: $(BYTE_TARGET)", "\tjs_of_ocaml --pretty --source-map-inline $(shell env OCAMLPATH=$(OCAMLPATH) ocamlfind query -r -format '%+(jsoo_runtime)' -separator ' ' $(PACKAGES)) terrat_ui_sw.byte"]

[src.terrat_user]
install = false
deps = [
"abb",
"brtl",
"containers",
"pgsql_io",
"pgsql_pool",
"terrat_storage",
"uuidm",
]

[src.terrat_session]
install = false
deps = [
"terrat_storage",
"brtl",
"terrat_user",
"brtl_mw_session",
]

[src.terrat_vcs_github]
install = false
deps = [
"abb",
"abbs",
"brtl",
"brtl_permissions",
"containers",
"githubc2",
"pgsql_io",
"terrat_api",
"terrat_base_repo_config_v1",
"terrat_change",
"terrat_code_idx",
"terrat_config",
"terrat_evaluator3",
"terrat_github",
"terrat_github_webhooks",
"terrat_metrics",
"terrat_pull_request",
"terrat_session",
"terrat_storage",
"terrat_task",
"terrat_telemetry",
"terrat_user",
"terrat_vcs_provider",
"terrat_work_manifest3",
]

[src.terrat_vcs_provider]
install = false
deps = [
"brtl",
"containers",
"pgsql_io",
"terrat_access_control",
Expand All @@ -956,8 +1070,9 @@ deps = [
"terrat_comment",
"terrat_commit_check",
"terrat_config",
"terrat_files",
"terrat_plan_diff",
"terrat_pull_request",
"terrat_work_manifest3",
"terratc_intf",
]

Expand Down
9 changes: 0 additions & 9 deletions code/src/terrat/terrat_ep_github_events3.mli

This file was deleted.

4 changes: 2 additions & 2 deletions code/src/terrat/terrat_ep_installations.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1280,11 +1280,11 @@ module Repos = struct
Terrat_user.enforce_installation_access storage user installation_id ctx
>>= fun () ->
let open Abb.Future.Infix_monad in
Terrat_github_installation.refresh_repos'
Terrat_vcs_github_installation.refresh_repos'
~request_id:(Brtl_ctx.token ctx)
~config
~storage
(Terrat_github_installation.Id.make installation_id)
(Terrat_vcs_github_installation.Id.make installation_id)
>>= function
| Ok task ->
let id = Uuidm.to_string (Terrat_task.id task) in
Expand Down
16 changes: 12 additions & 4 deletions code/src/terrat/terrat_ep_user.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module Installations = struct

let get' config storage user =
let open Abbs_future_combinators.Infix_result_monad in
Terrat_github_user.get_token config storage user
Terrat_vcs_github_user.get_token config storage user
>>= fun token ->
Terrat_github.with_client config (`Bearer token) Terrat_github.get_user_installations
>>= fun installations ->
Expand Down Expand Up @@ -65,7 +65,11 @@ module Installations = struct
Abb.Future.return (Ok (Brtl_ctx.set_response (Brtl_rspnc.create ~status:`OK body) ctx))
| Error (`Refresh_err _ as err) ->
Logs.err (fun m ->
m "%s : GET : INSTALLATIONS : %a" (Brtl_ctx.token ctx) Terrat_github_user.pp_err err);
m
"%s : GET : INSTALLATIONS : %a"
(Brtl_ctx.token ctx)
Terrat_vcs_github_user.pp_err
err);
Abb.Future.return
(Ok (Brtl_ctx.set_response (Brtl_rspnc.create ~status:`Forbidden "") ctx))
| Error `Bad_refresh_token ->
Expand All @@ -92,9 +96,13 @@ module Installations = struct
err);
Abb.Future.return
(Ok (Brtl_ctx.set_response (Brtl_rspnc.create ~status:`Internal_server_error "") ctx))
| Error (#Terrat_github_user.err as err) ->
| Error (#Terrat_vcs_github_user.err as err) ->
Logs.err (fun m ->
m "%s : GET : INSTALLATIONS : %a" (Brtl_ctx.token ctx) Terrat_github_user.pp_err err);
m
"%s : GET : INSTALLATIONS : %a"
(Brtl_ctx.token ctx)
Terrat_vcs_github_user.pp_err
err);
Abb.Future.return
(Ok (Brtl_ctx.set_response (Brtl_rspnc.create ~status:`Internal_server_error "") ctx)))
end
20 changes: 10 additions & 10 deletions code/src/terrat/terrat_server.ml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module Make
(Terratc :
Terratc_intf.S
with type Github.Client.t = Terrat_github_evaluator3.S.Client.t
and type Github.Account.t = Terrat_github_evaluator3.S.Account.t
and type Github.Repo.t = Terrat_github_evaluator3.S.Repo.t
and type Github.Remote_repo.t = Terrat_github_evaluator3.S.Remote_repo.t
and type Github.Ref.t = Terrat_github_evaluator3.S.Ref.t) =
with type Github.Client.t = Terrat_vcs_github.S.Client.t
and type Github.Account.t = Terrat_vcs_github.S.Account.t
and type Github.Repo.t = Terrat_vcs_github.S.Repo.t
and type Github.Remote_repo.t = Terrat_vcs_github.S.Remote_repo.t
and type Github.Ref.t = Terrat_vcs_github.S.Ref.t) =
struct
module Github_evaluator = Terrat_github_evaluator3.Make (Terratc)
module Github_events = Terrat_ep_github_events3.Make (Terratc)
module Github_work_manifest = Terrat_ep_github_work_manifest3.Make (Terratc)
module Github_evaluator = Terrat_vcs_github.Make (Terratc)
module Github_events = Terrat_vcs_github_ep_events3.Make (Terratc)
module Github_work_manifest = Terrat_vcs_github_ep_work_manifest.Make (Terratc)

module Rt = struct
let api () = Brtl_rtng.Route.(rel / "api")
Expand Down Expand Up @@ -196,8 +196,8 @@ struct
--> Github_work_manifest.Access_token.post config storage );
(* Github *)
(`POST, Rt.github_events () --> Github_events.post config storage);
(`GET, Rt.github_callback () --> Terrat_ep_github_callback.get config storage);
(`GET, Rt.github_client_id () --> Terrat_ep_github_client_id.get config storage);
(`GET, Rt.github_callback () --> Terrat_vcs_github_ep_callback.get config storage);
(`GET, Rt.github_client_id () --> Terrat_vcs_github_ep_client_id.get config storage);
(* User *)
(`GET, Rt.whoami () --> Terrat_ep_whoami.get config storage);
(`GET, Rt.user_installations_rt () --> Terrat_ep_user.Installations.get config storage);
Expand Down
13 changes: 7 additions & 6 deletions code/src/terrat/terrat_server.mli
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module Make
(Terratc : Terratc_intf.S
with type Github.Client.t = Terrat_github_evaluator3.S.Client.t
and type Github.Account.t = Terrat_github_evaluator3.S.Account.t
and type Github.Repo.t = Terrat_github_evaluator3.S.Repo.t
and type Github.Remote_repo.t = Terrat_github_evaluator3.S.Remote_repo.t
and type Github.Ref.t = Terrat_github_evaluator3.S.Ref.t) : sig
(Terratc :
Terratc_intf.S
with type Github.Client.t = Terrat_vcs_github.S.Client.t
and type Github.Account.t = Terrat_vcs_github.S.Account.t
and type Github.Repo.t = Terrat_vcs_github.S.Repo.t
and type Github.Remote_repo.t = Terrat_vcs_github.S.Remote_repo.t
and type Github.Ref.t = Terrat_vcs_github.S.Ref.t) : sig
val run : Terrat_config.t -> Terrat_storage.t -> unit Abb.Future.t
end
2 changes: 1 addition & 1 deletion code/src/terrat_ee/terrat_ee.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Terratc = Terratc_ee.Make (struct
module Github = Terrat_github_evaluator3.S
module Github = Terrat_vcs_github.S
end)

module Server = Terrat_server.Make (Terratc)
Expand Down
2 changes: 1 addition & 1 deletion code/src/terrat_oss/terrat_oss.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Terratc = Terratc_oss.Make (struct
module Github = Terrat_github_evaluator3.S
module Github = Terrat_vcs_github.S
end)

module Server = Terrat_server.Make (Terratc)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,10 @@ struct
include S
module Db = Pgsql_io

module Routes = struct
let get = []
end

module Drift = struct
type t
end
Expand Down Expand Up @@ -4321,7 +4325,7 @@ struct
"GITHUB_EVALUATOR : %s : CREATE_COMMIT_CHECKS : num=%d"
request_id
(CCList.length checks));
Terrat_github_commit_check.create
Terrat_vcs_github_commit_check.create
~owner:(Repo.owner repo)
~repo:(Repo.name repo)
~ref_
Expand All @@ -4343,16 +4347,21 @@ struct
(fun time ->
Logs.info (fun m -> m "GITHUB_EVALUATOR : %s : LIST_COMMIT_CHECKS : %f" request_id time))
(fun () ->
Terrat_github_commit_check.list ~log_id:request_id ~owner ~repo ~ref_ client.Client.client)
Terrat_vcs_github_commit_check.list
~log_id:request_id
~owner
~repo
~ref_
client.Client.client)
>>= function
| Ok _ as res -> Abb.Future.return res
| Error (#Terrat_github_commit_check.list_err as err) ->
| Error (#Terrat_vcs_github_commit_check.list_err as err) ->
Prmths.Counter.inc_one Metrics.github_errors_total;
Logs.err (fun m ->
m
"GITHUB_EVALUATOR : %s : FETCH_COMMIT_CHECKS : %a"
request_id
Terrat_github_commit_check.pp_list_err
Terrat_vcs_github_commit_check.pp_list_err
err);
Abb.Future.return (Error `Error)

Expand Down
Loading