Skip to content

Commit

Permalink
Added workflow for PR labeling using Danger
Browse files Browse the repository at this point in the history
Workflow is called when PR is created or updated. It checks if PR is too big (>500 changed lines), changes one of translation files (YML, except en.yml) or contains merge-commits and generates appropriate labels.
  • Loading branch information
nenad-vujicic committed Jul 19, 2024
1 parent f9ea6aa commit 8849b12
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/labeling.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Danger

run-name: Updating labels for current PR

on:
pull_request_target:
types: [opened, synchronize]

jobs:
danger:
runs-on: ubuntu-22.04
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Setup ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0
rubygems: 3.4.10
bundler-cache: true
- name: Danger
env:
DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
bundle exec danger --verbose
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ require:
AllCops:
TargetRubyVersion: 3.0
NewCops: enable
Include:
- '**/Dangerfile'
Exclude:
- 'vendor/**/*'

Expand Down
44 changes: 44 additions & 0 deletions Dangerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Get PR number and initialize is_good_pr variable
pr_number = github.pr_json["number"]
is_good_pr = true

# Report if number of changed lines is > 500
if git.lines_of_code > 500
warn("Number of updated lines of code is too large to be in one PR. Perhaps it should be separated into two or more?")
auto_label.set(pr_number, "Big PR", "ffff00")
is_good_pr = false
else
auto_label.remove("Big PR")
end

# Get list of translation files (except en.yml) which are modified
modified_yml_files = git.modified_files.select do |file|
file.start_with?("config/locales") && File.extname(file) == ".yml" && File.basename(file) != "en.yml"
end

# Report if some translation file (except en.yml) is modified
if modified_yml_files.empty?
auto_label.remove("Compromised Translations")
else
modified_files_str = modified_yml_files.map { |file| "`#{file}`" }.join(", ")
warn("The following YAML files other than `en.yml` have been modified: #{modified_files_str}. Only `en.yml` is allowed to be changed.")
auto_label.set(pr_number, "Compromised Translations", "ff0000")
is_good_pr = false
end

# Report if there are merge-commits in PR
if git.commits.any? { |c| c.parents.count > 1 }
warn("Merge commits are found in PR. Please rebase to get rid of the merge commits in this PR and read CONTRIBUTE.md.")
auto_label.set(pr_number, "Merge Commits", "ffaec9")
is_good_pr = false
else
auto_label.remove("Merge Commits")
end

# Report "Everything is fine!" if no warnings were generated
if is_good_pr
message("Everything is fine!")
auto_label.set(pr_number, "Good PR", "00ff00")
else
auto_label.remove("Good PR")
end
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ gem "multi_xml", "~> 0.6.0"
group :development do
gem "better_errors"
gem "binding_of_caller"
gem "danger"
gem "danger-auto_label"
gem "debug_inspector"
gem "i18n-tasks"
gem "listen"
Expand Down
44 changes: 44 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,40 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
claide (1.1.0)
claide-plugins (0.9.2)
cork
nap
open4 (~> 1.3)
colored2 (3.1.2)
concurrent-ruby (1.3.3)
config (5.5.1)
deep_merge (~> 1.2, >= 1.2.1)
connection_pool (2.4.1)
cork (0.3.0)
colored2 (~> 3.1)
crack (1.0.0)
bigdecimal
rexml
crass (1.0.6)
dalli (3.2.8)
danger (9.4.3)
claide (~> 1.0)
claide-plugins (>= 0.9.2)
colored2 (~> 3.1)
cork (~> 0.1)
faraday (>= 0.9.0, < 3.0)
faraday-http-cache (~> 2.0)
git (~> 1.13)
kramdown (~> 2.3)
kramdown-parser-gfm (~> 1.0)
no_proxy_fix
octokit (>= 4.0)
terminal-table (>= 1, < 4)
danger-auto_label (1.3.1)
danger-plugin-api (~> 1.0)
danger-plugin-api (1.0.0)
danger (> 2.0)
dartsass-ruby (3.0.2)
sass-embedded (~> 1.54, < 1.67)
dartsass-sprockets (3.0.0)
Expand Down Expand Up @@ -237,6 +262,8 @@ GEM
faraday (2.10.0)
faraday-net_http (>= 2.0, < 3.2)
logger
faraday-http-cache (2.5.1)
faraday (>= 0.8)
faraday-net_http (3.1.0)
net-http
ffi (1.17.0)
Expand All @@ -251,6 +278,9 @@ GEM
fspath (3.1.2)
gd2-ffij (0.4.0)
ffi (>= 1.0.0)
git (1.19.1)
addressable (~> 2.8)
rchardet (~> 1.8)
globalid (1.2.1)
activesupport (>= 6.1)
google-protobuf (3.25.3)
Expand Down Expand Up @@ -307,6 +337,8 @@ GEM
kgio (2.11.4)
kramdown (2.4.0)
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
language_server-protocol (3.17.0.3)
libv8-node (18.19.0.0)
libxml-ruby (5.0.3)
Expand Down Expand Up @@ -340,6 +372,7 @@ GEM
multi_json (1.15.0)
multi_xml (0.6.0)
mutex_m (0.2.0)
nap (1.1.0)
net-http (0.4.1)
uri
net-imap (0.4.14)
Expand All @@ -352,6 +385,7 @@ GEM
net-smtp (0.5.0)
net-protocol
nio4r (2.7.3)
no_proxy_fix (0.1.2)
nokogiri (1.16.6)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
Expand All @@ -368,6 +402,9 @@ GEM
rack (>= 1.2, < 4)
snaky_hash (~> 2.0)
version_gem (~> 1.1)
octokit (9.1.0)
faraday (>= 1, < 3)
sawyer (~> 0.9)
omniauth (2.0.4)
hashie (>= 3.4.6)
rack (>= 1.6.2, < 3)
Expand Down Expand Up @@ -402,6 +439,7 @@ GEM
omniauth-rails_csrf_protection (1.0.2)
actionpack (>= 4.2)
omniauth (~> 2.0)
open4 (1.3.4)
openstreetmap-deadlock_retry (1.3.1)
parallel (1.25.1)
parser (3.3.4.0)
Expand Down Expand Up @@ -478,6 +516,7 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.11.1)
ffi (~> 1.0)
rchardet (1.8.0)
rdoc (6.7.0)
psych (>= 4.0.0)
regexp_parser (2.9.2)
Expand Down Expand Up @@ -533,6 +572,9 @@ GEM
sass-embedded (1.64.2)
google-protobuf (~> 3.23)
rake (>= 13.0.0)
sawyer (0.9.2)
addressable (>= 2.3.5)
faraday (>= 0.17.3, < 3)
selenium-webdriver (4.22.0)
base64 (~> 0.2)
logger (~> 1.4)
Expand Down Expand Up @@ -625,6 +667,8 @@ DEPENDENCIES
config
connection_pool
dalli
danger
danger-auto_label
dartsass-sprockets
debug_inspector
delayed_job_active_record
Expand Down

0 comments on commit 8849b12

Please sign in to comment.