benoittgt

benoittgt

Hello

I wrote a very simple tool on Elixir to get notified on Slack when someone mention you in and issue on Github.

The project use Plug and I recently added a fix for a specific behavior of the github’s api but I’m not sure about what I did.

The change is small (don’t be scared about the 187 lines it’s the fixture) and simple but I would to get some feedbacks.

https://github.com/benoittgt/PhubMe/pull/16

Feel free to make any comments. I have already shared some doubts on the pull request.

Thanks

Showing Posts 1 to 4

thomasbrus

thomasbrus

Hey!

I have a few comments on web.ex as a whole:

  • web.ex:27 cond can simply be an if/else expression

  • web.ex:50-55 should be possible to split this method using pattern matching (e.g. def valid_github_payload?(%{"issue" => _issue} = body_params, [{"x-github-event", "issue_comment", ...}])),

    You can then have one function definition per case (last one matches on any body_params and simply returns false). This way the function is easier to digest and it’s more obvious what the different scenarios are.

    The function definition might get a bit long if you’re gonna pattern match on the complete request headers, so perhaps an idea is to leave out the {"content-type", "application/json"} part.

I agree about perhaps refactoring the valid_github_payload? function cause it indeed does two things now. Just looking at that function name alone I think it makes sense it either returns true or false (not a tuple).

The request handler could then (when true) invoke handle_github_payload, which sends the private message, or does nothing. Again pattern matching can be used.

Finally, a few subjective remarks:

  • web.ex:15 remove space after _ :yum: . Also I like this style better:
adapter_port = port(System.get_env("PORT")))
{:ok, _} = Plug.Adapters.Cowboy.http(PhubMe.Web, [], adapter_port)
  • web.ex:20 and web.ex:22 would both have them in the same style instead of only one via the , do: shorthand
def port(nil), do: 8080
def port(value), do: String.to_integer(value)

… Actually, I don’t think you need the port method at all, this would do the job as well:

port = (System.get_env("PORT") || "8080") |> String.to_integer
{:ok, _} = Plug.Adapters.Cowboy.http(PhubMe.Web, [], port)
benoittgt

benoittgt OP

Awesome. Thanks a lot Thomas ! Will make the changes now.

Thanks a lot

benoittgt

benoittgt OP

I made the changes : Fix first github call when creating webhook by benoittgt · Pull Request #16 · benoittgt/PhubMe · GitHub

It’s much better now. I see a little bit of duplication between valid_github_payload? and handle_github_payload. But the method are readable.

thomasbrus

thomasbrus

Sure! You’re welcome. It’s not perfect but a good step in the right direction I’d say

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

webofbits
Aludel 0.7.0 is released :tada: Since 0.5.0, Aludel has grown into a much more complete LLM evaluation toolkit for Elixir and Phoenix app...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews