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

Sort patches before creating merge commit #393

Merged
merged 2 commits into from
Apr 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lib/github/github/server_mock.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ defmodule BorsNG.GitHub.ServerMock do
...> ] },
...> {{:installation, 91}, 14} => %{
...> branches: %{},
...> commits: %{},
...> comments: %{1 => []},
...> pulls: %{
...> 1 => %GitHub.Pr{
Expand Down Expand Up @@ -72,10 +73,16 @@ defmodule BorsNG.GitHub.ServerMock do
@type tbranch :: bitstring
@type tcommit :: bitstring

@type tsynthesized :: %{
commit_message: bitstring,
parents: [bitstring]
}

@type tstate :: %{
tconn => %{
branches: %{tbranch => tcommit},
comments: %{integer => [bitstring]},
commits: %{bitstring => tsynthesized},
statuses: %{tbranch => %{bitstring => :open | :closed | :running}},
files: %{tbranch => %{bitstring => bitstring}},
collaborators: [tcollaborator]
Expand Down Expand Up @@ -215,15 +222,20 @@ defmodule BorsNG.GitHub.ServerMock do
branch: branch,
tree: tree,
parents: parents,
commit_message: _commit_message}}, state) do
commit_message: commit_message}}, state) do
with {:ok, repo} <- Map.fetch(state, repo_conn),
{:ok, branches} <- Map.fetch(repo, :branches) do
{:ok, branches} <- Map.fetch(repo, :branches),
{:ok, commits} <- Map.fetch(repo, :commits) do
nsha = parents
|> Enum.reverse()
|> Enum.reduce(&<>/2)
^nsha = tree
commits = Map.put(commits, nsha, %{
parents: parents,
commit_message: commit_message})
branches = Map.put(branches, branch, nsha)
repo = %{repo | branches: branches}
repo = %{repo | commits: commits}
state = %{state | repo_conn => repo}
{{:ok, nsha}, state}
end
Expand Down
1 change: 1 addition & 0 deletions lib/worker/batcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ defmodule BorsNG.Worker.Batcher do
project = batch.project
repo_conn = get_repo_conn(project)
patch_links = Repo.all(LinkPatchBatch.from_batch(batch.id))
|> Enum.sort_by(&(&1.patch.pr_xref))
stmp = "#{project.staging_branch}.tmp"
base = GitHub.get_branch!(
repo_conn,
Expand Down
1 change: 0 additions & 1 deletion lib/worker/batcher/message.ex
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ defmodule BorsNG.Worker.Batcher.Message do
end

def generate_commit_message(patch_links, cut_body_after) do
patch_links = Enum.sort_by(patch_links, &(&1.patch.pr_xref))
commit_title = Enum.reduce(patch_links,
"Merge", &"#{&2} \##{&1.patch.pr_xref}")
commit_body = Enum.reduce(patch_links, "", fn link, acc ->
Expand Down
26 changes: 26 additions & 0 deletions test/attemptor_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ defmodule BorsNG.Worker.AttemptorTest do
GitHub.ServerMock.put_state(%{
{{:installation, 91}, 14} => %{
branches: %{},
commits: %{},
comments: %{1 => []},
statuses: %{},
files: %{}
Expand All @@ -51,6 +52,7 @@ defmodule BorsNG.Worker.AttemptorTest do
assert state == %{
{{:installation, 91}, 14} => %{
branches: %{},
commits: %{},
comments: %{
1 => ["## try\n\nNot awaiting review"]
},
Expand All @@ -63,6 +65,7 @@ defmodule BorsNG.Worker.AttemptorTest do
GitHub.ServerMock.put_state(%{
{{:installation, 91}, 14} => %{
branches: %{"master" => "ini", "trying" => "", "trying.tmp" => ""},
commits: %{},
comments: %{1 => []},
statuses: %{"iniN" => []},
files: %{"trying" => %{".travis.yml" => ""}}
Expand All @@ -77,6 +80,7 @@ defmodule BorsNG.Worker.AttemptorTest do
GitHub.ServerMock.put_state(%{
{{:installation, 91}, 14} => %{
branches: %{"master" => "ini", "trying" => "", "trying.tmp" => ""},
commits: %{},
comments: %{1 => []},
statuses: %{"iniN" => []},
files: %{"trying" => %{".travis.yml" => "", "appveyor.yml" => ""}}
Expand All @@ -94,6 +98,7 @@ defmodule BorsNG.Worker.AttemptorTest do
GitHub.ServerMock.put_state(%{
{{:installation, 91}, 14} => %{
branches: %{"master" => "ini", "trying" => "", "trying.tmp" => ""},
commits: %{},
comments: %{1 => []},
statuses: %{"iniN" => []},
files: %{"trying" => %{"circle.yml" => ""}}
Expand All @@ -108,6 +113,7 @@ defmodule BorsNG.Worker.AttemptorTest do
GitHub.ServerMock.put_state(%{
{{:installation, 91}, 14} => %{
branches: %{"master" => "ini", "trying" => "", "trying.tmp" => ""},
commits: %{},
comments: %{1 => []},
statuses: %{"iniN" => []},
files: %{"trying" => %{"jet-steps.yml" => ""}}
Expand All @@ -122,6 +128,7 @@ defmodule BorsNG.Worker.AttemptorTest do
GitHub.ServerMock.put_state(%{
{{:installation, 91}, 14} => %{
branches: %{"master" => "ini", "trying" => "", "trying.tmp" => ""},
commits: %{},
comments: %{1 => []},
statuses: %{"iniN" => []},
files: %{"trying" => %{"jet-steps.json" => ""}}
Expand All @@ -136,6 +143,7 @@ defmodule BorsNG.Worker.AttemptorTest do
GitHub.ServerMock.put_state(%{
{{:installation, 91}, 14} => %{
branches: %{"master" => "ini", "trying" => "", "trying.tmp" => ""},
commits: %{},
comments: %{1 => []},
statuses: %{"iniN" => []},
files: %{"trying" => %{"codeship-steps.yml" => ""}}
Expand All @@ -150,6 +158,7 @@ defmodule BorsNG.Worker.AttemptorTest do
GitHub.ServerMock.put_state(%{
{{:installation, 91}, 14} => %{
branches: %{"master" => "ini", "trying" => "", "trying.tmp" => ""},
commits: %{},
comments: %{1 => []},
statuses: %{"iniN" => []},
files: %{"trying" => %{"codeship-steps.json" => ""}}
Expand All @@ -165,6 +174,7 @@ defmodule BorsNG.Worker.AttemptorTest do
GitHub.ServerMock.put_state(%{
{{:installation, 91}, 14} => %{
branches: %{"master" => "ini", "trying" => "", "trying.tmp" => ""},
commits: %{},
comments: %{1 => []},
statuses: %{"iniN" => []},
files: %{"trying" => %{"bors.toml" => ~s/status = [ "ci" ]/}}
Expand All @@ -176,6 +186,9 @@ defmodule BorsNG.Worker.AttemptorTest do
branches: %{
"master" => "ini",
"trying" => "iniN"},
commits: %{
"ini" => %{commit_message: "[ci skip]", parents: ["ini"]},
"iniN" => %{commit_message: "Try #1:test", parents: ["ini", "N"]}},
comments: %{1 => []},
statuses: %{"iniN" => []},
files: %{"trying" => %{"bors.toml" => ~s/status = [ "ci" ]/}}
Expand All @@ -189,6 +202,9 @@ defmodule BorsNG.Worker.AttemptorTest do
branches: %{
"master" => "ini",
"trying" => "iniN"},
commits: %{
"ini" => %{commit_message: "[ci skip]", parents: ["ini"]},
"iniN" => %{commit_message: "Try #1:test", parents: ["ini", "N"]}},
comments: %{1 => []},
statuses: %{"iniN" => []},
files: %{"trying" => %{"bors.toml" => ~s/status = [ "ci" ]/}}
Expand All @@ -202,6 +218,9 @@ defmodule BorsNG.Worker.AttemptorTest do
branches: %{
"master" => "ini",
"trying" => "iniN"},
commits: %{
"ini" => %{commit_message: "[ci skip]", parents: ["ini"]},
"iniN" => %{commit_message: "Try #1:test", parents: ["ini", "N"]}},
comments: %{1 => []},
statuses: %{"iniN" => [{"ci", :ok}]},
files: %{"trying" => %{"bors.toml" => ~s/status = [ "ci" ]/}}
Expand All @@ -214,6 +233,9 @@ defmodule BorsNG.Worker.AttemptorTest do
branches: %{
"master" => "ini",
"trying" => "iniN"},
commits: %{
"ini" => %{commit_message: "[ci skip]", parents: ["ini"]},
"iniN" => %{commit_message: "Try #1:test", parents: ["ini", "N"]}},
comments: %{1 => []},
statuses: %{"iniN" => [{"ci", :ok}]},
files: %{"trying" => %{"bors.toml" => ~s/status = [ "ci" ]/}}
Expand All @@ -230,6 +252,9 @@ defmodule BorsNG.Worker.AttemptorTest do
branches: %{
"master" => "ini",
"trying" => "iniN"},
commits: %{
"ini" => %{commit_message: "[ci skip]", parents: ["ini"]},
"iniN" => %{commit_message: "Try #1:test", parents: ["ini", "N"]}},
comments: %{1 => ["## try\n\n# Build succeeded\n * ci"]},
statuses: %{"iniN" => [{"ci", :ok}]},
files: %{"trying" => %{"bors.toml" => ~s/status = [ "ci" ]/}}
Expand All @@ -240,6 +265,7 @@ defmodule BorsNG.Worker.AttemptorTest do
GitHub.ServerMock.put_state(%{
{{:installation, 91}, 14} => %{
branches: %{"master" => "ini", "trying" => "", "trying.tmp" => ""},
commits: %{},
comments: %{1 => []},
statuses: %{"iniN" => []},
files: %{"trying" => %{"circle.yml" => ""}}
Expand Down
Loading