1313# - GITHUB_REPOSITORY_OWNER: Owner of the repository
1414# - GITHUB_REPOSITORY_NAME: Name of the repository
1515# - GH_TOKEN: GitHub token for API access
16+ # - DRY_RUN: Set to "true" to only print what would happen without making changes (optional)
1617
1718# Calculate cutoff dates
1819SECONDS_IN_DAY=86400
@@ -22,6 +23,11 @@ CLOSE_CUTOFF=$(date -u -d "@$(($(date +%s) - (STALE_DAYS + WARNING_DAYS) * SECON
2223echo " Stale cutoff (for warnings): $STALE_CUTOFF "
2324echo " Close cutoff (for closing): $CLOSE_CUTOFF "
2425
26+ if [ " $DRY_RUN " = " true" ]; then
27+ echo " "
28+ echo " *** DRY RUN MODE - No actual changes will be made ***"
29+ fi
30+
2531# Debug: Check token permissions
2632echo " "
2733echo " Checking GitHub token permissions..."
@@ -78,19 +84,23 @@ cat discussions.json | jq -r --arg warningCutoff "$CLOSE_CUTOFF" '.data.reposito
7884 echo " Discussion #$DISCUSSION_NUMBER : $DISCUSSION_TITLE "
7985 echo " URL: $DISCUSSION_URL "
8086 echo " Last updated: $DISCUSSION_UPDATED "
81- echo " Action: Closing and locking"
87+ if [ " $DRY_RUN " = " true" ]; then
88+ echo " Action: Would close and lock (DRY RUN)"
89+ else
90+ echo " Action: Closing and locking"
8291
83- # Step 1: Add a closing comment explaining why the discussion was closed
84- echo " Adding close comment..."
85- gh api graphql -f query=' mutation($discussionId: ID!, $body: String!) { addDiscussionComment(input: {discussionId: $discussionId, body: $body}) { comment { id } } }' -f discussionId=" $DISCUSSION_ID " -f body=" $CLOSE_MESSAGE "
92+ # Step 1: Add a closing comment explaining why the discussion was closed
93+ echo " Adding close comment..."
94+ gh api graphql -f query=' mutation($discussionId: ID!, $body: String!) { addDiscussionComment(input: {discussionId: $discussionId, body: $body}) { comment { id } } }' -f discussionId=" $DISCUSSION_ID " -f body=" $CLOSE_MESSAGE "
8695
87- # Step 2: Close the discussion
88- echo " Closing discussion..."
89- gh api graphql -f query=' mutation($discussionId: ID!) { closeDiscussion(input: {discussionId: $discussionId}) { discussion { id } } }' -f discussionId=" $DISCUSSION_ID "
96+ # Step 2: Close the discussion
97+ echo " Closing discussion..."
98+ gh api graphql -f query=' mutation($discussionId: ID!) { closeDiscussion(input: {discussionId: $discussionId}) { discussion { id } } }' -f discussionId=" $DISCUSSION_ID "
9099
91- # Step 3: Lock the discussion to prevent further comments
92- echo " Locking discussion..."
93- gh api graphql -f query=' mutation($discussionId: ID!) { lockLockable(input: {lockableId: $discussionId}) { lockedRecord { locked } } }' -f discussionId=" $DISCUSSION_ID "
100+ # Step 3: Lock the discussion to prevent further comments
101+ echo " Locking discussion..."
102+ gh api graphql -f query=' mutation($discussionId: ID!) { lockLockable(input: {lockableId: $discussionId}) { lockedRecord { locked } } }' -f discussionId=" $DISCUSSION_ID "
103+ fi
94104
95105 echo " "
96106 fi
@@ -115,11 +125,15 @@ cat discussions.json | jq -r --arg staleCutoff "$STALE_CUTOFF" '.data.repository
115125 echo " Discussion #$DISCUSSION_NUMBER : $DISCUSSION_TITLE "
116126 echo " URL: $DISCUSSION_URL "
117127 echo " Last updated: $DISCUSSION_UPDATED "
118- echo " Action: Adding warning comment"
119-
120- # Add a warning comment to the discussion
121- echo " Adding warning comment..."
122- gh api graphql -f query=' mutation($discussionId: ID!, $body: String!) { addDiscussionComment(input: {discussionId: $discussionId, body: $body}) { comment { id } } }' -f discussionId=" $DISCUSSION_ID " -f body=" $WARNING_MESSAGE "
128+ if [ " $DRY_RUN " = " true" ]; then
129+ echo " Action: Would add warning comment (DRY RUN)"
130+ else
131+ echo " Action: Adding warning comment"
132+
133+ # Add a warning comment to the discussion
134+ echo " Adding warning comment..."
135+ gh api graphql -f query=' mutation($discussionId: ID!, $body: String!) { addDiscussionComment(input: {discussionId: $discussionId, body: $body}) { comment { id } } }' -f discussionId=" $DISCUSSION_ID " -f body=" $WARNING_MESSAGE "
136+ fi
123137
124138 echo " "
125139 fi
0 commit comments