File tree Expand file tree Collapse file tree 4 files changed +34
-12
lines changed
lib/opencov/services/github Expand file tree Collapse file tree 4 files changed +34
-12
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,8 @@ config :event_bus,
6666config :librecov , :github ,
6767 app_id: System . get_env ( "GITHUB_APP_ID" ) ,
6868 client_id: System . get_env ( "GITHUB_CLIENT_ID" ) ,
69- client_secret: System . get_env ( "GITHUB_CLIENT_SECRET" )
69+ client_secret: System . get_env ( "GITHUB_CLIENT_SECRET" ) ,
70+ app_name: System . get_env ( "GITHUB_APP_NAME" )
7071
7172config :ueberauth , Ueberauth.Strategy.Github.OAuth ,
7273 client_id: System . get_env ( "GITHUB_CLIENT_ID" ) ,
Original file line number Diff line number Diff line change 11defmodule Librecov.Services.Github.Auth do
2+ import Librecov.Services.Github.Config
23 alias ExOctocat.Connection
34 alias ExOctocat.Api.Apps
45 alias ExOctocat.Model.Installation
@@ -102,12 +103,4 @@ defmodule Librecov.Services.Github.Auth do
102103 )
103104 |> OAuth2.Client . put_serializer ( "application/json" , Jason )
104105 end
105-
106- defp config do
107- Application . get_env ( :librecov , :github , [ ] )
108- end
109-
110- defp github_app_id , do: config ( ) |> Keyword . get ( :app_id , "" )
111- defp github_client_id , do: config ( ) |> Keyword . get ( :client_id , "" )
112- defp github_client_secret , do: config ( ) |> Keyword . get ( :client_secret , "" )
113106end
Original file line number Diff line number Diff line change 11defmodule Librecov.Services.Github.Comments do
22 require Logger
3+ import Librecov.Services.Github.Config
34 alias ExOctocat.Connection
45 alias ExOctocat.Api.Issues
56 alias Librecov.Services.Github.PullRequests
@@ -51,10 +52,27 @@ defmodule Librecov.Services.Github.Comments do
5152 } ) do
5253 Logger . info ( "Sending pr_message to #{ owner } /#{ repo } ##{ issue_number } ." )
5354
55+ conn = token |> Connection . new ( )
56+
57+ { :ok , messages } =
58+ existing_messages =
59+ conn |> Issues . issues_list_comments ( owner , repo , issue_number , per_page: 100 )
60+
61+ existing_message =
62+ messages |> Enum . find ( fn m -> m . user . login == "#{ github_app_name ( ) } [bot]" end )
63+
64+ IO . inspect ( existing_message )
65+
5466 { :ok , % { id: id } = comment } =
55- token
56- |> Connection . new ( )
57- |> Issues . issues_create_comment ( owner , repo , issue_number , body: % { body: pr_message } )
67+ if is_nil ( existing_message ) do
68+ conn
69+ |> Issues . issues_create_comment ( owner , repo , issue_number , body: % { body: pr_message } )
70+ else
71+ conn
72+ |> Issues . issues_update_comment ( owner , repo , existing_message . id ,
73+ body: % { body: pr_message }
74+ )
75+ end
5876
5977 Logger . info (
6078 "Succesfully sent message to #{ owner } /#{ repo } ##{ issue_number } . IssueComment##{ id } "
Original file line number Diff line number Diff line change 1+ defmodule Librecov.Services.Github.Config do
2+ def config do
3+ Application . get_env ( :librecov , :github , [ ] )
4+ end
5+
6+ def github_app_id , do: config ( ) |> Keyword . get ( :app_id , "" )
7+ def github_client_id , do: config ( ) |> Keyword . get ( :client_id , "" )
8+ def github_client_secret , do: config ( ) |> Keyword . get ( :client_secret , "" )
9+ def github_app_name , do: config ( ) |> Keyword . get ( :app_name , "" )
10+ end
You can’t perform that action at this time.
0 commit comments