-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (115 loc) · 4.59 KB
/
ff-merge-merger.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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('GS_FULL_CTX:', context);
console.log('GS_CTX_PAYLOAD:', context.payload);
console.log('GS_CTX_REPO:', context.repo);
console.log('GH_CTX:', JSON.stringify(${{ github }}));
console.log('GH_CTX_EVENT:', JSON.stringify(${{ github.event }} ));
- 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
issues: write
pull-requests: 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 Inspection 🕵️
# id: ff_inspect
# if: ${{ success() }}
# uses: actions/[email protected]
# with:
# script: |
#
# - name: Fast-Forward Merge 🚀
# id: ff_merge
# if: ${{ success() }}
# run: |
# echo "✅ Fast-Forward Merge completed."
# git checkout origin/${{ github.base_ref }}
# git merge --ff-only origin/${{ github.event.pull_request.head.ref }}
# git push origin ${{ github.base_ref }}