Skip to content

Commit a5c9935

Browse files
committed
improved workflows
1 parent efcbad2 commit a5c9935

File tree

10 files changed

+48
-10
lines changed

10 files changed

+48
-10
lines changed

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
blank_issues_enabled: false
2+

.github/pull_request_template.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@
2525
- [ ] My code follows the project's style guidelines
2626
- [ ] I have performed a self-review of my code
2727
- [ ] I have updated the README.md if applicable
28+

.github/workflows/fanex-id-bot.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ jobs:
2323
with:
2424
github-token: ${{ secrets.GITHUB_TOKEN }}
2525
enabled: true
26+

.github/workflows/housekeeping.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,4 @@ jobs:
6969
}
7070
}
7171
console.log(`Deleted ${deletedCount} orphaned caches`);
72+

.github/workflows/pr-assistant.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,4 @@ jobs:
8686
repo: context.repo.repo,
8787
body: `🎉 **Thank you @${author}!**\n\nYour contribution to the **faneX-ID GitHub Bot** repository is valuable! 🚀`
8888
});
89+

.github/workflows/pr-autofix.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ jobs:
3939
git commit -m "style: auto-fix linting issues [skip ci]"
4040
git push origin HEAD:${{ github.head_ref }}
4141
fi
42+

.github/workflows/pr-thanks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ jobs:
2525
repo: context.repo.repo,
2626
body: `🎉 **Thank you @${author}!**\n\nYour contribution to the **faneX-ID GitHub Bot** repository is valuable! 🚀`
2727
})
28+

.github/workflows/pr-validation.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,4 @@ jobs:
7373
body: "❌ **PR Validation Failed**\n\nPlease check the logs and fix the issues."
7474
});
7575
}
76+

bot.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,12 @@ def post_pr_summary(self, pr_number: int, force_update: bool = False) -> None:
315315
status = self.workflow_manager.get_workflow_status(pr.head.sha, pr.head.ref)
316316

317317
# Check if all checks truly passed (including branch workflows)
318-
all_passed, details = self.workflow_manager.are_all_checks_passed(pr.head.sha, pr.head.ref)
318+
# Exclude bot workflow from the check if it failed (bot can fail but other checks should pass)
319+
all_passed, details = self.workflow_manager.are_all_checks_passed(
320+
pr.head.sha,
321+
pr.head.ref,
322+
exclude_workflows=["faneX-ID Bot"] # Exclude bot workflow from merge check
323+
)
319324

320325
# Check if we already posted a summary
321326
comments = pr.get_issue_comments()
@@ -341,6 +346,19 @@ def post_pr_summary(self, pr_number: int, force_update: bool = False) -> None:
341346
pr.create_issue_comment(summary)
342347
print(f"✅ Created new PR summary comment on PR #{pr_number}")
343348

349+
# Auto-merge if all checks passed (excluding bot workflow)
350+
if all_passed and pr.mergeable and not pr.merged:
351+
try:
352+
# Check if PR is in a mergeable state
353+
if pr.state == "open":
354+
# Attempt to merge
355+
pr.merge(merge_method="squash", commit_message=f"Auto-merge: {pr.title}")
356+
print(f"✅ Auto-merged PR #{pr_number}")
357+
pr.create_issue_comment("🤖 **Auto-merged by faneX-ID Bot** - All checks passed successfully!")
358+
except Exception as e:
359+
print(f"⚠️ Could not auto-merge PR #{pr_number}: {e}")
360+
# Don't fail the workflow if merge fails (might be due to branch protection, etc.)
361+
344362

345363
def main():
346364
"""Main entry point for the bot."""

workflow_manager.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def get_workflow_status(self, sha: str, branch: str = None) -> Dict:
116116
"workflows": list(workflows.values()),
117117
}
118118

119-
def are_all_checks_passed(self, sha: str, branch: str = None) -> Tuple[bool, Dict]:
119+
def are_all_checks_passed(self, sha: str, branch: str = None, exclude_workflows: List[str] = None) -> Tuple[bool, Dict]:
120120
"""
121121
Check if all checks and workflows have passed for a commit and branch.
122122
@@ -128,10 +128,13 @@ def are_all_checks_passed(self, sha: str, branch: str = None) -> Tuple[bool, Dic
128128
Args:
129129
sha: Commit SHA
130130
branch: Optional branch name to also check workflows for the branch
131+
exclude_workflows: List of workflow names to exclude from the check
131132
132133
Returns:
133134
Tuple of (all_passed: bool, details: Dict)
134135
"""
136+
if exclude_workflows is None:
137+
exclude_workflows = []
135138
import requests
136139

137140
# Get checks for the SHA
@@ -170,24 +173,32 @@ def are_all_checks_passed(self, sha: str, branch: str = None) -> Tuple[bool, Dic
170173
combined_status == "success"
171174
)
172175

173-
# Check if all workflows passed
176+
# Check if all workflows passed (excluding specified workflows)
174177
workflows = workflow_status.get("workflows", [])
178+
# Filter out excluded workflows
179+
relevant_workflows = [
180+
w for w in workflows
181+
if w.get("name") not in exclude_workflows
182+
]
183+
175184
all_workflows_passed = (
176-
len(workflows) > 0 and
185+
len(relevant_workflows) > 0 and
177186
all(w.get("status") == "completed" and w.get("conclusion") == "success"
178-
for w in workflows)
187+
for w in relevant_workflows)
179188
)
180189

181-
# Check for running workflows
190+
# Check for running workflows (excluding excluded ones)
182191
running_workflows = [
183192
w for w in workflows
184-
if w.get("status") in ["in_progress", "queued", "waiting"]
193+
if w.get("name") not in exclude_workflows
194+
and w.get("status") in ["in_progress", "queued", "waiting"]
185195
]
186196

187-
# Check for failed workflows
197+
# Check for failed workflows (excluding excluded ones)
188198
failed_workflows = [
189199
w for w in workflows
190-
if w.get("status") == "completed" and w.get("conclusion") == "failure"
200+
if w.get("name") not in exclude_workflows
201+
and w.get("status") == "completed" and w.get("conclusion") == "failure"
191202
]
192203

193204
# Check for pending checks
@@ -221,8 +232,9 @@ def are_all_checks_passed(self, sha: str, branch: str = None) -> Tuple[bool, Dic
221232
"pending_checks": pending_checks,
222233
"failed_checks": failed_checks,
223234
"total_checks": len(check_runs),
224-
"total_workflows": len(workflows),
235+
"total_workflows": len(relevant_workflows),
225236
"combined_status": combined_status,
237+
"excluded_workflows": exclude_workflows,
226238
}
227239

228240
return (truly_all_passed, details)

0 commit comments

Comments
 (0)