mirror of
https://github.com/laoxong/nofx.git
synced 2026-06-04 09:58:22 +08:00
Fix PR check
This commit is contained in:
@@ -104,6 +104,53 @@ jobs:
|
||||
echo "⚠️ Frontend results artifact not found"
|
||||
fi
|
||||
|
||||
- name: Get PR information
|
||||
id: pr-info
|
||||
if: steps.backend.outputs.pr_number != '0'
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const prNumber = ${{ steps.backend.outputs.pr_number }};
|
||||
|
||||
// Get PR details
|
||||
const { data: pr } = await github.rest.pulls.get({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
pull_number: prNumber
|
||||
});
|
||||
|
||||
// Check PR title format (Conventional Commits)
|
||||
const prTitle = pr.title;
|
||||
const conventionalCommitPattern = /^(feat|fix|docs|style|refactor|perf|test|chore|ci|security|build)(\(.+\))?: .+/;
|
||||
const titleValid = conventionalCommitPattern.test(prTitle);
|
||||
|
||||
core.setOutput('pr_title', prTitle);
|
||||
core.setOutput('title_valid', titleValid);
|
||||
|
||||
// Calculate PR size
|
||||
const additions = pr.additions;
|
||||
const deletions = pr.deletions;
|
||||
const total = additions + deletions;
|
||||
|
||||
let size = '';
|
||||
let sizeEmoji = '';
|
||||
if (total < 300) {
|
||||
size = 'Small';
|
||||
sizeEmoji = '🟢';
|
||||
} else if (total < 1000) {
|
||||
size = 'Medium';
|
||||
sizeEmoji = '🟡';
|
||||
} else {
|
||||
size = 'Large';
|
||||
sizeEmoji = '🔴';
|
||||
}
|
||||
|
||||
core.setOutput('pr_size', size);
|
||||
core.setOutput('size_emoji', sizeEmoji);
|
||||
core.setOutput('total_lines', total);
|
||||
core.setOutput('additions', additions);
|
||||
core.setOutput('deletions', deletions);
|
||||
|
||||
- name: Post advisory results comment
|
||||
if: steps.backend.outputs.pr_number != '0'
|
||||
uses: actions/github-script@v7
|
||||
@@ -113,7 +160,40 @@ jobs:
|
||||
|
||||
let comment = '## 🤖 Advisory Check Results\n\n';
|
||||
comment += 'These are **advisory** checks to help improve code quality. They won\'t block your PR from being merged.\n\n';
|
||||
comment += '> **Note:** PR title and size checks are handled by the main workflow and may appear in a separate comment.\n\n';
|
||||
|
||||
// PR Information section
|
||||
const prTitle = '${{ steps.pr-info.outputs.pr_title }}';
|
||||
const titleValid = '${{ steps.pr-info.outputs.title_valid }}' === 'true';
|
||||
const prSize = '${{ steps.pr-info.outputs.pr_size }}';
|
||||
const sizeEmoji = '${{ steps.pr-info.outputs.size_emoji }}';
|
||||
const totalLines = '${{ steps.pr-info.outputs.total_lines }}';
|
||||
const additions = '${{ steps.pr-info.outputs.additions }}';
|
||||
const deletions = '${{ steps.pr-info.outputs.deletions }}';
|
||||
|
||||
comment += '### 📋 PR Information\n\n';
|
||||
|
||||
// Title check
|
||||
if (titleValid) {
|
||||
comment += '**Title Format:** ✅ Good - Follows Conventional Commits\n';
|
||||
} else {
|
||||
comment += '**Title Format:** ⚠️ Suggestion - Consider using `type(scope): description`\n';
|
||||
comment += '<details><summary>Recommended format</summary>\n\n';
|
||||
comment += '**Valid types:** `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `chore`, `ci`, `security`, `build`\n\n';
|
||||
comment += '**Examples:**\n';
|
||||
comment += '- `feat(trader): add new trading strategy`\n';
|
||||
comment += '- `fix(api): resolve authentication issue`\n';
|
||||
comment += '- `docs: update README`\n';
|
||||
comment += '</details>\n\n';
|
||||
}
|
||||
|
||||
// Size check
|
||||
comment += `**PR Size:** ${sizeEmoji} ${prSize} (${totalLines} lines: +${additions} -${deletions})\n`;
|
||||
|
||||
if (prSize === 'Large') {
|
||||
comment += '\n💡 **Suggestion:** This is a large PR. Consider breaking it into smaller, focused PRs for easier review.\n';
|
||||
}
|
||||
|
||||
comment += '\n';
|
||||
|
||||
// Backend checks
|
||||
const fmtStatus = '${{ steps.backend.outputs.fmt_status }}';
|
||||
@@ -208,37 +288,71 @@ jobs:
|
||||
return;
|
||||
}
|
||||
|
||||
const prNumber = pulls.data[0].number;
|
||||
const pr = pulls.data[0];
|
||||
const prNumber = pr.number;
|
||||
|
||||
const comment = [
|
||||
'## ⚠️ Advisory Checks - Results Unavailable',
|
||||
'',
|
||||
'The advisory checks workflow completed, but results could not be retrieved.',
|
||||
'',
|
||||
'### Possible reasons:',
|
||||
'- Artifacts were not uploaded successfully',
|
||||
'- Artifacts expired (retention: 1 day)',
|
||||
'- Permission issues',
|
||||
'',
|
||||
'### What to do:',
|
||||
'1. Check the [PR Checks - Run workflow](${{ github.event.workflow_run.html_url }}) logs',
|
||||
'2. Ensure your code passes local checks:',
|
||||
'```bash',
|
||||
'# Backend',
|
||||
'go fmt ./...',
|
||||
'go vet ./...',
|
||||
'go build',
|
||||
'go test ./...',
|
||||
'',
|
||||
'# Frontend (if applicable)',
|
||||
'cd web',
|
||||
'npm run build',
|
||||
'```',
|
||||
'',
|
||||
'---',
|
||||
'',
|
||||
'*This is an automated fallback message. The advisory checks ran but results are not available.*'
|
||||
].join('\n');
|
||||
// Get PR information for fallback comment
|
||||
const prTitle = pr.title;
|
||||
const conventionalCommitPattern = /^(feat|fix|docs|style|refactor|perf|test|chore|ci|security|build)(\(.+\))?: .+/;
|
||||
const titleValid = conventionalCommitPattern.test(prTitle);
|
||||
|
||||
const additions = pr.additions || 0;
|
||||
const deletions = pr.deletions || 0;
|
||||
const total = additions + deletions;
|
||||
|
||||
let size = '';
|
||||
let sizeEmoji = '';
|
||||
if (total < 300) {
|
||||
size = 'Small';
|
||||
sizeEmoji = '🟢';
|
||||
} else if (total < 1000) {
|
||||
size = 'Medium';
|
||||
sizeEmoji = '🟡';
|
||||
} else {
|
||||
size = 'Large';
|
||||
sizeEmoji = '🔴';
|
||||
}
|
||||
|
||||
let comment = '## ⚠️ Advisory Checks - Results Unavailable\n\n';
|
||||
comment += 'The advisory checks workflow completed, but results could not be retrieved.\n\n';
|
||||
|
||||
// Add PR Information
|
||||
comment += '### 📋 PR Information\n\n';
|
||||
|
||||
if (titleValid) {
|
||||
comment += '**Title Format:** ✅ Good - Follows Conventional Commits\n';
|
||||
} else {
|
||||
comment += '**Title Format:** ⚠️ Suggestion - Consider using `type(scope): description`\n';
|
||||
}
|
||||
|
||||
comment += `**PR Size:** ${sizeEmoji} ${size} (${total} lines: +${additions} -${deletions})\n\n`;
|
||||
|
||||
if (size === 'Large') {
|
||||
comment += '💡 **Suggestion:** This is a large PR. Consider breaking it into smaller, focused PRs for easier review.\n\n';
|
||||
}
|
||||
|
||||
comment += '---\n\n';
|
||||
comment += '### ⚠️ Backend/Frontend Check Results\n\n';
|
||||
comment += 'Results could not be retrieved.\n\n';
|
||||
comment += '**Possible reasons:**\n';
|
||||
comment += '- Artifacts were not uploaded successfully\n';
|
||||
comment += '- Artifacts expired (retention: 1 day)\n';
|
||||
comment += '- Permission issues\n\n';
|
||||
comment += '**What to do:**\n';
|
||||
comment += `1. Check the [PR Checks - Run workflow](${context.payload.workflow_run?.html_url || 'logs'}) logs\n`;
|
||||
comment += '2. Ensure your code passes local checks:\n';
|
||||
comment += '```bash\n';
|
||||
comment += '# Backend\n';
|
||||
comment += 'go fmt ./...\n';
|
||||
comment += 'go vet ./...\n';
|
||||
comment += 'go build\n';
|
||||
comment += 'go test ./...\n\n';
|
||||
comment += '# Frontend (if applicable)\n';
|
||||
comment += 'cd web\n';
|
||||
comment += 'npm run build\n';
|
||||
comment += '```\n\n';
|
||||
comment += '---\n\n';
|
||||
comment += '*This is an automated fallback message. The advisory checks ran but results are not available.*';
|
||||
|
||||
await github.rest.issues.createComment({
|
||||
issue_number: prNumber,
|
||||
|
||||
Reference in New Issue
Block a user