Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(pr): run a action when pr #31

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/danger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: PR Summary
on:
pull_request:
types: [opened, synchronize]

permissions:
pull-requests: write
contents: read

jobs:
danger:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'

- name: Install Danger
run: gem install danger

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install Python dependencies
run: pip install flake8

- name: Run Danger
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: danger
49 changes: 49 additions & 0 deletions Dangerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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_exit_status != 0
fail("Flake8 code issues found:\n```\n#{flake8_result}\n```")
else
message("No Flake8 issues found!")
end
end