1+ name : CCOA
2+
3+ on :
4+ pull_request_target :
5+ types :
6+ - opened
7+ - reopened
8+ branches :
9+ - main
10+
11+ permissions :
12+ pull-requests : write
13+
14+ jobs :
15+ add_label_and_comment :
16+ runs-on : ubuntu-latest
17+
18+ steps :
19+ - name : Check current date securely
20+ id : date_check
21+ run : |
22+ # Define the block date (Jan 7, 2025)
23+ BLOCK_DATE=$(date -d "2025-01-07" +%s)
24+
25+ # Get the current date in seconds
26+ CURRENT_DATE=$(date +%s)
27+
28+ # Validate the dates and safely output the result
29+ if [ "$CURRENT_DATE" -lt "$BLOCK_DATE" ]; then
30+ echo "continue=true" >> "$GITHUB_OUTPUT"
31+ else
32+ echo "continue=false" >> "$GITHUB_OUTPUT"
33+ fi
34+
35+ - name : Add do-not-merge label
36+ if : steps.date_check.outputs.continue == 'true'
37+ uses : actions/github-script@v7
38+ with :
39+ github-token : ${{ secrets.GITHUB_TOKEN }}
40+ script : |
41+ github.rest.issues.addLabels({
42+ owner: context.repo.owner,
43+ repo: context.repo.repo,
44+ issue_number: context.issue.number,
45+ labels: ["do-not-merge"],
46+ })
47+
48+ - name : Comment on PR
49+ if : steps.date_check.outputs.continue == 'true'
50+ uses : actions/github-script@v7
51+ with :
52+ github-token : ${{ secrets.GITHUB_TOKEN }}
53+ script : |
54+ // Fetch existing comments
55+ const comments = await github.rest.issues.listComments({
56+ owner: context.repo.owner,
57+ repo: context.repo.repo,
58+ issue_number: context.issue.number,
59+ });
60+
61+ // Check if the specific comment already exists
62+ const existingComment = comments.data.find(comment =>
63+ comment.body.includes("🚫All pull requests will be blocked to merge until Jan 6, 2025 due to CCOA")
64+ );
65+
66+ if (existingComment) {
67+ console.log("Comment already exists. Skipping...");
68+ } else {
69+ console.log("No comment found. Adding a new one...");
70+ // Add a new comment
71+ await github.rest.issues.createComment({
72+ owner: context.repo.owner,
73+ repo: context.repo.repo,
74+ issue_number: context.issue.number,
75+ body: "🚫All pull requests will be blocked to merge until Jan 6, 2025 due to CCOA",
76+ });
77+ }
0 commit comments