From a5e91b71a6e66cbb989f5250ec586ce72d7a7733 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 27 Feb 2024 11:15:42 +0200 Subject: Review --- mod/mod-ci-github.hxx | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) (limited to 'mod/mod-ci-github.hxx') diff --git a/mod/mod-ci-github.hxx b/mod/mod-ci-github.hxx index 72bbf82..4f724af 100644 --- a/mod/mod-ci-github.hxx +++ b/mod/mod-ci-github.hxx @@ -12,8 +12,101 @@ #include #include +namespace butl +{ + namespace json + { + class parser; + } +} + namespace brep { + // GitHub request/response types. + // + // Note that having this types directly in brep causes clashes (e.g., for + // the repository name). + // + namespace gh + { + // The "check_suite" object within a check_quite webhook request. + // + struct check_suite + { + uint64_t id; + string head_branch; + string head_sha; + string before; + string after; + + explicit + check_suite (json::parser&); + + check_suite () = default; + }; + + struct repository + { + string name; + string full_name; + string default_branch; + + explicit + repository (json::parser&); + + repository () = default; + }; + + struct installation + { + uint64_t id; + + explicit + installation (json::parser&); + + installation () = default; + }; + + struct check_suite_event + { + string action; + gh::check_suite check_suite; + gh::repository repository; + gh::installation installation; + + explicit + check_suite_event (json::parser&); + + check_suite_event () = default; + }; + + struct installation_access_token + { + string token; + timestamp expires_at; + + explicit + installation_access_token (json::parser&); + + installation_access_token () = default; + }; + + static ostream& + operator<< (ostream&, const check_suite&); + + static ostream& + operator<< (ostream&, const repository&); + + static ostream& + operator<< (ostream&, const installation&); + + static ostream& + operator<< (ostream&, const check_suite_event&); + + static ostream& + operator<< (ostream&, const installation_access_token&); + } + class ci_github: public handler { public: @@ -35,6 +128,19 @@ namespace brep virtual void init (cli::scanner&); + // Handle the check_suite event `requested` and `rerequested` actions. + // + bool + handle_check_suite_request (check_suite_event) const; + + void string + generate_jwt () const; + + // Authenticate to GitHub as an app installation. + // + gh::installation_access_token + obtain_installation_access_token (string jwt) const; + private: shared_ptr options_; }; -- cgit v1.1