Skip to content

Commit ebc9324

Browse files
committed
Adding Bot For PR's
1 parent d2b2838 commit ebc9324

File tree

1 file changed

+169
-0
lines changed

1 file changed

+169
-0
lines changed

.github/workflows/bot.yml

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
name: PR Bot
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- opened
7+
- synchronize
8+
9+
jobs:
10+
check-pr-status:
11+
name: Workflow Status Check
12+
runs-on: ubuntu-latest
13+
permissions:
14+
pull-requests: write
15+
contents: read
16+
issues: write
17+
actions: read
18+
19+
steps:
20+
- name: Checkout Repository
21+
uses: actions/checkout@v4
22+
with:
23+
ref: ${{ github.event.pull_request.head.sha }}
24+
25+
- name: Setup Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: '22'
29+
30+
- name: Install Dependencies
31+
run: npm install
32+
33+
- name: Run Build Test (CI Check)
34+
id: ci-check
35+
run: |
36+
if npm run build; then
37+
echo "CI_PASSED=true" >> $GITHUB_ENV
38+
echo "CI_ERROR=" >> $GITHUB_ENV
39+
else
40+
echo "CI_PASSED=false" >> $GITHUB_ENV
41+
echo "CI_ERROR=Build failed" >> $GITHUB_ENV
42+
fi
43+
44+
- name: Run Linting Checks
45+
id: lint-check
46+
run: |
47+
LINT_ERRORS=""
48+
LINT_PASSED=true
49+
50+
# Run TypeScript linting
51+
if ! npm run lint:ts; then
52+
LINT_PASSED=false
53+
LINT_ERRORS="${LINT_ERRORS}• TypeScript linting failed\n"
54+
fi
55+
56+
# Run Markdown linting
57+
if ! npm run lint:md; then
58+
LINT_PASSED=false
59+
LINT_ERRORS="${LINT_ERRORS}• Markdown linting failed\n"
60+
fi
61+
62+
# Check code formatting with Prettier
63+
if ! npm run format:check; then
64+
LINT_PASSED=false
65+
LINT_ERRORS="${LINT_ERRORS}• Code formatting issues detected\n"
66+
fi
67+
68+
echo "LINT_PASSED=$LINT_PASSED" >> $GITHUB_ENV
69+
echo "LINT_ERRORS<<EOF" >> $GITHUB_ENV
70+
echo -e "$LINT_ERRORS" >> $GITHUB_ENV
71+
echo "EOF" >> $GITHUB_ENV
72+
73+
- name: Generate PR Comment
74+
id: generate-comment
75+
run: |
76+
# Extract PR number
77+
PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
78+
79+
# Generate a temporary file for the comment
80+
COMMENT_FILE=$(mktemp)
81+
82+
# Save variables to GITHUB_OUTPUT
83+
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_OUTPUT
84+
echo "COMMENT_FILE=$COMMENT_FILE" >> $GITHUB_OUTPUT
85+
86+
# Generate content for the comment file
87+
{
88+
if [ "$CI_PASSED" = "true" ] && [ "$LINT_PASSED" = "true" ]; then
89+
echo "## 🎉 All Checks Passed!"
90+
echo ""
91+
echo "**Status:** ✅ Ready to merge"
92+
echo ""
93+
echo "### ✅ Completed Workflows"
94+
echo ""
95+
echo "| Workflow | Status | Details |"
96+
echo "|----------|--------|---------|"
97+
echo "| 🔨 **Continuous Integration** | ✅ Passed | Build completed successfully |"
98+
echo "| 📝 **Code Linting** | ✅ Passed | All formatting and style checks passed |"
99+
echo ""
100+
echo "---"
101+
echo ""
102+
echo "🚀 **This PR is ready for review and can be safely merged to \`main\` branch!**"
103+
echo ""
104+
echo "*Great work! Your code meets all quality standards.* 👏"
105+
else
106+
echo "## ❌ Checks Failed"
107+
echo ""
108+
echo "**Status:** 🚫 Not ready to merge"
109+
echo ""
110+
echo "Please fix the following issues before merging:"
111+
echo ""
112+
113+
if [ "$CI_PASSED" = "false" ]; then
114+
echo "### 🔨 Continuous Integration Failed"
115+
echo ""
116+
echo "**Issue:** The build process failed to complete."
117+
echo ""
118+
echo "**How to fix:**"
119+
echo "1. Run \`npm run build\` locally to identify the issue"
120+
echo "2. Fix any TypeScript compilation errors"
121+
echo "3. Ensure all dependencies are properly installed"
122+
echo "4. Test your changes before pushing"
123+
echo ""
124+
echo "---"
125+
echo ""
126+
fi
127+
128+
if [ "$LINT_PASSED" = "false" ]; then
129+
echo "### 📝 Code Linting Failed"
130+
echo ""
131+
echo "**Issue:** Code formatting or style violations detected."
132+
echo ""
133+
if [ -n "$LINT_ERRORS" ]; then
134+
echo "**Specific problems:**"
135+
echo ""
136+
echo -e "$LINT_ERRORS"
137+
echo ""
138+
fi
139+
echo "**How to fix:**"
140+
echo ""
141+
echo "| Platform | Command | Description |"
142+
echo "|----------|---------|-------------|"
143+
echo "| 🐧 **Unix/macOS/Linux** | \`npm run format\` | Auto-fix all formatting issues |"
144+
echo "| 🪟 **Windows** | \`npm run format:file <filename>\` | Fix specific files |"
145+
echo "| 🔍 **Check Only** | \`npm run format:check\` | Check formatting without fixing |"
146+
echo ""
147+
echo "**Need help with linting?** Check out the [Linting Guide for Windows Users](https://github.com/sugarlabs/www-v2/pull/12) for detailed instructions."
148+
echo ""
149+
echo "---"
150+
echo ""
151+
fi
152+
153+
echo "### 🛠️ Next Steps"
154+
echo ""
155+
echo "1. **Fix the issues** mentioned above"
156+
echo "2. **Test locally** to ensure everything works"
157+
echo "3. **Push your fixes** to this branch"
158+
echo "4. **Wait for re-check** - This bot will automatically run again"
159+
echo ""
160+
echo "> 🤖 *This comment will be updated automatically when you push new commits*"
161+
fi
162+
} > "$COMMENT_FILE"
163+
164+
- name: Comment on PR
165+
uses: thollander/actions-comment-pull-request@v3
166+
with:
167+
file-path: ${{ steps.generate-comment.outputs.COMMENT_FILE }}
168+
pr-number: ${{ steps.generate-comment.outputs.PR_NUMBER }}
169+
github-token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)