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
a344173
commit 2bd330d
Showing
4 changed files
with
103 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: | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Remove all previously added labels | ||
auto_label.remove("Big PR") | ||
auto_label.remove("Compromised Translations") | ||
auto_label.remove("Merge Commits") | ||
auto_label.remove("Good PR") | ||
|
||
# Report if number of changed lines is > 500 | ||
pr_number = github.pr_json["number"] | ||
is_big_pr = 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?") if is_big_pr | ||
auto_label.set(pr_number, "Big PR", "ffff00") if is_big_pr | ||
|
||
# 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 | ||
unless modified_yml_files.empty? | ||
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") | ||
end | ||
|
||
# Report if there are merge-commits in PR | ||
are_merge_commits_available = git.commits.any? { |c| c.parents.count > 1 } | ||
warn("Merge commits found in this pull request. Please, read CONTRIBUTE.md!") if are_merge_commits_available | ||
auto_label.set(pr_number, "Merge Commits", "ffaec9") if are_merge_commits_available | ||
|
||
# Report "Everything is fine!" if no warnings were generated | ||
message("Everything is fine!") if !is_big_pr && modified_yml_files.empty? && !are_merge_commits_available | ||
auto_label.set(pr_number, "Good PR", "00ff00") if !is_big_pr && modified_yml_files.empty? && !are_merge_commits_available |
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