@@ -156,34 +156,32 @@ jobs:
156156 with :
157157 github-token : ${{ secrets.GITHUB_TOKEN }}
158158 script : |
159- const pages = 5;
159+ const MAX_PAGES = 20;
160+ const PER_PAGE = 100;
160161 let runs_to_delete = [];
161- console.log(`🔍 Scanning for workflow runs triggered by User 'dependabot[bot]'...`);
162- // 1. List ALL workflow runs in the repo, filtered by actor
163- for (let page = 1; page <= pages; page++) {
162+ console.log("🔍 Scanning workflow runs...");
163+ for (let page = 1; page <= MAX_PAGES; page++) {
164164 const response = await github.rest.actions.listWorkflowRunsForRepo({
165165 owner: context.repo.owner,
166166 repo: context.repo.repo,
167- page: page,
168- per_page: 50,
169- actor: 'dependabot[bot]'
167+ per_page: PER_PAGE,
168+ page: page
170169 });
171- if (!response.data.workflow_runs || response.data.workflow_runs.length === 0) {
172- break;
173- }
174- for (const run of response.data.workflow_runs) {
175- runs_to_delete.push([run.id, run.name, run.workflow_id]);
170+ const runs = response.data.workflow_runs;
171+ if (!runs || runs.length === 0) break;
172+ for (const run of runs) {
173+ if (run.actor?.login === "dependabot[bot]") {
174+ runs_to_delete.push([run.id, run.name]);
175+ }
176176 }
177- // If we got fewer than 50, we are on the last page
178- if (response.data.workflow_runs.length < 50) break;
177+ if (runs.length < PER_PAGE) break;
179178 }
180179 if (runs_to_delete.length === 0) {
181- console.log(` ✅ No Dependabot workflow runs found.` );
180+ console.log(" ✅ No Dependabot runs found." );
182181 return;
183182 }
184183 console.log(`🗑️ Found ${runs_to_delete.length} runs to delete.`);
185- // 2. Delete workflow runs
186- for (const [runId, runName, workflowId] of runs_to_delete) {
184+ for (const [runId, runName] of runs_to_delete) {
187185 console.log(`[Deleting] Run #${runId} (${runName})`);
188186 try {
189187 await github.rest.actions.deleteWorkflowRun({
@@ -195,4 +193,4 @@ jobs:
195193 console.warn(`⚠️ Failed to delete run ${runId}: ${error.message}`);
196194 }
197195 }
198- console.log(` ✅ Cleanup complete.` );
196+ console.log(" ✅ Cleanup complete." );
0 commit comments