@@ -83,27 +83,58 @@ jobs:
8383 const uniqueLabels = [...new Set(labelsToAdd)];
8484
8585 if (uniqueLabels.length > 0) {
86- console.log(`Adding labels: ${uniqueLabels.join(', ')}`);
87-
88- // Add labels to PR
89- await github.rest.issues.addLabels({
86+ // Get current labels to avoid re-adding
87+ const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({
9088 owner: context.repo.owner,
9189 repo: context.repo.repo,
9290 issue_number: context.issue.number,
93- labels: uniqueLabels
9491 });
9592
93+ const currentLabelNames = new Set(currentLabels.map(l => l.name));
94+ const labelsToActuallyAdd = uniqueLabels.filter(label => !currentLabelNames.has(label));
95+
96+ if (labelsToActuallyAdd.length > 0) {
97+ console.log(`Adding new labels: ${labelsToActuallyAdd.join(', ')}`);
98+
99+ // Add labels to PR
100+ await github.rest.issues.addLabels({
101+ owner: context.repo.owner,
102+ repo: context.repo.repo,
103+ issue_number: context.issue.number,
104+ labels: labelsToActuallyAdd
105+ });
106+ } else {
107+ console.log('All labels already present, no changes needed');
108+ }
109+
96110 // Only comment when PR is first opened (not on every update)
97111 if (context.payload.action === 'opened') {
98- const typesList = Array.from(types).filter(t => t !== 'breaking').join(', ');
99- const breakingNote = types.has('breaking') ? '\n\n⚠️ **This PR contains breaking changes!**' : '';
100-
101- await github.rest.issues.createComment({
112+ // Check if we've already commented
113+ const { data: comments } = await github.rest.issues.listComments({
102114 owner: context.repo.owner,
103115 repo: context.repo.repo,
104116 issue_number: context.issue.number,
105- body: `🏷️ Auto-labeled based on commits: \`${typesList}\`${breakingNote}`
106117 });
118+
119+ const botCommentExists = comments.some(comment =>
120+ comment.user.type === 'Bot' &&
121+ comment.body.includes('🏷️ Auto-labeled based on commits:')
122+ );
123+
124+ if (!botCommentExists) {
125+ const typesList = Array.from(types).filter(t => t !== 'breaking').join(', ');
126+ const breakingNote = types.has('breaking') ? '\n\n⚠️ **This PR contains breaking changes!**' : '';
127+
128+ console.log('Posting auto-label summary comment');
129+ await github.rest.issues.createComment({
130+ owner: context.repo.owner,
131+ repo: context.repo.repo,
132+ issue_number: context.issue.number,
133+ body: `🏷️ Auto-labeled based on commits: \`${typesList}\`${breakingNote}`
134+ });
135+ } else {
136+ console.log('Auto-label comment already exists, skipping');
137+ }
107138 } else {
108139 console.log('Labels updated (no comment on synchronize/reopened to reduce noise)');
109140 }
@@ -141,31 +172,40 @@ jobs:
141172
142173 console.log(`PR size: ${total} lines (${additions} additions, ${deletions} deletions) → ${sizeLabel}`);
143174
144- // Remove old size labels
175+ // Get current labels
145176 const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({
146177 owner: context.repo.owner,
147178 repo: context.repo.repo,
148179 issue_number: context.issue.number,
149180 });
150181
151- for (const label of currentLabels) {
152- if (label.name.startsWith('size/')) {
153- await github.rest.issues.removeLabel({
154- owner: context.repo.owner,
155- repo: context.repo.repo,
156- issue_number: context.issue.number,
157- name: label.name,
158- }).catch(() => {});
182+ const currentSizeLabel = currentLabels.find(l => l.name.startsWith('size/'))?.name;
183+
184+ // Only update if size label changed
185+ if (currentSizeLabel === sizeLabel) {
186+ console.log(`Size label ${sizeLabel} already correct, no change needed`);
187+ } else {
188+ // Remove old size labels
189+ for (const label of currentLabels) {
190+ if (label.name.startsWith('size/')) {
191+ await github.rest.issues.removeLabel({
192+ owner: context.repo.owner,
193+ repo: context.repo.repo,
194+ issue_number: context.issue.number,
195+ name: label.name,
196+ }).catch(() => {});
197+ }
159198 }
160- }
161199
162- // Add new size label
163- await github.rest.issues.addLabels({
164- owner: context.repo.owner,
165- repo: context.repo.repo,
166- issue_number: context.issue.number,
167- labels: [sizeLabel]
168- });
200+ // Add new size label
201+ console.log(`Updating size label: ${currentSizeLabel || 'none'} → ${sizeLabel}`);
202+ await github.rest.issues.addLabels({
203+ owner: context.repo.owner,
204+ repo: context.repo.repo,
205+ issue_number: context.issue.number,
206+ labels: [sizeLabel]
207+ });
208+ }
169209
170210 - name : Hacktoberfest auto-accept
171211 uses : actions/github-script@v7
@@ -193,23 +233,52 @@ jobs:
193233 const hasPreviousContributions = searchResults.total_count > 0;
194234
195235 if (hasPreviousContributions) {
196- console.log(`${author} is a previous contributor - adding hacktoberfest-accepted label `);
236+ console.log(`${author} is a previous contributor`);
197237
198- await github.rest.issues.addLabels({
238+ // Check if label already exists
239+ const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({
199240 owner: context.repo.owner,
200241 repo: context.repo.repo,
201242 issue_number: context.issue.number,
202- labels: ['hacktoberfest-accepted']
203243 });
204244
205- // Only comment on first opened
206- if (context.payload.action === 'opened') {
207- await github.rest.issues.createComment({
245+ const hasHacktoberfestLabel = currentLabels.some(l => l.name === 'hacktoberfest-accepted');
246+
247+ if (!hasHacktoberfestLabel) {
248+ console.log('Adding hacktoberfest-accepted label');
249+
250+ await github.rest.issues.addLabels({
208251 owner: context.repo.owner,
209252 repo: context.repo.repo,
210253 issue_number: context.issue.number,
211- body: '🎃 **Happy Hacktoberfest!** Thank you for being a returning contributor. Your PR has been automatically accepted for Hacktoberfest.'
254+ labels: ['hacktoberfest- accepted']
212255 });
256+
257+ // Check if we've already commented about Hacktoberfest
258+ const { data: comments } = await github.rest.issues.listComments({
259+ owner: context.repo.owner,
260+ repo: context.repo.repo,
261+ issue_number: context.issue.number,
262+ });
263+
264+ const hacktoberfestCommentExists = comments.some(comment =>
265+ comment.user.type === 'Bot' &&
266+ comment.body.includes('Happy Hacktoberfest!')
267+ );
268+
269+ if (!hacktoberfestCommentExists && context.payload.action === 'opened') {
270+ console.log('Posting Hacktoberfest welcome comment');
271+ await github.rest.issues.createComment({
272+ owner: context.repo.owner,
273+ repo: context.repo.repo,
274+ issue_number: context.issue.number,
275+ body: '🎃 **Happy Hacktoberfest!** Thank you for being a returning contributor. Your PR has been automatically accepted for Hacktoberfest.'
276+ });
277+ } else {
278+ console.log('Hacktoberfest comment already exists or not first opened, skipping');
279+ }
280+ } else {
281+ console.log('Hacktoberfest label already present');
213282 }
214283 } else {
215284 console.log(`${author} is a new contributor - manual review required for Hacktoberfest`);
0 commit comments