-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDangerfile
51 lines (38 loc) · 1.85 KB
/
Dangerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
modified_files = git.modified_files + git.added_files
deleted_files = git.deleted_files
total_lines_changed = git.lines_of_code
summary = "### 🤖 PR Auto Summary\n"
summary += "🚀 **Total affected files**: #{modified_files.count + deleted_files.count}\n"
summary += "🆕 **New files**: #{git.added_files.count}\n"
summary += "✏️ **Modified files**: #{git.modified_files.count}\n"
summary += "🗑️ **Deleted files**: #{git.deleted_files.count}\n"
summary += "📊 **Total lines changed**: #{total_lines_changed}\n"
summary += "📂 **Key modified files**:\n"
modified_files.first(5).each do |file|
summary += " - `#{file}`\n"
end
unless deleted_files.empty?
summary += "🗂️ **Key deleted files**:\n"
deleted_files.first(5).each do |file|
summary += " - `#{file}`\n"
end
end
warn("PR description is empty. Please provide a detailed explanation of the changes.") if github.pr_body.nil? || github.pr_body.strip.empty?
source_branch = github.branch_for_head
target_branch = github.branch_for_base
warn("PR target branch is `#{target_branch}`. Ensure this PR follows the merge strategy!") if (target_branch == "main" || target_branch == "master") && !(source_branch == "dev" || source_branch == "develop")
warn("PR is marked as Work in Progress (WIP).") if github.pr_title.include? "WIP"
warn("Please add labels to this PR.") if github.pr_labels.empty?
markdown(summary)
python_files = (git.modified_files + git.added_files).select { |file| file.end_with?(".py") }
unless python_files.empty?
flake8_result = `flake8 #{python_files.join(" ")}`
flake8_exit_status = $?.exitstatus
if flake8_result.include?("E501")
warn("Flake8 code issues found (lines > 79 characters):\n```\n#{flake8_result}\n```")
elsif flake8_exit_status != 0
fail("Flake8 code issues found:\n```\n#{flake8_result}\n```")
else
message("No Flake8 issues found!")
end
end