From 0091a2b0ac7682c0712b989b837c4646d5dd40fd Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Sun, 22 Jan 2017 20:48:19 +0100 Subject: [PATCH 1/7] First attempt at configuring Danger --- Dangerfile | 18 ++++++++++++++++++ Gemfile | 1 + Gemfile.lock | 37 +++++++++++++++++++++++++++++++++++++ circle.yml | 2 ++ 4 files changed, 58 insertions(+) create mode 100644 Dangerfile diff --git a/Dangerfile b/Dangerfile new file mode 100644 index 0000000..01d23ed --- /dev/null +++ b/Dangerfile @@ -0,0 +1,18 @@ +# Sometimes it's a README fix, or something like that - which isn't relevant for +# including in a project's CHANGELOG for example +declared_trivial = github.pr_title.include? "#trivial" + +# Make it more obvious that a PR is a work in progress and shouldn't be merged yet +warn("PR is classed as Work in Progress") if github.pr_title.include? "[WIP]" + +# Warn when there is a big PR +warn("Big PR") if git.lines_of_code > 500 + +# if git.lines_of_code > 3 && !git.modified_files.include?("CHANGELOG.yml") +if !git.modified_files.include?("CHANGELOG.yml") && !declared_trivial + fail("Please include a CHANGELOG entry. \nYou can find it at [CHANGELOG.md](https://github.com/SwiftGen/SwiftGen/blob/master/CHANGELOG.md).") + message "We use the following format for CHANGELOG entries:\n\n" + + '```' + "\n" + + "* Describe your change here. Don't forget to use 2 spaces at the end of the last line describing your change. \n" + + " [#nn](https://github.com/SwiftGen/SwiftGen/pull/nn)" +end diff --git a/Gemfile b/Gemfile index 42481de..9120c2e 100644 --- a/Gemfile +++ b/Gemfile @@ -2,4 +2,5 @@ source 'https://rubygems.org' gem 'cocoapods', '1.2.1' +gem 'danger' gem 'xcpretty' diff --git a/Gemfile.lock b/Gemfile.lock index b788395..744fe7d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,7 +7,13 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) + addressable (2.5.1) + public_suffix (~> 2.0, >= 2.0.2) claide (1.0.1) + claide-plugins (0.9.2) + cork + nap + open4 (~> 1.3) cocoapods (1.2.1) activesupport (>= 4.0.2, < 5) claide (>= 1.0.1, < 2.0) @@ -42,21 +48,51 @@ GEM netrc (= 0.7.8) cocoapods-try (1.1.0) colored2 (3.1.2) + cork (0.3.0) + colored2 (~> 3.1) + danger (5.1.0) + claide (~> 1.0) + claide-plugins (>= 0.9.2) + colored2 (~> 3.1) + cork (~> 0.1) + faraday (~> 0.9) + faraday-http-cache (~> 1.0) + git (~> 1) + kramdown (~> 1.5) + octokit (~> 4.2) + terminal-table (~> 1) escape (0.0.4) + faraday (0.12.1) + multipart-post (>= 1.2, < 3) + faraday-http-cache (1.3.1) + faraday (~> 0.8) fourflusher (2.0.1) fuzzy_match (2.0.4) gh_inspector (1.0.3) + git (1.3.0) i18n (0.8.1) + kramdown (1.13.2) minitest (5.10.1) molinillo (0.5.7) + multipart-post (2.0.0) nanaimo (0.2.3) nap (1.1.0) netrc (0.7.8) + octokit (4.7.0) + sawyer (~> 0.8.0, >= 0.5.3) + open4 (1.3.4) + public_suffix (2.0.5) rouge (1.11.1) ruby-macho (1.1.0) + sawyer (0.8.1) + addressable (>= 2.3.5, < 2.6) + faraday (~> 0.8, < 1.0) + terminal-table (1.7.3) + unicode-display_width (~> 1.1.1) thread_safe (0.3.6) tzinfo (1.2.3) thread_safe (~> 0.1) + unicode-display_width (1.1.3) xcodeproj (1.4.4) CFPropertyList (~> 2.3.3) claide (>= 1.0.1, < 2.0) @@ -70,6 +106,7 @@ PLATFORMS DEPENDENCIES cocoapods (= 1.2.1) + danger xcpretty BUNDLED WITH diff --git a/circle.yml b/circle.yml index 859fab7..d45aa43 100644 --- a/circle.yml +++ b/circle.yml @@ -7,6 +7,8 @@ dependencies: - rake lint:install test: + pre: + - bundle exec danger override: - rake lint:tests - rake xcode:test From 4614aa1c8af9a29eb66fd5ceabe3e6bfb1789edb Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Sun, 22 Jan 2017 21:10:08 +0100 Subject: [PATCH 2/7] Fix message sent by Danger about the CHANGELOG format --- Dangerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dangerfile b/Dangerfile index 01d23ed..adaf8d8 100644 --- a/Dangerfile +++ b/Dangerfile @@ -14,5 +14,6 @@ if !git.modified_files.include?("CHANGELOG.yml") && !declared_trivial message "We use the following format for CHANGELOG entries:\n\n" + '```' + "\n" + "* Describe your change here. Don't forget to use 2 spaces at the end of the last line describing your change. \n" + - " [#nn](https://github.com/SwiftGen/SwiftGen/pull/nn)" + " [#nn](https://github.com/SwiftGen/SwiftGen/pull/nn)" + + '```' + "\n" end From 1c69606593aecb921e3aa55342bae964848e76d8 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Sun, 22 Jan 2017 21:23:31 +0100 Subject: [PATCH 3/7] Fix CHANGELOG format message again --- Dangerfile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Dangerfile b/Dangerfile index adaf8d8..751121f 100644 --- a/Dangerfile +++ b/Dangerfile @@ -11,9 +11,11 @@ warn("Big PR") if git.lines_of_code > 500 # if git.lines_of_code > 3 && !git.modified_files.include?("CHANGELOG.yml") if !git.modified_files.include?("CHANGELOG.yml") && !declared_trivial fail("Please include a CHANGELOG entry. \nYou can find it at [CHANGELOG.md](https://github.com/SwiftGen/SwiftGen/blob/master/CHANGELOG.md).") - message "We use the following format for CHANGELOG entries:\n\n" + - '```' + "\n" + - "* Describe your change here. Don't forget to use 2 spaces at the end of the last line describing your change. \n" + - " [#nn](https://github.com/SwiftGen/SwiftGen/pull/nn)" + - '```' + "\n" + message <<-CHANGELOG_FORMAT.gsub(/^ *\|/,'') + We use the following format for CHANGELOG entries: + |
+  | * Describe your change here.  Don’t forget to use 2 spaces at the end of the last line describing your change.  
+  |   [#nn](https://github.com/SwiftGen/SwiftGen/pull/nn)
+  |
/ +CHANGELOG_FORMAT end From 7a2025827025cfb5dfc3e6d6e5a8920c2a69d095 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Sun, 22 Jan 2017 21:35:27 +0100 Subject: [PATCH 4/7] Come on, heredoc syntax! --- Dangerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dangerfile b/Dangerfile index 751121f..c8a8d35 100644 --- a/Dangerfile +++ b/Dangerfile @@ -11,11 +11,12 @@ warn("Big PR") if git.lines_of_code > 500 # if git.lines_of_code > 3 && !git.modified_files.include?("CHANGELOG.yml") if !git.modified_files.include?("CHANGELOG.yml") && !declared_trivial fail("Please include a CHANGELOG entry. \nYou can find it at [CHANGELOG.md](https://github.com/SwiftGen/SwiftGen/blob/master/CHANGELOG.md).") - message <<-CHANGELOG_FORMAT.gsub(/^ *\|/,'') - We use the following format for CHANGELOG entries: + changelog_msg = <<-CHANGELOG_FORMAT.gsub(/^ *\|/,'') + |We use the following format for CHANGELOG entries: |
   | * Describe your change here.  Don’t forget to use 2 spaces at the end of the last line describing your change.  
   |   [#nn](https://github.com/SwiftGen/SwiftGen/pull/nn)
   |
/ CHANGELOG_FORMAT + message(changelog_msg) end From 45c01f4bf464766939f233b98cbc70acc0115543 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Sun, 22 Jan 2017 21:42:40 +0100 Subject: [PATCH 5/7] [Danger] Use the markdown method to display the CHANGELOG format --- Dangerfile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Dangerfile b/Dangerfile index c8a8d35..f0a61cf 100644 --- a/Dangerfile +++ b/Dangerfile @@ -12,11 +12,12 @@ warn("Big PR") if git.lines_of_code > 500 if !git.modified_files.include?("CHANGELOG.yml") && !declared_trivial fail("Please include a CHANGELOG entry. \nYou can find it at [CHANGELOG.md](https://github.com/SwiftGen/SwiftGen/blob/master/CHANGELOG.md).") changelog_msg = <<-CHANGELOG_FORMAT.gsub(/^ *\|/,'') - |We use the following format for CHANGELOG entries: - |
-  | * Describe your change here.  Don’t forget to use 2 spaces at the end of the last line describing your change.  
+  |Note: we use the following format for CHANGELOG entries:
+  |```
+  | * Describe your change here. Don’t forget to use 2 spaces at the end
+  |   of the last line describing your change.  
   |   [#nn](https://github.com/SwiftGen/SwiftGen/pull/nn)
-  |
/ + |``` CHANGELOG_FORMAT - message(changelog_msg) + markdown(changelog_msg) end From 9e7442924fbeec7e30996c2dea4ea1560427ae43 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Sun, 22 Jan 2017 22:30:52 +0100 Subject: [PATCH 6/7] More dynamic suggestions --- Dangerfile | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Dangerfile b/Dangerfile index f0a61cf..d3beb7e 100644 --- a/Dangerfile +++ b/Dangerfile @@ -10,14 +10,22 @@ warn("Big PR") if git.lines_of_code > 500 # if git.lines_of_code > 3 && !git.modified_files.include?("CHANGELOG.yml") if !git.modified_files.include?("CHANGELOG.yml") && !declared_trivial - fail("Please include a CHANGELOG entry. \nYou can find it at [CHANGELOG.md](https://github.com/SwiftGen/SwiftGen/blob/master/CHANGELOG.md).") + repo_url = github.pr_json['head']['repo']['html_url'] + pr_number = github.pr_json['number'] + pr_url = github.pr_json['html_url'] + pr_title = github.pr_title.sub(/[?.!,;]?$/, '').capitalize + pr_author = github.pr_author + pr_author_url = "https://github.com/#{github.pr_author}" + + fail("Please include a CHANGELOG entry. \nYou can find it at [CHANGELOG.md](#{repo_url}/blob/master/CHANGELOG.md).") changelog_msg = <<-CHANGELOG_FORMAT.gsub(/^ *\|/,'') |Note: we use the following format for CHANGELOG entries: |``` - | * Describe your change here. Don’t forget to use 2 spaces at the end - | of the last line describing your change. - | [#nn](https://github.com/SwiftGen/SwiftGen/pull/nn) + | * #{pr_title} + | [##{pr_number}](#{pr_url}) + | [@#{pr_author}](#{pr_author_url}) |``` + |:bulb: Don't forget to use 2 spaces after the full stop at the end of the line describing your changes. CHANGELOG_FORMAT markdown(changelog_msg) end From cf03df24d99d6201557c617c1de940a076670f6f Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Sun, 22 Jan 2017 22:47:05 +0100 Subject: [PATCH 7/7] Don't forget the full stop! --- Dangerfile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Dangerfile b/Dangerfile index d3beb7e..2cb0d6b 100644 --- a/Dangerfile +++ b/Dangerfile @@ -11,11 +11,12 @@ warn("Big PR") if git.lines_of_code > 500 # if git.lines_of_code > 3 && !git.modified_files.include?("CHANGELOG.yml") if !git.modified_files.include?("CHANGELOG.yml") && !declared_trivial repo_url = github.pr_json['head']['repo']['html_url'] + pr_title = github.pr_title + pr_title += '.' unless pr_title.end_with?('.') pr_number = github.pr_json['number'] pr_url = github.pr_json['html_url'] - pr_title = github.pr_title.sub(/[?.!,;]?$/, '').capitalize pr_author = github.pr_author - pr_author_url = "https://github.com/#{github.pr_author}" + pr_author_url = "https://github.com/#{pr_author}" fail("Please include a CHANGELOG entry. \nYou can find it at [CHANGELOG.md](#{repo_url}/blob/master/CHANGELOG.md).") changelog_msg = <<-CHANGELOG_FORMAT.gsub(/^ *\|/,'') @@ -26,6 +27,6 @@ if !git.modified_files.include?("CHANGELOG.yml") && !declared_trivial | [@#{pr_author}](#{pr_author_url}) |``` |:bulb: Don't forget to use 2 spaces after the full stop at the end of the line describing your changes. -CHANGELOG_FORMAT + CHANGELOG_FORMAT markdown(changelog_msg) end