Skip to content

Commit

Permalink
web: add crawler api codegen
Browse files Browse the repository at this point in the history
This change enables the web client to query the crawler api to collect
any errors.
  • Loading branch information
TristanCacqueray committed Dec 22, 2023
1 parent 4084bff commit 9f040a7
Show file tree
Hide file tree
Showing 16 changed files with 3,839 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ codegen-haskell:

codegen-javascript:
rm -f web/src/messages/*
sh -c 'for pb in $(MESSAGES); do ocaml-protoc $(PINCLUDE) -bs -ml_out web/src/messages/ schemas/$${pb}; done'
sh -c 'for pb in $(MESSAGES) $(CRAWLER); do ocaml-protoc $(PINCLUDE) -bs -ml_out web/src/messages/ schemas/$${pb}; done'
python3 ./codegen/rename_bs_module.py ./web/src/messages/

codegen-openapi:
Expand Down
1 change: 0 additions & 1 deletion codegen/MonocleCodegen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ protoToReScript = fromProto headers mkService
msgName moduleName msg = moduleName <> "Types." <> snake (attrName msg)

mkMethod moduleName (name, input, output, path)
| "/crawler/" `Text.isInfixOf` path = []
| otherwise =
[ "@module(\"axios\")"
, "external " <> camel name <> "Raw: (string, 'a) => axios<'b> = \"post\""
Expand Down
71 changes: 53 additions & 18 deletions codegen/rename_bs_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,73 @@ def fix_field_name(content):
)
.replace("Task_data_types", "TaskDataTypes")
.replace("Task_data_bs", "TaskDataBs")
#.replace("Ratio", "_ratio")
.replace("Change_types", "ChangeTypes")
.replace("Change_bs", "ChangeBs")
.replace("Search_types", "SearchTypes")
.replace("Search_bs", "SearchBs")
.replace("Issue_types", "IssueTypes")
.replace("Issue_bs", "IssueBs")
.replace("_ofChanges", "_of_changes")
.replace("_withTests", "_with_tests")
.replace("_perChange", "_per_change")
# on_createdAt -> on_created_at
.replace("edAt", "ed_at")
.replace("commitAt", "commit_at")
.replace("Count", "_count")
)


def fix_timestamp(content):
# Fix timestamp message encoding which is a rfc3339 string, not an object
return (
functools.reduce(
lambda acc, field: acc.replace(
field + '" (Js.Json.object_', field + '" (Js.Json.string'
),
# TODO: add new timestamp field to this list, e.g. when this error happens:
# Js.Dict.set json "updated_at" (Js.Json.object_ json');
# This has type: string, Somewhere wanted: Js.Json.t Js.Dict.t
[
"timestamp",
"updated_at",
"closed_at",
"created_at",
"changed_at",
"authored_at",
"committed_at",
"merged_at",
"commit_at",
],
content,
)
.replace(
"TimestampBs.decode_timestamp (Pbrt_bs.object_",
"TimestampBs.decode_timestamp (Pbrt_bs.string",
)
.replace(
# The codegen believes that TimestampTypes.default_timestamp is a function but it is a term
"TimestampTypes.default_timestamp ()",
"TimestampTypes.default_timestamp",
)
)


def fix_enum(content):
# Fix the following error:
# This variant constructor, Change_commit_pushed, expects 0 arguments; here, we've found 1.
return functools.reduce(
lambda acc, field: acc.replace(
field + '" (Js.Json.object_', field + '" (Js.Json.string'
),
# TODO: add new timestamp field to this list, e.g. when this error happens:
# Js.Dict.set json "updated_at" (Js.Json.object_ json');
# This has type: string, Somewhere wanted: Js.Json.t Js.Dict.t
lambda acc, field: acc.replace("| " + field + " v ->", "| " + field + " ->"),
[
"timestamp",
"updated_at",
"created_at",
"changed_at",
"authored_at",
"committed_at",
"merged_at",
"Change_created",
"Change_commented",
"Change_abandoned",
"Change_commit_force_pushed",
"Change_commit_pushed",
"Change_merged",
"Issue_created",
"Issue_closed",
],
content,
).replace(
"TimestampBs.decode_timestamp (Pbrt_bs.object_",
"TimestampBs.decode_timestamp (Pbrt_bs.string",
)


Expand All @@ -83,7 +118,7 @@ def fix_module(filepath):
typeName = pascalCase(filepath.name.split("_bs")[0] + "_types")
newTypeName = pascalCases(typeName)
content = content.replace(typeName, newTypeName)
newFile.write_text(fix_timestamp(fix_field_name(content)))
newFile.write_text(fix_enum(fix_timestamp(fix_field_name(content))))


def fixable_file(filename):
Expand Down
37 changes: 37 additions & 0 deletions web/src/components/WebApi.res

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9f040a7

Please sign in to comment.