From 34ddcb349efd36facb27440444aae4fd1c2e3f28 Mon Sep 17 00:00:00 2001 From: HoffsMH Date: Fri, 17 May 2019 17:55:27 -0500 Subject: [PATCH 1/8] converge on a single spelling of reusable --- lib/slax/commands/github_commands.ex | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/slax/commands/github_commands.ex b/lib/slax/commands/github_commands.ex index a7ea26e..9842cbd 100644 --- a/lib/slax/commands/github_commands.ex +++ b/lib/slax/commands/github_commands.ex @@ -10,7 +10,7 @@ defmodule Slax.Commands.GithubCommands do :slack_channel, :lintron, :board_checker, - :resuseable_stories + :reusable_stories ] alias Slax.{Github} @@ -53,7 +53,7 @@ defmodule Slax.Commands.GithubCommands do Enum.map(errors, fn {:error, path, message} -> "#{path}: #{message}" end) |> Enum.join("\n") - Map.update(results, :errors, %{}, fn x -> Map.put(x, :resuseable_stories, errors) end) + Map.update(results, :errors, %{}, fn x -> Map.put(x, :reusable_stories, errors) end) else results end @@ -62,7 +62,7 @@ defmodule Slax.Commands.GithubCommands do if length(issue_ids) > 0 do Map.put(results, :reusable_stories, true) |> Map.update(:success, %{}, fn x -> - Map.put(x, :resuseable_stories, "Reuseable Stories Created") + Map.put(x, :reusable_stories, "Reuseable Stories Created") end) else results @@ -186,8 +186,8 @@ defmodule Slax.Commands.GithubCommands do :board_checker -> "Board Checker" - :resuseable_stories -> - "Reuseable Stories" + :reusable_stories -> + "Reusable Stories" _ -> "" From 02178cd2f7086ca4a9d922918f9d2ec6f3beaed3 Mon Sep 17 00:00:00 2001 From: HoffsMH Date: Fri, 17 May 2019 18:26:59 -0500 Subject: [PATCH 2/8] testing for github commands including error stats when various requests fail or formatting is incorrect --- lib/slax/commands/github_commands.ex | 6 +- test/slax/commands/github_commands_test.exs | 288 ++++++++++++++++++++ 2 files changed, 291 insertions(+), 3 deletions(-) create mode 100644 test/slax/commands/github_commands_test.exs diff --git a/lib/slax/commands/github_commands.ex b/lib/slax/commands/github_commands.ex index 9842cbd..5a089e2 100644 --- a/lib/slax/commands/github_commands.ex +++ b/lib/slax/commands/github_commands.ex @@ -71,7 +71,7 @@ defmodule Slax.Commands.GithubCommands do results {:error, message} -> - Map.update(results, :errors, %{}, fn x -> Map.put(x, :resuseable_stories, message) end) + Map.update(results, :errors, %{}, fn x -> Map.put(x, :reusable_stories, message) end) end end @@ -102,7 +102,7 @@ defmodule Slax.Commands.GithubCommands do blobs |> Enum.map(fn {:ok, path, content} -> with {:ok, issue} <- Base.decode64(content |> String.replace("\n", "")), - {:ok, front_matter, body} <- YamlFrontMatter.parse(issue) do + {:ok, {:ok, front_matter}, body} <- YamlFrontMatter.parse(issue) do {:ok, path, front_matter, body} else :error -> @@ -139,7 +139,7 @@ defmodule Slax.Commands.GithubCommands do end) |> Enum.split_with(fn {:ok, _, _} -> true - {:error, _} -> false + {:error, _,_} -> false end) end diff --git a/test/slax/commands/github_commands_test.exs b/test/slax/commands/github_commands_test.exs new file mode 100644 index 0000000..510fe7a --- /dev/null +++ b/test/slax/commands/github_commands_test.exs @@ -0,0 +1,288 @@ +defmodule Slax.GithubCommands.Test do + use Slax.ModelCase, async: true + alias Slax.Commands.GithubCommands + import Mox + + test "format_issues/1" do + assert GithubCommands.format_issues([ + %{ + "title" => "title", + "updated_at" => "2019-04-18T14:08:35Z", + "labels" => [%{"name" => "in progress"}] + } + ]) =~ "Last Updated at" + end + + describe "parse_project_name/2" do + def setup_starting_result(context) do + {:ok, + context + |> Map.put(:starting_result, %{errors: %{}, success: %{}})} + end + + setup :setup_starting_result + + test "invalid characters", %{starting_result: starting_result} do + with result <- GithubCommands.parse_project_name(starting_result, "hi&") do + assert Map.get(result, :errors) == %{project_name: "Invalid Project Name"} + assert Map.get(result, :project_name) == nil + end + end + + test "too many characters", %{starting_result: starting_result} do + with result <- + GithubCommands.parse_project_name( + starting_result, + "thisshouldbemorethantwentytwocharacters" + ) do + assert Map.get(result, :errors) == %{project_name: "Invalid Project Name"} + assert Map.get(result, :project_name) == nil + end + end + + test "valid_input", %{starting_result: starting_result} do + with result <- GithubCommands.parse_project_name(starting_result, "valid_repo_name") do + assert Map.get(result, :errors) == %{} + assert Map.get(result, :success) == %{project_name: "Project Name Parsed"} + assert Map.get(result, :project_name) == "valid_repo_name" + end + end + end + + def setup_starting_result_with_name(context) do + {:ok, + context + |> Map.put(:starting_result, %{errors: %{}, success: %{}}) + |> put_in([:starting_result, :success, :project_name], "Project Name Parsed") + |> put_in([:starting_result, :project_name], "valid_project_name")} + end + + def setup_successful_tree_requests(context) do + {:ok, + context + |> Map.put(:starting_result, %{errors: %{}, success: %{}}) + |> put_in([:starting_result, :success, :project_name], "Project Name Parsed") + |> put_in([:starting_result, :project_name], "valid_project_name")} + end + + def successful_tree_request(_, _, _) do + {:ok, + %HTTPoison.Response{ + status_code: 200, + body: ~s<{ + "tree": [ + { + "path": "story_path1.md", + "sha": "test_sha", + "type": "blob" + }, + { + "path": "story_path3.md", + "sha": "test_sha", + "type": "blob" + } + + ] + }> + }} + end + + def successful_blob_request(_, _, _) do + {:ok, + %HTTPoison.Response{ + status_code: 200, + body: ~s<{ + "content": "LS0tCnRpdGxlOiB0ZXN0X3RpdGxlCi0tLQp0ZXN0IGNvbnRlbnQK" + }> + }} + end + + def successful_issue_request(_,_,_,_) do + {:ok, + %HTTPoison.Response{ + status_code: 200, + body: ~s<{ + "content": ["1"] + }> + }} + end + + + describe "create_reusable_stories/5" do + setup [:setup_starting_result_with_name] + + test "when all requests are successful", %{starting_result: starting_result} do + expect(Slax.HttpMock, :get, 1, &successful_tree_request/3) + expect(Slax.HttpMock, :get, 2, &successful_blob_request/3) + expect(Slax.HttpMock, :post, 3, &successful_issue_request/4) + + result = + GithubCommands.create_reusable_stories( + starting_result, + "access_token", + "test_org", + "story_repo", + path1: "story_path1", + path3: "story_path3" + ) + + assert result[:errors] == %{} + assert result[:project_name] == "valid_project_name" + assert result[:reusable_stories] == true + assert result[:success][:reusable_stories] == "Reuseable Stories Created" + end + + def failing_request(_,_,_) do + {:ok, + %HTTPoison.Response{ + status_code: 400, + body: ~s<{ + "message": "you done goofed" + }> + }} + end + def failing_request(w,x,y,_), do: failing_request(w,x,y) + + test "when fetching the project tree fails", %{starting_result: starting_result} do + expect(Slax.HttpMock, :get, 1, &failing_request/3) + + result = + GithubCommands.create_reusable_stories( + starting_result, + "access_token", + "test_org", + "story_repo", + path1: "story_path1", + path3: "story_path3" + ) + + assert result[:reusable_stories] == nil + assert result[:errors] == %{reusable_stories: "you done goofed"} + assert result[:project_name] == "valid_project_name" + assert result[:success] == %{project_name: "Project Name Parsed"} + end + + test "when fetching a blob fails", %{starting_result: starting_result} do + expect(Slax.HttpMock, :get, 1, &successful_tree_request/3) + expect(Slax.HttpMock, :get, 2, &failing_request/3) + + result = + GithubCommands.create_reusable_stories( + starting_result, + "access_token", + "test_org", + "story_repo", + path1: "story_path1", + path3: "story_path3" + ) + + assert result[:reusable_stories] == nil + + assert result[:errors] == %{ + reusable_stories: + "story_path1.md: you done goofed\nstory_path3.md: you done goofed" + } + + assert result[:project_name] == "valid_project_name" + assert result[:success] == %{project_name: "Project Name Parsed"} + end + + test "when posting issues fails", %{starting_result: starting_result} do + expect(Slax.HttpMock, :get, 1, &successful_tree_request/3) + expect(Slax.HttpMock, :get, 2, &successful_blob_request/3) + expect(Slax.HttpMock, :post, 3, &failing_request/4) + + result = + GithubCommands.create_reusable_stories( + starting_result, + "access_token", + "test_org", + "story_repo", + path1: "story_path1", + path3: "story_path3" + ) + + assert result[:reusable_stories] == nil + + assert result[:errors] == %{ + reusable_stories: + "story_path1.md: you done goofed\nstory_path3.md: you done goofed" + } + + assert result[:project_name] == "valid_project_name" + assert result[:success] == %{project_name: "Project Name Parsed"} + end + + def invalid_blob_request(_,_,_) do + {:ok, + %HTTPoison.Response{ + status_code: 200, + body: ~s<{ + "content": "invalidblob" + }> + }} + end + + test "when decoding a blob fails", %{starting_result: starting_result} do + expect(Slax.HttpMock, :get, 1, &successful_tree_request/3) + expect(Slax.HttpMock, :get, 2, &invalid_blob_request/3) + expect(Slax.HttpMock, :post, 3, &successful_issue_request/4) + + result = + GithubCommands.create_reusable_stories( + starting_result, + "access_token", + "test_org", + "story_repo", + path1: "story_path1", + path3: "story_path3" + ) + + assert result[:reusable_stories] == nil + + assert result[:errors] == %{ + reusable_stories: + "story_path1.md: Unable to parse content\nstory_path3.md: Unable to parse content" + } + + assert result[:project_name] == "valid_project_name" + assert result[:success] == %{project_name: "Project Name Parsed"} + end + + def invalid_frontmatter_request(_,_,_) do + {:ok, + %HTTPoison.Response{ + status_code: 200, + body: ~s<{ + "content": "LS0KaW52YWxpZCBmcm9udG1hdHRlcgpfCm9vcHMK" + }> + }} + end + + test "when parsing issue frontmatter fails", %{starting_result: starting_result} do + expect(Slax.HttpMock, :get, 1, &successful_tree_request/3) + expect(Slax.HttpMock, :get, 2, &invalid_frontmatter_request/3) + expect(Slax.HttpMock, :post, 3, &successful_issue_request/4) + + result = + GithubCommands.create_reusable_stories( + starting_result, + "access_token", + "test_org", + "story_repo", + path1: "story_path1", + path3: "story_path3" + ) + + assert result[:reusable_stories] == nil + + assert result[:errors] == %{ + reusable_stories: + "story_path1.md: invalid_front_matter\nstory_path3.md: invalid_front_matter" + } + + assert result[:project_name] == "valid_project_name" + assert result[:success] == %{project_name: "Project Name Parsed"} + end + end +end From 003ec50afe9acdbc59699ae3c8393149c38bec65 Mon Sep 17 00:00:00 2001 From: HoffsMH Date: Fri, 17 May 2019 20:14:52 -0500 Subject: [PATCH 3/8] testing format_results/1 and format_issues/1 --- test/slax/commands/github_commands_test.exs | 112 ++++++++++++++------ 1 file changed, 81 insertions(+), 31 deletions(-) diff --git a/test/slax/commands/github_commands_test.exs b/test/slax/commands/github_commands_test.exs index 510fe7a..c709cc9 100644 --- a/test/slax/commands/github_commands_test.exs +++ b/test/slax/commands/github_commands_test.exs @@ -3,14 +3,72 @@ defmodule Slax.GithubCommands.Test do alias Slax.Commands.GithubCommands import Mox - test "format_issues/1" do - assert GithubCommands.format_issues([ - %{ - "title" => "title", - "updated_at" => "2019-04-18T14:08:35Z", - "labels" => [%{"name" => "in progress"}] - } - ]) =~ "Last Updated at" + describe "format_issues/1" do + test "when there is an 'in progress' label" do + assert GithubCommands.format_issues([ + %{ + "title" => "title", + "updated_at" => "2019-04-18T14:08:35Z", + "labels" => [%{"name" => "in progress"}] + } + ]) =~ "Last Updated at" + end + + test "when there is not an 'in progress' label" do + assert GithubCommands.format_issues([ + %{ + "title" => "title", + "updated_at" => "2019-04-18T14:08:35Z", + "labels" => [%{"name" => "back log"}] + } + ]) =~ ":snail: *Issues In Progress for 5/18* :snail: \n" + end + end + + describe "format_results/1" do + setup :setup_no_errors + + def setup_no_errors(context) do + {:ok, + context + |> Map.put(:starting_result, %{ + project_name: true, + github_repo: true, + slack_channel: true, + errors: %{}, + success: %{ + project_name: "project_name", + github_repo: "org_name/project_name", + slack_channel: "slack_channel" + } + })} + end + + test "when there are no errors for any steps", %{starting_result: starting_result} do + result = GithubCommands.format_results(starting_result) + + assert result == + "Project Name: project_name\nGithub: org_name/project_name\nGithub Teams: \nSlack: slack_channel\nLintron: \nBoard Checker: \nReusable Stories: " + end + + test "when there are errors for certain steps" do + starting_result = %{ + project_name: true, + github_repo: true, + errors: %{ + slack_channel: "slack_channel error" + }, + success: %{ + project_name: "project_name", + github_repo: "org_name/project_name" + } + } + + result = GithubCommands.format_results(starting_result) + + assert result == + "Project Name: project_name\nGithub: org_name/project_name\nGithub Teams: \nSlack: slack_channel error\nLintron: \nBoard Checker: \nReusable Stories: " + end end describe "parse_project_name/2" do @@ -57,14 +115,6 @@ defmodule Slax.GithubCommands.Test do |> put_in([:starting_result, :project_name], "valid_project_name")} end - def setup_successful_tree_requests(context) do - {:ok, - context - |> Map.put(:starting_result, %{errors: %{}, success: %{}}) - |> put_in([:starting_result, :success, :project_name], "Project Name Parsed") - |> put_in([:starting_result, :project_name], "valid_project_name")} - end - def successful_tree_request(_, _, _) do {:ok, %HTTPoison.Response{ @@ -97,7 +147,7 @@ defmodule Slax.GithubCommands.Test do }} end - def successful_issue_request(_,_,_,_) do + def successful_issue_request(_, _, _, _) do {:ok, %HTTPoison.Response{ status_code: 200, @@ -107,7 +157,6 @@ defmodule Slax.GithubCommands.Test do }} end - describe "create_reusable_stories/5" do setup [:setup_starting_result_with_name] @@ -132,7 +181,7 @@ defmodule Slax.GithubCommands.Test do assert result[:success][:reusable_stories] == "Reuseable Stories Created" end - def failing_request(_,_,_) do + def failing_request(_, _, _) do {:ok, %HTTPoison.Response{ status_code: 400, @@ -141,7 +190,8 @@ defmodule Slax.GithubCommands.Test do }> }} end - def failing_request(w,x,y,_), do: failing_request(w,x,y) + + def failing_request(w, x, y, _), do: failing_request(w, x, y) test "when fetching the project tree fails", %{starting_result: starting_result} do expect(Slax.HttpMock, :get, 1, &failing_request/3) @@ -205,15 +255,15 @@ defmodule Slax.GithubCommands.Test do assert result[:reusable_stories] == nil assert result[:errors] == %{ - reusable_stories: - "story_path1.md: you done goofed\nstory_path3.md: you done goofed" - } + reusable_stories: + "story_path1.md: you done goofed\nstory_path3.md: you done goofed" + } assert result[:project_name] == "valid_project_name" assert result[:success] == %{project_name: "Project Name Parsed"} end - def invalid_blob_request(_,_,_) do + def invalid_blob_request(_, _, _) do {:ok, %HTTPoison.Response{ status_code: 200, @@ -241,15 +291,15 @@ defmodule Slax.GithubCommands.Test do assert result[:reusable_stories] == nil assert result[:errors] == %{ - reusable_stories: - "story_path1.md: Unable to parse content\nstory_path3.md: Unable to parse content" - } + reusable_stories: + "story_path1.md: Unable to parse content\nstory_path3.md: Unable to parse content" + } assert result[:project_name] == "valid_project_name" assert result[:success] == %{project_name: "Project Name Parsed"} end - def invalid_frontmatter_request(_,_,_) do + def invalid_frontmatter_request(_, _, _) do {:ok, %HTTPoison.Response{ status_code: 200, @@ -277,9 +327,9 @@ defmodule Slax.GithubCommands.Test do assert result[:reusable_stories] == nil assert result[:errors] == %{ - reusable_stories: - "story_path1.md: invalid_front_matter\nstory_path3.md: invalid_front_matter" - } + reusable_stories: + "story_path1.md: invalid_front_matter\nstory_path3.md: invalid_front_matter" + } assert result[:project_name] == "valid_project_name" assert result[:success] == %{project_name: "Project Name Parsed"} From 3b5cb554be28fe16ba96d297567466547395312b Mon Sep 17 00:00:00 2001 From: HoffsMH Date: Fri, 17 May 2019 20:35:21 -0500 Subject: [PATCH 4/8] add some documentation for the public functions --- lib/slax/commands/github_commands.ex | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/slax/commands/github_commands.ex b/lib/slax/commands/github_commands.ex index 5a089e2..6e65910 100644 --- a/lib/slax/commands/github_commands.ex +++ b/lib/slax/commands/github_commands.ex @@ -15,6 +15,12 @@ defmodule Slax.Commands.GithubCommands do alias Slax.{Github} + @doc """ + Accepts a results map and the potential name of a new github repo. + If the name is a valid github repo name, it will return a new result map + containing the `project_name` as well as a key indicating that the `project_name` + step is complete + """ def parse_project_name(results, text) do case Regex.run(~r/^[a-zA-Z0-9\-_]{3,21}$/, text) do [project_name] -> @@ -28,6 +34,10 @@ defmodule Slax.Commands.GithubCommands do end end + @doc """ + Pulls all issue templates from a story repo that are included in `story_paths`. + It then uses these templates to create issues in a newly created github repository, + """ def create_reusable_stories( %{project_name: project_name} = results, github_access_token, From 56cb0c1e85d3f24963d348087a2d332b2e25a07d Mon Sep 17 00:00:00 2001 From: HoffsMH Date: Sat, 18 May 2019 11:44:22 -0500 Subject: [PATCH 5/8] use @subject pattern to make it easier to shuffle around these functions or change module names when refactoring --- test/slax/commands/github_commands_test.exs | 28 ++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/slax/commands/github_commands_test.exs b/test/slax/commands/github_commands_test.exs index c709cc9..2b67fcf 100644 --- a/test/slax/commands/github_commands_test.exs +++ b/test/slax/commands/github_commands_test.exs @@ -1,11 +1,11 @@ defmodule Slax.GithubCommands.Test do use Slax.ModelCase, async: true - alias Slax.Commands.GithubCommands import Mox + @subject Slax.Commands.GithubCommands describe "format_issues/1" do test "when there is an 'in progress' label" do - assert GithubCommands.format_issues([ + assert @subject.format_issues([ %{ "title" => "title", "updated_at" => "2019-04-18T14:08:35Z", @@ -15,7 +15,7 @@ defmodule Slax.GithubCommands.Test do end test "when there is not an 'in progress' label" do - assert GithubCommands.format_issues([ + assert @subject.format_issues([ %{ "title" => "title", "updated_at" => "2019-04-18T14:08:35Z", @@ -45,7 +45,7 @@ defmodule Slax.GithubCommands.Test do end test "when there are no errors for any steps", %{starting_result: starting_result} do - result = GithubCommands.format_results(starting_result) + result = @subject.format_results(starting_result) assert result == "Project Name: project_name\nGithub: org_name/project_name\nGithub Teams: \nSlack: slack_channel\nLintron: \nBoard Checker: \nReusable Stories: " @@ -64,7 +64,7 @@ defmodule Slax.GithubCommands.Test do } } - result = GithubCommands.format_results(starting_result) + result = @subject.format_results(starting_result) assert result == "Project Name: project_name\nGithub: org_name/project_name\nGithub Teams: \nSlack: slack_channel error\nLintron: \nBoard Checker: \nReusable Stories: " @@ -81,7 +81,7 @@ defmodule Slax.GithubCommands.Test do setup :setup_starting_result test "invalid characters", %{starting_result: starting_result} do - with result <- GithubCommands.parse_project_name(starting_result, "hi&") do + with result <- @subject.parse_project_name(starting_result, "hi&") do assert Map.get(result, :errors) == %{project_name: "Invalid Project Name"} assert Map.get(result, :project_name) == nil end @@ -89,7 +89,7 @@ defmodule Slax.GithubCommands.Test do test "too many characters", %{starting_result: starting_result} do with result <- - GithubCommands.parse_project_name( + @subject.parse_project_name( starting_result, "thisshouldbemorethantwentytwocharacters" ) do @@ -99,7 +99,7 @@ defmodule Slax.GithubCommands.Test do end test "valid_input", %{starting_result: starting_result} do - with result <- GithubCommands.parse_project_name(starting_result, "valid_repo_name") do + with result <- @subject.parse_project_name(starting_result, "valid_repo_name") do assert Map.get(result, :errors) == %{} assert Map.get(result, :success) == %{project_name: "Project Name Parsed"} assert Map.get(result, :project_name) == "valid_repo_name" @@ -166,7 +166,7 @@ defmodule Slax.GithubCommands.Test do expect(Slax.HttpMock, :post, 3, &successful_issue_request/4) result = - GithubCommands.create_reusable_stories( + @subject.create_reusable_stories( starting_result, "access_token", "test_org", @@ -197,7 +197,7 @@ defmodule Slax.GithubCommands.Test do expect(Slax.HttpMock, :get, 1, &failing_request/3) result = - GithubCommands.create_reusable_stories( + @subject.create_reusable_stories( starting_result, "access_token", "test_org", @@ -217,7 +217,7 @@ defmodule Slax.GithubCommands.Test do expect(Slax.HttpMock, :get, 2, &failing_request/3) result = - GithubCommands.create_reusable_stories( + @subject.create_reusable_stories( starting_result, "access_token", "test_org", @@ -243,7 +243,7 @@ defmodule Slax.GithubCommands.Test do expect(Slax.HttpMock, :post, 3, &failing_request/4) result = - GithubCommands.create_reusable_stories( + @subject.create_reusable_stories( starting_result, "access_token", "test_org", @@ -279,7 +279,7 @@ defmodule Slax.GithubCommands.Test do expect(Slax.HttpMock, :post, 3, &successful_issue_request/4) result = - GithubCommands.create_reusable_stories( + @subject.create_reusable_stories( starting_result, "access_token", "test_org", @@ -315,7 +315,7 @@ defmodule Slax.GithubCommands.Test do expect(Slax.HttpMock, :post, 3, &successful_issue_request/4) result = - GithubCommands.create_reusable_stories( + @subject.create_reusable_stories( starting_result, "access_token", "test_org", From 2b350aa8419488625fe51554de7cd4c31095cae3 Mon Sep 17 00:00:00 2001 From: HoffsMH Date: Sun, 19 May 2019 14:17:44 -0500 Subject: [PATCH 6/8] adjust for bug wherein a result set could be passed to create_reusable_stories and the result set doesnt include a github repo, which means that even if we were to parse out the story issues correctly there would be nothing to send them to. a github repo should be a hard requirement for this step --- lib/slax/commands/github_commands.ex | 7 +- test/slax/commands/github_commands_test.exs | 109 ++++++++++++++------ 2 files changed, 82 insertions(+), 34 deletions(-) diff --git a/lib/slax/commands/github_commands.ex b/lib/slax/commands/github_commands.ex index 6e65910..f1c4321 100644 --- a/lib/slax/commands/github_commands.ex +++ b/lib/slax/commands/github_commands.ex @@ -37,9 +37,10 @@ defmodule Slax.Commands.GithubCommands do @doc """ Pulls all issue templates from a story repo that are included in `story_paths`. It then uses these templates to create issues in a newly created github repository, + If there is no github repository the function will exit early """ def create_reusable_stories( - %{project_name: project_name} = results, + %{project_name: project_name, github_repo: _} = results, github_access_token, org_name, story_repo, @@ -85,6 +86,8 @@ defmodule Slax.Commands.GithubCommands do end end + def create_reusable_stories(results, _, _, _, _), do: results + defp process_tree(data, story_repo, story_paths, github_access_token) do Map.get(data, "tree", []) |> Enum.filter(fn x -> x["type"] == "blob" && String.ends_with?(x["path"], ".md") end) @@ -149,7 +152,7 @@ defmodule Slax.Commands.GithubCommands do end) |> Enum.split_with(fn {:ok, _, _} -> true - {:error, _,_} -> false + {:error, _, _} -> false end) end diff --git a/test/slax/commands/github_commands_test.exs b/test/slax/commands/github_commands_test.exs index 2b67fcf..5d5d63d 100644 --- a/test/slax/commands/github_commands_test.exs +++ b/test/slax/commands/github_commands_test.exs @@ -112,7 +112,10 @@ defmodule Slax.GithubCommands.Test do context |> Map.put(:starting_result, %{errors: %{}, success: %{}}) |> put_in([:starting_result, :success, :project_name], "Project Name Parsed") - |> put_in([:starting_result, :project_name], "valid_project_name")} + |> put_in([:starting_result, :project_name], "valid_project_name") + |> put_in([:starting_result, :github_repo], "repo_url") + |> put_in([:starting_result, :success, :github_repo], "Github Repo Found or Created: ") + } end def successful_tree_request(_, _, _) do @@ -177,8 +180,13 @@ defmodule Slax.GithubCommands.Test do assert result[:errors] == %{} assert result[:project_name] == "valid_project_name" + assert result[:github_repo] == "repo_url" assert result[:reusable_stories] == true - assert result[:success][:reusable_stories] == "Reuseable Stories Created" + assert result[:success] == %{ + project_name: "Project Name Parsed", + reusable_stories: "Reuseable Stories Created", + github_repo: "Github Repo Found or Created: " + } end def failing_request(_, _, _) do @@ -191,6 +199,29 @@ defmodule Slax.GithubCommands.Test do }} end + test "when the starting results dont have a github repo" do + starting_result = + %{ + project_name: "valid_project_name", + errors: %{}, + success: %{ + project_name: "Project Name Parsed" + } + } + + result = + @subject.create_reusable_stories( + starting_result, + "access_token", + "test_org", + "story_repo", + path1: "story_path1", + path3: "story_path3" + ) + + assert result == starting_result + end + def failing_request(w, x, y, _), do: failing_request(w, x, y) test "when fetching the project tree fails", %{starting_result: starting_result} do @@ -206,10 +237,14 @@ defmodule Slax.GithubCommands.Test do path3: "story_path3" ) - assert result[:reusable_stories] == nil assert result[:errors] == %{reusable_stories: "you done goofed"} assert result[:project_name] == "valid_project_name" - assert result[:success] == %{project_name: "Project Name Parsed"} + assert result[:github_repo] == "repo_url" + assert result[:reusable_stories] == nil + assert result[:success] == %{ + project_name: "Project Name Parsed", + github_repo: "Github Repo Found or Created: " + } end test "when fetching a blob fails", %{starting_result: starting_result} do @@ -226,15 +261,18 @@ defmodule Slax.GithubCommands.Test do path3: "story_path3" ) - assert result[:reusable_stories] == nil - assert result[:errors] == %{ - reusable_stories: - "story_path1.md: you done goofed\nstory_path3.md: you done goofed" - } - + reusable_stories: + "story_path1.md: you done goofed\nstory_path3.md: you done goofed" + } assert result[:project_name] == "valid_project_name" - assert result[:success] == %{project_name: "Project Name Parsed"} + assert result[:github_repo] == "repo_url" + assert result[:reusable_stories] == nil + assert result[:success] == %{ + project_name: "Project Name Parsed", + github_repo: "Github Repo Found or Created: " + } + end test "when posting issues fails", %{starting_result: starting_result} do @@ -252,15 +290,18 @@ defmodule Slax.GithubCommands.Test do path3: "story_path3" ) - assert result[:reusable_stories] == nil - assert result[:errors] == %{ - reusable_stories: - "story_path1.md: you done goofed\nstory_path3.md: you done goofed" - } - + reusable_stories: + "story_path1.md: you done goofed\nstory_path3.md: you done goofed" + } assert result[:project_name] == "valid_project_name" - assert result[:success] == %{project_name: "Project Name Parsed"} + assert result[:github_repo] == "repo_url" + assert result[:reusable_stories] == nil + assert result[:success] == %{ + project_name: "Project Name Parsed", + github_repo: "Github Repo Found or Created: " + } + end def invalid_blob_request(_, _, _) do @@ -288,15 +329,17 @@ defmodule Slax.GithubCommands.Test do path3: "story_path3" ) - assert result[:reusable_stories] == nil - assert result[:errors] == %{ - reusable_stories: - "story_path1.md: Unable to parse content\nstory_path3.md: Unable to parse content" - } - + reusable_stories: + "story_path1.md: Unable to parse content\nstory_path3.md: Unable to parse content" + } assert result[:project_name] == "valid_project_name" - assert result[:success] == %{project_name: "Project Name Parsed"} + assert result[:github_repo] == "repo_url" + assert result[:reusable_stories] == nil + assert result[:success] == %{ + project_name: "Project Name Parsed", + github_repo: "Github Repo Found or Created: " + } end def invalid_frontmatter_request(_, _, _) do @@ -324,15 +367,17 @@ defmodule Slax.GithubCommands.Test do path3: "story_path3" ) - assert result[:reusable_stories] == nil - assert result[:errors] == %{ - reusable_stories: - "story_path1.md: invalid_front_matter\nstory_path3.md: invalid_front_matter" - } - + reusable_stories: + "story_path1.md: invalid_front_matter\nstory_path3.md: invalid_front_matter" + } assert result[:project_name] == "valid_project_name" - assert result[:success] == %{project_name: "Project Name Parsed"} + assert result[:github_repo] == "repo_url" + assert result[:reusable_stories] == nil + assert result[:success] == %{ + project_name: "Project Name Parsed", + github_repo: "Github Repo Found or Created: " + } end end end From 1eba86ac684fea83e27b8b75da687d92cc99abd1 Mon Sep 17 00:00:00 2001 From: HoffsMH Date: Sun, 19 May 2019 14:18:08 -0500 Subject: [PATCH 7/8] fix test to be date agnostic --- test/slax/commands/github_commands_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/slax/commands/github_commands_test.exs b/test/slax/commands/github_commands_test.exs index 5d5d63d..b7b97e5 100644 --- a/test/slax/commands/github_commands_test.exs +++ b/test/slax/commands/github_commands_test.exs @@ -21,7 +21,7 @@ defmodule Slax.GithubCommands.Test do "updated_at" => "2019-04-18T14:08:35Z", "labels" => [%{"name" => "back log"}] } - ]) =~ ":snail: *Issues In Progress for 5/18* :snail: \n" + ]) =~ ":snail: *Issues In Progress for" end end From e9863f19dd92680e1b8f7adf528d207d33a74f12 Mon Sep 17 00:00:00 2001 From: HoffsMH Date: Fri, 24 May 2019 10:35:52 -0500 Subject: [PATCH 8/8] get rid of no longer needed test for GithubCommands.format_issues/1 --- test/slax/commands/github_commands_test.exs | 22 --------------------- 1 file changed, 22 deletions(-) diff --git a/test/slax/commands/github_commands_test.exs b/test/slax/commands/github_commands_test.exs index b7b97e5..0c30451 100644 --- a/test/slax/commands/github_commands_test.exs +++ b/test/slax/commands/github_commands_test.exs @@ -3,28 +3,6 @@ defmodule Slax.GithubCommands.Test do import Mox @subject Slax.Commands.GithubCommands - describe "format_issues/1" do - test "when there is an 'in progress' label" do - assert @subject.format_issues([ - %{ - "title" => "title", - "updated_at" => "2019-04-18T14:08:35Z", - "labels" => [%{"name" => "in progress"}] - } - ]) =~ "Last Updated at" - end - - test "when there is not an 'in progress' label" do - assert @subject.format_issues([ - %{ - "title" => "title", - "updated_at" => "2019-04-18T14:08:35Z", - "labels" => [%{"name" => "back log"}] - } - ]) =~ ":snail: *Issues In Progress for" - end - end - describe "format_results/1" do setup :setup_no_errors