diff --git a/lib/custodian/github/processor.ex b/lib/custodian/github/processor.ex index 51ea2df..b57111e 100644 --- a/lib/custodian/github/processor.ex +++ b/lib/custodian/github/processor.ex @@ -68,6 +68,22 @@ defmodule Custodian.Github.Processor do - Removes all labels """ @spec pr(map) :: {:ok, Bot.t()} + def pr(%{"pull_request" => %{"state" => "open", "draft" => true}} = params) do + Appsignal.increment_counter("event_pr_open_count", 1) + bot = Bots.get_bot_by!(repo_id: params["repository"]["id"]) + + labels = @github.Labels.all({bot, params["pull_request"]["number"]}) + + if !Enum.member?(labels, "ready-to-merge") && !Enum.member?(labels, "needs-review") do + @github.Labels.add( + {bot, params["pull_request"]["number"]}, + "in-progress" + ) + end + + {:ok, bot} + end + def pr(%{"pull_request" => %{"state" => "open"}} = params) do Appsignal.increment_counter("event_pr_open_count", 1) bot = Bots.get_bot_by!(repo_id: params["repository"]["id"]) diff --git a/test/custodian/github/processor_test.exs b/test/custodian/github/processor_test.exs index 634d0be..c1eef63 100644 --- a/test/custodian/github/processor_test.exs +++ b/test/custodian/github/processor_test.exs @@ -96,6 +96,29 @@ defmodule Custodian.Github.ProcessorTest do assert_received {:add, ["needs-review"]} end + test "labels draft pr when opened" do + Bots.create_bot(%{ + repo_id: 1, + owner: "lleger", + name: "gh-api-test", + installation_id: 1 + }) + + params = %{ + "repository" => %{ + "id" => 1 + }, + "pull_request" => %{ + "number" => "open", + "state" => "open", + "draft" => true + } + } + + assert {:ok, bot} = Processor.pr(params) + assert_received {:add, ["in-progress"]} + end + test "labels pr when closed" do Bots.create_bot(%{ repo_id: 1,