Skip to content

Commit afc7f4c

Browse files
pelikhanCopilot
andauthored
better javascript typechecking (#12) (#191)
* Initial plan * Configure JavaScript build environment for @actions/github-script types * Clean up temporary test files and finalize configuration * 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 <198982749+Copilot@users.noreply.github.com> Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent e2b9847 commit afc7f4c

File tree

8 files changed

+114
-12
lines changed

8 files changed

+114
-12
lines changed

.github/workflows/test-claude.lock.yml

Lines changed: 9 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{
22
"devDependencies": {
33
"@actions/core": "^1.11.1",
4+
"@actions/exec": "^1.1.1",
45
"@actions/github": "^6.0.1",
6+
"@actions/glob": "^0.4.0",
7+
"@actions/io": "^1.1.3",
58
"@types/node": "^24.3.0",
69
"@vitest/coverage-v8": "^3.2.4",
710
"@vitest/ui": "^3.2.4",

pkg/workflow/js/create_comment.cjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ async function main() {
5353
let body = outputContent.trim();
5454
// Add AI disclaimer with run id, run htmlurl
5555
const runId = context.runId;
56-
const runUrl = `${context.payload.repository.html_url}/actions/runs/${runId}`;
56+
const runUrl = context.payload.repository
57+
? `${context.payload.repository.html_url}/actions/runs/${runId}`
58+
: `https://github.com/actions/runs/${runId}`;
5759
body += `\n\n> Generated by Agentic Workflow Run [${runId}](${runUrl})\n`;
5860

5961
console.log(`Creating comment on ${commentEndpoint} #${issueNumber}`);

pkg/workflow/js/create_issue.cjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ async function main() {
6565
// Add AI disclaimer with run id, run htmlurl
6666
// Add AI disclaimer with workflow run information
6767
const runId = context.runId;
68-
const runUrl = `${context.payload.repository.html_url}/actions/runs/${runId}`;
68+
const runUrl = context.payload.repository
69+
? `${context.payload.repository.html_url}/actions/runs/${runId}`
70+
: `https://github.com/actions/runs/${runId}`;
6971
bodyLines.push(``, ``, `> Generated by Agentic Workflow Run [${runId}](${runUrl})`, '');
7072

7173
// Prepare the body content

pkg/workflow/js/create_pull_request.cjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ async function main() {
7676

7777
// Add AI disclaimer with run id, run htmlurl
7878
const runId = context.runId;
79-
const runUrl = `${context.payload.repository.html_url}/actions/runs/${runId}`;
79+
const runUrl = context.payload.repository
80+
? `${context.payload.repository.html_url}/actions/runs/${runId}`
81+
: `https://github.com/actions/runs/${runId}`;
8082
bodyLines.push(``, ``, `> Generated by Agentic Workflow Run [${runId}](${runUrl})`, '');
8183

8284
// Prepare the body content

pkg/workflow/js/types/github-script.d.ts

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,57 @@
11
// Type definitions for GitHub Actions github-script action
22
// These globals are provided by the github-script action environment
3+
// Based on @actions/github-script AsyncFunctionArguments interface
34

4-
import * as core from '@actions/core';
5-
import * as github from '@actions/github';
5+
import * as __actionsCore from '@actions/core';
6+
import * as __actionsExec from '@actions/exec';
7+
import * as __actionsGithub from '@actions/github';
8+
import * as __actionsGlob from '@actions/glob';
9+
import * as __actionsIo from '@actions/io';
10+
import type { Context } from '@actions/github/lib/context';
11+
import type { GitHub } from '@actions/github/lib/utils';
612

713
declare global {
814
/**
915
* GitHub API client instance provided by github-script action
16+
* This is an authenticated Octokit instance with pagination plugins
1017
*/
11-
const github: ReturnType<typeof github.getOctokit>;
18+
const github: InstanceType<typeof GitHub>;
19+
20+
/**
21+
* Alternative name for the github client (same as github)
22+
* Provided for backward compatibility
23+
*/
24+
const octokit: InstanceType<typeof GitHub>;
1225

1326
/**
1427
* GitHub Actions context object provided by github-script action
28+
* Contains information about the workflow run context
1529
*/
16-
const context: typeof github.context;
30+
const context: Context;
1731

1832
/**
1933
* Actions core utilities provided by github-script action
34+
* For setting outputs, logging, and other workflow operations
35+
*/
36+
const core: typeof __actionsCore;
37+
38+
/**
39+
* Actions exec utilities provided by github-script action
40+
* For executing shell commands and tools
2041
*/
21-
const core: typeof core;
42+
const exec: typeof __actionsExec;
43+
44+
/**
45+
* Actions glob utilities provided by github-script action
46+
* For file pattern matching and globbing
47+
*/
48+
const glob: typeof __actionsGlob;
49+
50+
/**
51+
* Actions io utilities provided by github-script action
52+
* For file and directory operations
53+
*/
54+
const io: typeof __actionsIo;
2255

2356
/**
2457
* Console object for logging (available in Node.js environment)
@@ -31,10 +64,18 @@ declare global {
3164
const process: NodeJS.Process;
3265

3366
/**
34-
* Require function for CommonJS modules
67+
* Enhanced require function for CommonJS modules
68+
* This is a proxy wrapper around the normal Node.js require
69+
* that enables requiring relative paths and npm packages
3570
*/
3671
const require: NodeRequire;
3772

73+
/**
74+
* Original require function without the github-script wrapper
75+
* Use this if you need the non-wrapped require functionality
76+
*/
77+
const __original_require__: NodeRequire;
78+
3879
/**
3980
* Global exports object for CommonJS modules
4081
*/

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"typeRoots": ["./node_modules/@types", "./pkg/workflow/js/types"]
3333
},
3434
"include": [
35+
"pkg/workflow/js/add_labels.cjs",
3536
"pkg/workflow/js/create_comment.cjs",
3637
"pkg/workflow/js/create_issue.cjs",
3738
"pkg/workflow/js/create_pull_request.cjs",

0 commit comments

Comments
 (0)