From 4734fe2bf972e00131364f8239e5cbb36964771c Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Mon, 22 Jul 2024 18:52:12 +0200 Subject: [PATCH 1/5] Provide more team encouragement --- README.md | 10 +++---- config/runtime.exs | 2 +- lib/ff_bot/dispatch/issue_comment.ex | 4 +-- lib/ff_bot/github/merger.ex | 11 ++------ lib/ff_bot/politics.ex | 42 ++++++++++++++++++++++++++++ 5 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 lib/ff_bot/politics.ex diff --git a/README.md b/README.md index d9e2716..a2cfac0 100644 --- a/README.md +++ b/README.md @@ -42,11 +42,11 @@ The following environment variables must be set: You can also optionally set these variables: -| Variable | Description | Default | -|--------------------|------------------------------------------------------------------------------------------|----------------------| -| `FF_POLICY_FILE` | The file to read for policy on who can perform merges | `.github/ff-bot.yml` | -| `FF_LISTEN_PORT` | The HTTP port for the service to listen on | 4000 | -| `FF_NO_PROPAGANDA` | Disable all team encouragement messages generated by the bot on merged Pull Requests. | | +| Variable | Description | Default | +|-----------------------|------------------------------------------------------------------------------------------|----------------------| +| `FF_POLICY_FILE` | The file to read for policy on who can perform merges | `.github/ff-bot.yml` | +| `FF_LISTEN_PORT` | The HTTP port for the service to listen on | 4000 | +| `FF_REAGAN_SUPPORTER` | Disable any encouragement messages generated by the bot. | | ## Usage diff --git a/config/runtime.exs b/config/runtime.exs index c836ae1..f4546ed 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -6,4 +6,4 @@ config :ff_bot, github_client_secret: System.fetch_env!("GITHUB_CLIENT_SECRET") |> String.replace("\\n", "\n"), policy_file: System.get_env("FF_POLICY_FILE", ".github/ff-bot.yml"), service_port: System.get_env("FF_LISTEN_PORT", "4000") |> String.to_integer(), - disable_propaganda?: System.get_env("FF_NO_PROPAGANDA") + reagan_supporter?: System.get_env("FF_REAGAN_SUPPORTER") diff --git a/lib/ff_bot/dispatch/issue_comment.ex b/lib/ff_bot/dispatch/issue_comment.ex index d3ec251..03d64c6 100644 --- a/lib/ff_bot/dispatch/issue_comment.ex +++ b/lib/ff_bot/dispatch/issue_comment.ex @@ -5,7 +5,7 @@ defmodule FFBot.Dispatch.IssueComment do """ @behaviour FFBot.Dispatch - alias FFBot.{Auth.InstallationTokenServer, GitHub, Policy} + alias FFBot.{Auth.InstallationTokenServer, GitHub, Policy, Politics} require Logger @@ -132,7 +132,7 @@ defmodule FFBot.Dispatch.IssueComment do "#{comparison_details["ahead_by"]} commits and behind by " <> "#{comparison_details["behind_by"]} commits. Please update the branch " <> "to reflect changes on `#{repo_details["default_branch"]}` and try again, " <> - "or merge locally." + "or merge locally." <> Politics.maybe_encouraging_comment() ) else Logger.info("Triggering merger...") diff --git a/lib/ff_bot/github/merger.ex b/lib/ff_bot/github/merger.ex index 33d146b..ef3229e 100644 --- a/lib/ff_bot/github/merger.ex +++ b/lib/ff_bot/github/merger.ex @@ -11,6 +11,7 @@ defmodule FFBot.GitHub.Merger do require Logger + alias FFBot.Politics alias FFBot.GitHub.Request def start_merge(token, repo, pull_request) do @@ -44,7 +45,7 @@ defmodule FFBot.GitHub.Merger do pull_request["number"], :success, "Successfully fast-forwarded commits from `#{pull_request["head"]["label"]}` " <> - "onto `#{repo["default_branch"]}`" <> maybe_propaganda() + "onto `#{repo["default_branch"]}`" <> Politics.maybe_supportive_comment() ) end @@ -66,12 +67,4 @@ defmodule FFBot.GitHub.Merger do defp push_changes(cloned) do {:ok, _} = Git.push(cloned) end - - defp maybe_propaganda do - if Application.get_env(:ff_bot, :disable_propaganda?) == nil and :rand.uniform() < 0.01 do - ". Glory to Arstotzka!" - else - "" - end - end end diff --git a/lib/ff_bot/politics.ex b/lib/ff_bot/politics.ex new file mode 100644 index 0000000..2d21c37 --- /dev/null +++ b/lib/ff_bot/politics.ex @@ -0,0 +1,42 @@ +defmodule FFBot.Politics do + @moduledoc """ + Encouragement functions for our Comrades. + """ + + @german_reunification_margin 0.01 + @cuban_missile_crisis_threshold 0.01 + + defp supports_comrades? do + Application.get_env(:ff_bot, :reagan_supporter?) == nil + end + + defp should_generate_supportive_comment? do + :rand.uniform() < @german_reunification_margin + end + + defp should_generate_encouraging_comment? do + :rand.uniform() < @cuban_missile_crisis_threshold + end + + @doc """ + On a slim chance, generate a comment that expresses appreciation in the comrade's work. + """ + def maybe_supportive_comment do + if supports_comrades?() && should_generate_supportive_comment?() do + ". Glory to Arstotzka!" + else + "" + end + end + + @doc """ + On a slim chance, generate a comment that expresses encouragement for the comrade to work better. + """ + def maybe_encouraging_comment do + if supports_comrades?() && should_generate_encouraging_comment?() do + ". Any negligence will result in swift punishment." + else + "" + end + end +end From 5ac52d5650f5e3bd73fb48078dcdd5a14d1aba7a Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Thu, 25 Jul 2024 19:20:59 +0200 Subject: [PATCH 2/5] Pleasure the western style dictator --- README.md | 10 +++++----- lib/ff_bot/dispatch/issue_comment.ex | 4 ++-- lib/ff_bot/{politics.ex => encouragement.ex} | 2 +- lib/ff_bot/github/merger.ex | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) rename lib/ff_bot/{politics.ex => encouragement.ex} (96%) diff --git a/README.md b/README.md index a2cfac0..2ed2958 100644 --- a/README.md +++ b/README.md @@ -42,11 +42,11 @@ The following environment variables must be set: You can also optionally set these variables: -| Variable | Description | Default | -|-----------------------|------------------------------------------------------------------------------------------|----------------------| -| `FF_POLICY_FILE` | The file to read for policy on who can perform merges | `.github/ff-bot.yml` | -| `FF_LISTEN_PORT` | The HTTP port for the service to listen on | 4000 | -| `FF_REAGAN_SUPPORTER` | Disable any encouragement messages generated by the bot. | | +| Variable | Description | Default | +|--------------------|------------------------------------------------------------------------------------------|----------------------| +| `FF_POLICY_FILE` | The file to read for policy on who can perform merges | `.github/ff-bot.yml` | +| `FF_LISTEN_PORT` | The HTTP port for the service to listen on | 4000 | +| `FF_NO_PROPAGANDA` | Disable all team encouragement messages generated by the bot. | | ## Usage diff --git a/lib/ff_bot/dispatch/issue_comment.ex b/lib/ff_bot/dispatch/issue_comment.ex index 03d64c6..0908d82 100644 --- a/lib/ff_bot/dispatch/issue_comment.ex +++ b/lib/ff_bot/dispatch/issue_comment.ex @@ -5,7 +5,7 @@ defmodule FFBot.Dispatch.IssueComment do """ @behaviour FFBot.Dispatch - alias FFBot.{Auth.InstallationTokenServer, GitHub, Policy, Politics} + alias FFBot.{Auth.InstallationTokenServer, GitHub, Policy, Encouragement} require Logger @@ -132,7 +132,7 @@ defmodule FFBot.Dispatch.IssueComment do "#{comparison_details["ahead_by"]} commits and behind by " <> "#{comparison_details["behind_by"]} commits. Please update the branch " <> "to reflect changes on `#{repo_details["default_branch"]}` and try again, " <> - "or merge locally." <> Politics.maybe_encouraging_comment() + "or merge locally." <> Encouragement.maybe_encouraging_comment() ) else Logger.info("Triggering merger...") diff --git a/lib/ff_bot/politics.ex b/lib/ff_bot/encouragement.ex similarity index 96% rename from lib/ff_bot/politics.ex rename to lib/ff_bot/encouragement.ex index 2d21c37..30191f0 100644 --- a/lib/ff_bot/politics.ex +++ b/lib/ff_bot/encouragement.ex @@ -1,4 +1,4 @@ -defmodule FFBot.Politics do +defmodule FFBot.Encouragement do @moduledoc """ Encouragement functions for our Comrades. """ diff --git a/lib/ff_bot/github/merger.ex b/lib/ff_bot/github/merger.ex index ef3229e..c0bdc09 100644 --- a/lib/ff_bot/github/merger.ex +++ b/lib/ff_bot/github/merger.ex @@ -11,7 +11,7 @@ defmodule FFBot.GitHub.Merger do require Logger - alias FFBot.Politics + alias FFBot.Encouragement alias FFBot.GitHub.Request def start_merge(token, repo, pull_request) do @@ -45,7 +45,7 @@ defmodule FFBot.GitHub.Merger do pull_request["number"], :success, "Successfully fast-forwarded commits from `#{pull_request["head"]["label"]}` " <> - "onto `#{repo["default_branch"]}`" <> Politics.maybe_supportive_comment() + "onto `#{repo["default_branch"]}`" <> Encouragement.maybe_supportive_comment() ) end From f09dac04c98d5fb435f9d1de510a22eee98efd8a Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Thu, 25 Jul 2024 20:08:38 +0200 Subject: [PATCH 3/5] Reduce amount of patriotic comments --- config/runtime.exs | 2 +- lib/ff_bot/encouragement.ex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index f4546ed..c836ae1 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -6,4 +6,4 @@ config :ff_bot, github_client_secret: System.fetch_env!("GITHUB_CLIENT_SECRET") |> String.replace("\\n", "\n"), policy_file: System.get_env("FF_POLICY_FILE", ".github/ff-bot.yml"), service_port: System.get_env("FF_LISTEN_PORT", "4000") |> String.to_integer(), - reagan_supporter?: System.get_env("FF_REAGAN_SUPPORTER") + disable_propaganda?: System.get_env("FF_NO_PROPAGANDA") diff --git a/lib/ff_bot/encouragement.ex b/lib/ff_bot/encouragement.ex index 30191f0..74eb6d8 100644 --- a/lib/ff_bot/encouragement.ex +++ b/lib/ff_bot/encouragement.ex @@ -7,7 +7,7 @@ defmodule FFBot.Encouragement do @cuban_missile_crisis_threshold 0.01 defp supports_comrades? do - Application.get_env(:ff_bot, :reagan_supporter?) == nil + Application.get_env(:ff_bot, :disable_propaganda?) == nil end defp should_generate_supportive_comment? do From edfd814a5587450b96f0399236cc4b9ebafe8302 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Thu, 25 Jul 2024 21:08:54 +0200 Subject: [PATCH 4/5] Use politically accepted variables for the Western spy --- lib/ff_bot/encouragement.ex | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/ff_bot/encouragement.ex b/lib/ff_bot/encouragement.ex index 74eb6d8..81059b2 100644 --- a/lib/ff_bot/encouragement.ex +++ b/lib/ff_bot/encouragement.ex @@ -3,19 +3,23 @@ defmodule FFBot.Encouragement do Encouragement functions for our Comrades. """ - @german_reunification_margin 0.01 - @cuban_missile_crisis_threshold 0.01 + # Fractional percentage of how often the bot will generate a supportive + # comment on merge. + @support_a_comrade_margin 0.01 + # Fractional percentage of how often the bot will generate an encouraging + # comment on conflicts. + @encourage_a_comrade_threshold 0.01 defp supports_comrades? do Application.get_env(:ff_bot, :disable_propaganda?) == nil end defp should_generate_supportive_comment? do - :rand.uniform() < @german_reunification_margin + :rand.uniform() < @support_a_comrade_margin end defp should_generate_encouraging_comment? do - :rand.uniform() < @cuban_missile_crisis_threshold + :rand.uniform() < @encourage_a_comrade_threshold end @doc """ From 47bd230fa9a4a248ffc7c64c744f8ec2767872b3 Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Thu, 25 Jul 2024 21:11:08 +0200 Subject: [PATCH 5/5] Always encourage The Comrade --- lib/ff_bot/encouragement.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ff_bot/encouragement.ex b/lib/ff_bot/encouragement.ex index 81059b2..f74e75c 100644 --- a/lib/ff_bot/encouragement.ex +++ b/lib/ff_bot/encouragement.ex @@ -38,7 +38,7 @@ defmodule FFBot.Encouragement do """ def maybe_encouraging_comment do if supports_comrades?() && should_generate_encouraging_comment?() do - ". Any negligence will result in swift punishment." + ". March on, Comrade!" else "" end