forked from openstreetmap/openstreetmap-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added workflow for PR labeling using Danger
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
1 parent
f9ea6aa
commit 8849b12
Showing
5 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters