TIL you can add '.patch' to Github commit URLs

Oliver Peate posted on December 14th, 2018

If you add .patch to a Github commit URL it provides a patch:

https://github.com/odlp/rspec_overview/commit/185b5bc0442cc0d56f3e7e8ce783fbf6eff98765.patch

From 185b5bc0442cc0d56f3e7e8ce783fbf6eff98765 Mon Sep 17 00:00:00 2001
From: Oliver Peate <odlp@users.noreply.github.com>
Date: Tue, 7 Aug 2018 18:14:41 +0100
Subject: [PATCH] Tidyup rendering markdown table

---
 lib/rspec_overview/output/markdown_table.rb | 24 ++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/lib/rspec_overview/output/markdown_table.rb b/lib/rspec_overview/output/markdown_table.rb
index 04ebac5..fbab9d2 100644
--- a/lib/rspec_overview/output/markdown_table.rb
+++ b/lib/rspec_overview/output/markdown_table.rb
@@ -24,9 +24,27 @@ def column(index)
       attr_reader :matrix

       def render_table
-        lines = matrix.row_vectors.map(&method(:render_row))
-        lines.insert(1, create_heading_divider(lines.first))
-        lines.join("\n") + "\n"
+        heading_row = render_row(header_data)
+        heading_divider = create_heading_divider(heading_row)
+        body_rows = render_rows(body_data).join("\n")
+
+        <<~OUTPUT
+          #{heading_row}
+          #{heading_divider}
+          #{body_rows}
+        OUTPUT
+      end
+
+      def header_data
+        matrix.row_vectors[0]
+      end
+
+      def body_data
+        matrix.row_vectors[1..-1]
+      end
+
+      def render_rows(data_rows)
+        data_rows.map(&method(:render_row))
       end

       def render_row(data_row)

You can then save & apply this patch locally with git-apply. It works with pull requests too…

What did you learn today?

Write a quick TIL post to reflect on what you've learned.

Write a post