Skip to content

πŸ”€ FF Merge

πŸ”€ FF Merge #9

name: fast-forward-merger
run-name: 'πŸ”€ FF Merge'
on:
issue_comment:
types:
- created
permissions:
contents: read
jobs:
comment_checks:
name: Check FF-Merge Conditions
runs-on: ubuntu-latest
permissions:
contents: read
issues: read
outputs:
valid_commenter: ${{ steps.ff_merge_check_valid_commenter.outputs.valid_commenter }}
valid_comment: ${{ steps.ff_merge_check_comment_content.outputs.valid_comment }}
valid_label: ${{ steps.ff_merge_check_issue_labels.outputs.valid_label }}
steps:
- name: Debug Event
uses: actions/[email protected]
with:
script: |
console.log("%O", `${{ github.event }}`);
console.log("GH_CTX_EVENT:", `${{ github.event }}`);
console.log("GH_CTX_ISSUE_COMMENT:", ${{ github.event.pull_request }});
console.log("GS_CTX_PAYLOAD :", context.payload);
- name: Check Comment Author πŸ•΅οΈ
id: ff_merge_check_valid_commenter
uses: actions/[email protected]
with:
script: |
const commentAuthorAssociation = context.payload.comment.author_association;
const isMember = commentAuthorAssociation === 'MEMBER';
if (isMember) {
core.info('βœ… The comment author is a member of the organization.');
} else {
core.warning('❌ The comment author is not a member of the organization.');
}
core.debug('COMMENT_AUTHOR:', commentAuthorAssociation);
core.setOutput('valid_commenter', isMember);
- name: Check Comment Content πŸ“
id: ff_merge_check_comment_content
if: ${{ steps.ff_merge_check_valid_commenter.outputs.valid_commenter }}
uses: actions/[email protected]
with:
script: |
const commentBody = context.payload.comment.body;
const isValidComment = commentBody === '/ff-merge';
if (isValidComment) {
core.info('βœ… The comment content is valid.');
} else {
core.warning('❌ The comment content is invalid. (Expected: /ff-merge)');
}
core.debug('COMMENT_BODY:', commentBody);
core.setOutput('valid_comment', isValidComment);
- name: Check Issue Labels 🏷️
id: ff_merge_check_issue_labels
if: ${{ steps.ff_merge_check_comment_content.outputs.valid_comment }}
uses: actions/[email protected]
with:
script: |
const issueLabels = context.payload.issue.labels;
const hasFFMergeLabel = issueLabels.some((label) => label.name === 'ff-merge');
if (hasFFMergeLabel) {
core.info('βœ… The issue has the "ff-merge" label.');
} else {
core.warning('❌ The issue does not have the "ff-merge" label.');
}
core.debug('ISSUE_LABELS:', issueLabels.map((label) => label.name));
core.setOutput('valid_label', hasFFMergeLabel);
exec_ff_merge:
name: Execute Fast-Forward Merge
runs-on: ubuntu-latest
permissions:
contents: write
needs: comment_checks
if: ${{ needs.comment_checks.outputs.valid_commenter == 'true' && needs.comment_checks.outputs.valid_comment == 'true' && needs.comment_checks.outputs.valid_label == 'true' }}
steps:
- name: Lock PR πŸ”’
id: lock_pr
uses: actions/[email protected]
with:
script: |
try {
await github.rest.issues.lock({
'owner': context.repo.owner,
'repo': context.repo.repo,
'issue_number': context.issue.number,
'lock_reason': 'resolved',
});
console.info('PR locked:', context.payload.issue.html_url);
} catch (err) {
console.error('Error locking PR:', err);
core.setFailed(`Action failed with error ${err}`);
}
- name: Fast-Forward Merge πŸš€
if: ${{ success() }}
run: |
echo "βœ… Fast-Forward Merge completed."
echo "BASE_REF: ${{ github.base_ref }}"
echo "HEAD_REF: ${{ github.event.pull_request.head.ref }}"