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

Fixes for web hooks and oauth urls. #48

Merged
merged 2 commits into from
Mar 30, 2022
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
2 changes: 1 addition & 1 deletion lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
(public_name gitlab)
(wrapped false)
(modules gitlab_s gitlab_core gitlab_j gitlab_t gitlab_json)
(libraries cohttp-lwt uri yojson atdgen))
(libraries cohttp-lwt uri yojson atdgen str))
6 changes: 3 additions & 3 deletions lib/gitlab.atd
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ type issue = {
iid: int;
last_edited_at: string nullable;
last_edited_by_id: int nullable;
milestone_id: string nullable;
milestone_id: int nullable;
moved_to_id: string nullable;
duplicated_to_id: int nullable;
project_id: int;
Expand Down Expand Up @@ -567,7 +567,7 @@ type merge_request_attributes = {
merge_status: merge_status;
merge_user_id: int nullable;
merge_when_pipeline_succeeds: bool;
milestone_id: string nullable;
milestone_id: int nullable;
source: project_webhook;
source_branch: string;
source_project_id: int;
Expand Down Expand Up @@ -697,7 +697,7 @@ type issue_attributes = {
labels: string list;
last_edited_at: string nullable;
last_edited_by_id: int nullable;
milestone_id: string nullable;
milestone_id: int nullable;
moved_to_id: int nullable;
project_id: int;
relative_position: int;
Expand Down
14 changes: 11 additions & 3 deletions lib/gitlab_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,14 @@ struct
module URI = struct
let api = Env.gitlab_uri

let authorize = Uri.of_string (Printf.sprintf "%s/oauth/authorize" api)
let replace input output =
Str.global_replace (Str.regexp_string input) output

let token = Uri.of_string (Printf.sprintf "%s/oauth/token" api)
let authorize =
(* IF we're given an API URL replace the api v4 part. *)
Uri.of_string (Printf.sprintf "%s/oauth/authorize" (replace "api/v4" "" api))

let token = Uri.of_string (Printf.sprintf "%s/oauth/token" (replace "api/v4" "" api))

let events = Uri.of_string (Printf.sprintf "%s/events" api)

Expand Down Expand Up @@ -436,6 +441,7 @@ struct
"code", code;
]
in
log "Requesting %s" (Uri.to_string uri);
CL.post uri >>= fun (_res, body) ->
CLB.to_string body >>= fun body ->
try
Expand All @@ -447,7 +453,9 @@ struct
}
in
return (Some (OAuthToken oauth))
with _ -> return None
with exn ->
log "Token.of_code body: %s exn: %s" body (Printexc.to_string exn);
return None

let of_string s = AccessToken s

Expand Down
Loading