Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions .github/workflows/agents-auto-pilot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ jobs:
if: steps.check_enabled.outputs.enabled == 'true'
uses: actions/checkout@v6

- name: Set up Node
if: steps.check_enabled.outputs.enabled == 'true'
uses: actions/setup-node@v6
with:
node-version: '20'

- name: Install GitHub API dependencies
if: steps.check_enabled.outputs.enabled == 'true'
run: npm install --no-save --no-package-lock @octokit/rest @octokit/auth-app

- name: Export load balancer tokens
if: steps.check_enabled.outputs.enabled == 'true'
uses: ./.github/actions/export-load-balancer-tokens
Expand All @@ -128,10 +138,17 @@ jobs:
uses: actions/github-script@v8
with:
script: |
const { data } = await github.rest.repos.get({
const { createTokenAwareRetry } = require('./.github/scripts/github-api-with-retry.js');
const { withRetry } = await createTokenAwareRetry({
github,
core,
task: 'auto-pilot-resolve-workflows-ref',
});

const { data } = await withRetry((client) => client.rest.repos.get({
owner: 'stranske',
repo: 'Workflows'
});
}));
if (!data?.default_branch) {
core.setFailed('Could not determine Workflows default branch');
return;
Expand Down
32 changes: 21 additions & 11 deletions .github/workflows/agents-bot-comment-handler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,38 @@ jobs:
sparse-checkout: |
.github/actions/export-load-balancer-tokens
.github/scripts/github-api-with-retry.js
.github/scripts/token_load_balancer.js
sparse-checkout-cone-mode: false
- name: Export load balancer tokens
uses: ./.github/actions/export-load-balancer-tokens
with:
github_token: ${{ github.token }}
token_rotation_json: ${{ secrets.TOKEN_ROTATION_JSON }}
token_rotation_env_keys: ${{ vars.TOKEN_ROTATION_ENV_KEYS }}
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: '20'
- name: Install GitHub API dependencies
run: npm install --no-save --no-package-lock @octokit/rest @octokit/auth-app
- name: Resolve PR number and check conditions
id: resolve
uses: actions/github-script@v8
with:
script: |
const fs = require('fs');
const retryHelperPath = './.github/scripts/github-api-with-retry.js';
const retryHelpers = fs.existsSync(retryHelperPath)
? require(retryHelperPath)
: {
withRetry: (fn) => fn(),
paginateWithRetry: (githubInstance, method, params) =>
githubInstance.paginate(method, params),
};
const { withRetry } = retryHelpers;
const retryHelpers = fs.existsSync(retryHelperPath) ? require(retryHelperPath) : null;
let withRetry = (fn) => fn();

Copilot AI Feb 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback withRetry function should pass the github instance as a parameter. The current implementation (fn) => fn() calls the function without arguments, but the updated code at lines 129 and 167 expects to receive a client parameter (e.g., (client) => client.rest.repos.get(...)). If the fallback is ever triggered due to a misconfiguration, it will fail with "Cannot read property 'rest' of undefined". Change the fallback to: let withRetry = (fn) => fn(github);

Suggested change
let withRetry = (fn) => fn();
let withRetry = (fn) => fn(github);

Copilot uses AI. Check for mistakes.
if (retryHelpers?.createTokenAwareRetry) {
({ withRetry } = await retryHelpers.createTokenAwareRetry({
github,
core,
task: 'bot-comment-handler',
}));
} else if (retryHelpers?.withRetry) {
({ withRetry } = retryHelpers);
}

const eventName = context.eventName;
let prNumber = null;
Expand Down Expand Up @@ -116,10 +126,10 @@ jobs:

let defaultBranch = context.payload.repository?.default_branch;
if (!defaultBranch) {
const repoResponse = await github.rest.repos.get({
const repoResponse = await withRetry((client) => client.rest.repos.get({
owner: context.repo.owner,
repo: context.repo.repo
});
}));
defaultBranch = repoResponse.data?.default_branch;
}
if (!defaultBranch) {
Expand Down Expand Up @@ -154,7 +164,7 @@ jobs:
// Check if PR has agent label
let pr;
try {
const response = await withRetry(() => github.rest.pulls.get({
const response = await withRetry((client) => client.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
Expand Down
35 changes: 28 additions & 7 deletions .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,41 @@ jobs:
- name: Checkout for API helpers
uses: actions/checkout@v6
with:
sparse-checkout: .github/scripts
sparse-checkout: |
.github/actions/export-load-balancer-tokens
.github/scripts/github-api-with-retry.js
.github/scripts/token_load_balancer.js
sparse-checkout-cone-mode: false

- name: Export load balancer tokens
uses: ./.github/actions/export-load-balancer-tokens
with:
github_token: ${{ github.token }}
token_rotation_json: ${{ secrets.TOKEN_ROTATION_JSON }}
token_rotation_env_keys: ${{ vars.TOKEN_ROTATION_ENV_KEYS }}

- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: '20'

- name: Install GitHub API dependencies
run: npm install --no-save --no-package-lock @octokit/rest @octokit/auth-app

- name: Resolve PR context
id: context
uses: actions/github-script@v8
with:
github-token: ${{ secrets.AGENTS_AUTOMATION_PAT || secrets.ACTIONS_BOT_PAT || github.token }}
script: |
const path = require('path');
const { paginateWithBackoff } = require(
path.join(process.env.GITHUB_WORKSPACE, '.github/scripts/api-helpers.js')
const { createTokenAwareRetry } = require(
'./.github/scripts/github-api-with-retry.js'
);
const { paginateWithRetry } = await createTokenAwareRetry({
github,
core,
task: 'autofix-loop-resolve-context',
});

const pr = context.payload.pull_request;
if (!pr) {
Expand Down Expand Up @@ -103,11 +125,10 @@ jobs:
const { owner, repo } = context.repo;
let files = [];
try {
files = await paginateWithBackoff(
github,
files = await paginateWithRetry(
github.rest.pulls.listFiles,
{ owner, repo, pull_number: pr.number, per_page: 100 },
{ maxRetries: 3, core }
{ maxRetries: 3 }
);
} catch (error) {
const message = String(error?.message || error || '');
Expand Down
79 changes: 56 additions & 23 deletions .github/workflows/pr-00-gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,23 @@ jobs:
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
ref: ${{ github.event.pull_request.head.sha || github.sha }}
sparse-checkout: |
.github/actions/export-load-balancer-tokens
.github/scripts
.github/config
tools
sparse-checkout-cone-mode: false
- name: Export load balancer tokens
uses: ./.github/actions/export-load-balancer-tokens
with:
github_token: ${{ github.token }}
token_rotation_json: ${{ secrets.TOKEN_ROTATION_JSON }}
token_rotation_env_keys: ${{ vars.TOKEN_ROTATION_ENV_KEYS }}
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: '20'
- name: Install GitHub API dependencies
run: npm install --no-save --no-package-lock @octokit/rest @octokit/auth-app
- name: Handle docs-only change
if: needs.detect.outputs.doc_only == 'true'
id: docs_only
Expand Down Expand Up @@ -416,6 +429,12 @@ jobs:
FAILURE_CHECKS: ${{ steps.summarize.outputs.failure_checks || '' }}
with:
script: |
const { createTokenAwareRetry } = require('./.github/scripts/github-api-with-retry.js');
const { withRetry, paginateWithRetry } = await createTokenAwareRetry({
github,
core,
task: 'gate-autofix-label',
});
const { owner, repo } = context.repo;
const pr = context.payload.pull_request;
core.setOutput('applied', 'false');
Expand Down Expand Up @@ -450,12 +469,15 @@ jobs:
return;
}

const iterator = github.paginate.iterator(github.rest.pulls.listFiles, {
owner,
repo,
pull_number: pr.number,
per_page: 100,
});
const files = await paginateWithRetry(
github.rest.pulls.listFiles,
{
owner,
repo,
pull_number: pr.number,
per_page: 100,
},
);

const allowedExtensions = String(process.env.ALLOWED_EXTENSIONS || '')
.split(',')
Expand All @@ -464,20 +486,15 @@ jobs:
.map(ext => (ext.startsWith('.') ? ext : `.${ext}`));

const disallowed = [];
for await (const page of iterator) {
if (!Array.isArray(page.data)) {
for (const file of files || []) {
const filename = file?.filename;
if (typeof filename !== 'string' || filename.length === 0) {
continue;
}
for (const file of page.data) {
const filename = file?.filename;
if (typeof filename !== 'string' || filename.length === 0) {
continue;
}
const lower = filename.toLowerCase();
const allowed = allowedExtensions.some(ext => lower.endsWith(ext));
if (!allowed) {
disallowed.push(filename);
}
const lower = filename.toLowerCase();
const allowed = allowedExtensions.some(ext => lower.endsWith(ext));
if (!allowed) {
disallowed.push(filename);
}
}

Expand All @@ -487,12 +504,12 @@ jobs:
return;
}

await github.rest.issues.addLabels({
await withRetry((client) => client.rest.issues.addLabels({
owner,
repo,
issue_number: pr.number,
labels: ['autofix:clean'],
});
}));
core.info('Applied autofix:clean label for cosmetic failure.');
core.setOutput('applied', 'true');

Expand Down Expand Up @@ -554,6 +571,12 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const { createTokenAwareRetry } = require('./.github/scripts/github-api-with-retry.js');
const { withRetry } = await createTokenAwareRetry({
github,
core,
task: 'gate-keepalive-checklist',
});
const prNumber = Number(process.env.PR_NUMBER || '0');
const payloadBody = context.payload.pull_request?.body || '';

Expand All @@ -566,7 +589,11 @@ jobs:
if (!prBody && prNumber) {
const { owner, repo } = context.repo;
try {
const pr = await github.rest.pulls.get({ owner, repo, pull_number: prNumber });
const pr = await withRetry((client) => client.rest.pulls.get({
owner,
repo,
pull_number: prNumber
}));
prBody = pr.data.body || '';
} catch (error) {
const hitRateLimit = error?.status === 403 && /rate limit/i.test(error?.message || '');
Expand Down Expand Up @@ -716,6 +743,12 @@ jobs:
TARGET_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
with:
script: |
const { createTokenAwareRetry } = require('./.github/scripts/github-api-with-retry.js');
const { withRetry } = await createTokenAwareRetry({
github,
core,
task: 'gate-commit-status',
});
const owner = context.repo.owner;
const repo = context.repo.repo;
const sha = context.payload.pull_request?.head?.sha ?? context.sha;
Expand All @@ -727,15 +760,15 @@ jobs:
const targetUrl = process.env.TARGET_URL;

try {
await github.rest.repos.createCommitStatus({
await withRetry((client) => client.rest.repos.createCommitStatus({
owner,
repo,
sha,
state,
context: 'Gate / gate',
description,
target_url: targetUrl,
});
}));
} catch (error) {
const hitRateLimit = error?.status === 403 && /rate limit/i.test(error?.message || '');
if (hitRateLimit) {
Expand Down
Loading