Skip to content
This repository has been archived by the owner on Apr 5, 2023. It is now read-only.

Commit

Permalink
Add in-progress labeling for draft PRs when opened
Browse files Browse the repository at this point in the history
Ref #20
  • Loading branch information
lleger committed Feb 18, 2019
1 parent 68c3baf commit dd18798
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/custodian/github/processor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
23 changes: 23 additions & 0 deletions test/custodian/github/processor_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit dd18798

Please sign in to comment.