From 06e59d7fcd286a8ec71abfbd3529e835b46f46a9 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Fri, 22 Aug 2025 16:11:12 -0700 Subject: [PATCH] better javascript typechecking (#12) * Initial plan * Configure JavaScript build environment for @actions/github-script types Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> * Clean up temporary test files and finalize configuration Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> * fix: update run URL generation to handle missing repository context * fix: update import statements for GitHub Actions types to use consistent naming * fix: update import statements to use consistent naming and type imports --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> Co-authored-by: Peli de Halleux --- .github/workflows/test-claude.lock.yml | 12 ++++-- package-lock.json | 45 ++++++++++++++++++++ package.json | 3 ++ pkg/workflow/js/create_comment.cjs | 4 +- pkg/workflow/js/create_issue.cjs | 4 +- pkg/workflow/js/create_pull_request.cjs | 4 +- pkg/workflow/js/types/github-script.d.ts | 53 +++++++++++++++++++++--- tsconfig.json | 1 + 8 files changed, 114 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test-claude.lock.yml b/.github/workflows/test-claude.lock.yml index 285f3a15314..a1e6226b3e2 100644 --- a/.github/workflows/test-claude.lock.yml +++ b/.github/workflows/test-claude.lock.yml @@ -684,7 +684,9 @@ jobs: // Add AI disclaimer with run id, run htmlurl // Add AI disclaimer with workflow run information const runId = context.runId; - const runUrl = `${context.payload.repository.html_url}/actions/runs/${runId}`; + const runUrl = context.payload.repository + ? `${context.payload.repository.html_url}/actions/runs/${runId}` + : `https://github.com/actions/runs/${runId}`; bodyLines.push(``, ``, `> Generated by Agentic Workflow Run [${runId}](${runUrl})`, ''); // Prepare the body content const body = bodyLines.join('\n').trim(); @@ -792,7 +794,9 @@ jobs: let body = outputContent.trim(); // Add AI disclaimer with run id, run htmlurl const runId = context.runId; - const runUrl = `${context.payload.repository.html_url}/actions/runs/${runId}`; + const runUrl = context.payload.repository + ? `${context.payload.repository.html_url}/actions/runs/${runId}` + : `https://github.com/actions/runs/${runId}`; body += `\n\n> Generated by Agentic Workflow Run [${runId}](${runUrl})\n`; console.log(`Creating comment on ${commentEndpoint} #${issueNumber}`); console.log('Comment content length:', body.length); @@ -913,7 +917,9 @@ jobs: } // Add AI disclaimer with run id, run htmlurl const runId = context.runId; - const runUrl = `${context.payload.repository.html_url}/actions/runs/${runId}`; + const runUrl = context.payload.repository + ? `${context.payload.repository.html_url}/actions/runs/${runId}` + : `https://github.com/actions/runs/${runId}`; bodyLines.push(``, ``, `> Generated by Agentic Workflow Run [${runId}](${runUrl})`, ''); // Prepare the body content const body = bodyLines.join('\n').trim(); diff --git a/package-lock.json b/package-lock.json index a52dd4fff52..6a6edbab94e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,10 @@ "": { "devDependencies": { "@actions/core": "^1.11.1", + "@actions/exec": "^1.1.1", "@actions/github": "^6.0.1", + "@actions/glob": "^0.4.0", + "@actions/io": "^1.1.3", "@types/node": "^24.3.0", "@vitest/coverage-v8": "^3.2.4", "@vitest/ui": "^3.2.4", @@ -51,6 +54,41 @@ "undici": "^5.28.5" } }, + "node_modules/@actions/glob": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/@actions/glob/-/glob-0.4.0.tgz", + "integrity": "sha512-+eKIGFhsFa4EBwaf/GMyzCdWrXWymGXfFmZU3FHQvYS8mPcHtTtZONbkcqqUMzw9mJ/pImEBFET1JNifhqGsAQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@actions/core": "^1.9.1", + "minimatch": "^3.0.4" + } + }, + "node_modules/@actions/glob/node_modules/brace-expansion": { + "version": "1.1.12", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz", + "integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/@actions/glob/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, "node_modules/@actions/http-client": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.2.3.tgz", @@ -1466,6 +1504,13 @@ "dev": true, "license": "MIT" }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", + "dev": true, + "license": "MIT" + }, "node_modules/cross-spawn": { "version": "7.0.6", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", diff --git a/package.json b/package.json index 59ca8c17fb1..98c1b13ae08 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,10 @@ { "devDependencies": { "@actions/core": "^1.11.1", + "@actions/exec": "^1.1.1", "@actions/github": "^6.0.1", + "@actions/glob": "^0.4.0", + "@actions/io": "^1.1.3", "@types/node": "^24.3.0", "@vitest/coverage-v8": "^3.2.4", "@vitest/ui": "^3.2.4", diff --git a/pkg/workflow/js/create_comment.cjs b/pkg/workflow/js/create_comment.cjs index 1a619bd0bb8..a463db75cf2 100644 --- a/pkg/workflow/js/create_comment.cjs +++ b/pkg/workflow/js/create_comment.cjs @@ -53,7 +53,9 @@ async function main() { let body = outputContent.trim(); // Add AI disclaimer with run id, run htmlurl const runId = context.runId; - const runUrl = `${context.payload.repository.html_url}/actions/runs/${runId}`; + const runUrl = context.payload.repository + ? `${context.payload.repository.html_url}/actions/runs/${runId}` + : `https://github.com/actions/runs/${runId}`; body += `\n\n> Generated by Agentic Workflow Run [${runId}](${runUrl})\n`; console.log(`Creating comment on ${commentEndpoint} #${issueNumber}`); diff --git a/pkg/workflow/js/create_issue.cjs b/pkg/workflow/js/create_issue.cjs index 044c8484497..a0338aeb462 100644 --- a/pkg/workflow/js/create_issue.cjs +++ b/pkg/workflow/js/create_issue.cjs @@ -65,7 +65,9 @@ async function main() { // Add AI disclaimer with run id, run htmlurl // Add AI disclaimer with workflow run information const runId = context.runId; - const runUrl = `${context.payload.repository.html_url}/actions/runs/${runId}`; + const runUrl = context.payload.repository + ? `${context.payload.repository.html_url}/actions/runs/${runId}` + : `https://github.com/actions/runs/${runId}`; bodyLines.push(``, ``, `> Generated by Agentic Workflow Run [${runId}](${runUrl})`, ''); // Prepare the body content diff --git a/pkg/workflow/js/create_pull_request.cjs b/pkg/workflow/js/create_pull_request.cjs index ea73782332a..c4410ae8155 100644 --- a/pkg/workflow/js/create_pull_request.cjs +++ b/pkg/workflow/js/create_pull_request.cjs @@ -76,7 +76,9 @@ async function main() { // Add AI disclaimer with run id, run htmlurl const runId = context.runId; - const runUrl = `${context.payload.repository.html_url}/actions/runs/${runId}`; + const runUrl = context.payload.repository + ? `${context.payload.repository.html_url}/actions/runs/${runId}` + : `https://github.com/actions/runs/${runId}`; bodyLines.push(``, ``, `> Generated by Agentic Workflow Run [${runId}](${runUrl})`, ''); // Prepare the body content diff --git a/pkg/workflow/js/types/github-script.d.ts b/pkg/workflow/js/types/github-script.d.ts index eff35483acb..55ade16471f 100644 --- a/pkg/workflow/js/types/github-script.d.ts +++ b/pkg/workflow/js/types/github-script.d.ts @@ -1,24 +1,57 @@ // Type definitions for GitHub Actions github-script action // These globals are provided by the github-script action environment +// Based on @actions/github-script AsyncFunctionArguments interface -import * as core from '@actions/core'; -import * as github from '@actions/github'; +import * as __actionsCore from '@actions/core'; +import * as __actionsExec from '@actions/exec'; +import * as __actionsGithub from '@actions/github'; +import * as __actionsGlob from '@actions/glob'; +import * as __actionsIo from '@actions/io'; +import type { Context } from '@actions/github/lib/context'; +import type { GitHub } from '@actions/github/lib/utils'; declare global { /** * GitHub API client instance provided by github-script action + * This is an authenticated Octokit instance with pagination plugins */ - const github: ReturnType; + const github: InstanceType; + + /** + * Alternative name for the github client (same as github) + * Provided for backward compatibility + */ + const octokit: InstanceType; /** * GitHub Actions context object provided by github-script action + * Contains information about the workflow run context */ - const context: typeof github.context; + const context: Context; /** * Actions core utilities provided by github-script action + * For setting outputs, logging, and other workflow operations + */ + const core: typeof __actionsCore; + + /** + * Actions exec utilities provided by github-script action + * For executing shell commands and tools */ - const core: typeof core; + const exec: typeof __actionsExec; + + /** + * Actions glob utilities provided by github-script action + * For file pattern matching and globbing + */ + const glob: typeof __actionsGlob; + + /** + * Actions io utilities provided by github-script action + * For file and directory operations + */ + const io: typeof __actionsIo; /** * Console object for logging (available in Node.js environment) @@ -31,10 +64,18 @@ declare global { const process: NodeJS.Process; /** - * Require function for CommonJS modules + * Enhanced require function for CommonJS modules + * This is a proxy wrapper around the normal Node.js require + * that enables requiring relative paths and npm packages */ const require: NodeRequire; + /** + * Original require function without the github-script wrapper + * Use this if you need the non-wrapped require functionality + */ + const __original_require__: NodeRequire; + /** * Global exports object for CommonJS modules */ diff --git a/tsconfig.json b/tsconfig.json index 60b9e0e4166..46ac630a98e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -32,6 +32,7 @@ "typeRoots": ["./node_modules/@types", "./pkg/workflow/js/types"] }, "include": [ + "pkg/workflow/js/add_labels.cjs", "pkg/workflow/js/create_comment.cjs", "pkg/workflow/js/create_issue.cjs", "pkg/workflow/js/create_pull_request.cjs",