|
| 1 | +import { |
| 2 | + createStickyComment, |
| 3 | + findCommentByIdentifier, |
| 4 | + addLabelsToPullRequest, |
| 5 | + pullRequestHasLabels, |
| 6 | + getCurrentPullRequestNumber, |
| 7 | + getRepoInfo, |
| 8 | + sanitizeInput, |
| 9 | + escapeMarkdown, |
| 10 | + formatDate, |
| 11 | + checkBranchExists, |
| 12 | + listDeployments, |
| 13 | +} from "github-typescript-utils"; |
| 14 | + |
| 15 | +type Ctx = { |
| 16 | + core: typeof import("@actions/core"); |
| 17 | + github: ReturnType<typeof import("@actions/github").getOctokit>; |
| 18 | + context: typeof import("@actions/github").context; |
| 19 | + args: { |
| 20 | + testMessage: string; |
| 21 | + testLabels: string[]; |
| 22 | + testBranch: string; |
| 23 | + }; |
| 24 | +}; |
| 25 | + |
| 26 | +/** |
| 27 | + * E2E test script that exercises various utility functions |
| 28 | + * to verify they can be imported and bundled correctly |
| 29 | + */ |
| 30 | +export default async function run({ core, github, context, args }: Ctx) { |
| 31 | + core.info("🚀 Starting E2E test of github-typescript-utils"); |
| 32 | + |
| 33 | + try { |
| 34 | + // Test 1: Input sanitization |
| 35 | + const sanitizedMessage = sanitizeInput(args.testMessage); |
| 36 | + core.info( |
| 37 | + `✅ Input sanitization: "${args.testMessage}" → "${sanitizedMessage}"` |
| 38 | + ); |
| 39 | + |
| 40 | + // Test 2: Text formatting utilities |
| 41 | + const escapedText = escapeMarkdown("**Bold** _italic_ `code`"); |
| 42 | + const formattedDate = formatDate(new Date()); |
| 43 | + core.info( |
| 44 | + `✅ Text formatting: escaped="${escapedText}", date="${formattedDate}"` |
| 45 | + ); |
| 46 | + |
| 47 | + // Test 3: Context utilities |
| 48 | + const repoInfo = getRepoInfo(context); |
| 49 | + core.info(`✅ Repo info: ${repoInfo.owner}/${repoInfo.repo}`); |
| 50 | + |
| 51 | + // Test 4: PR context (if available) |
| 52 | + const prNumber = getCurrentPullRequestNumber(context); |
| 53 | + if (prNumber) { |
| 54 | + core.info(`✅ PR context: Found PR #${prNumber}`); |
| 55 | + |
| 56 | + // Test PR utilities |
| 57 | + const hasLabels = await pullRequestHasLabels({ |
| 58 | + ctx: { core, github, context }, |
| 59 | + repo: repoInfo, |
| 60 | + pullNumber: prNumber, |
| 61 | + labels: args.testLabels, |
| 62 | + }); |
| 63 | + core.info( |
| 64 | + `✅ PR label check: has labels [${args.testLabels.join( |
| 65 | + ", " |
| 66 | + )}] = ${hasLabels}` |
| 67 | + ); |
| 68 | + } else { |
| 69 | + core.info("ℹ️ No PR context available, skipping PR-specific tests"); |
| 70 | + } |
| 71 | + |
| 72 | + // Test 5: Branch utilities |
| 73 | + const branchExists = await checkBranchExists({ |
| 74 | + ctx: { core, github, context }, |
| 75 | + repo: repoInfo, |
| 76 | + branchName: args.testBranch, |
| 77 | + }); |
| 78 | + core.info(`✅ Branch check: "${args.testBranch}" exists = ${branchExists}`); |
| 79 | + |
| 80 | + core.info("🎉 E2E test completed successfully!"); |
| 81 | + |
| 82 | + return { |
| 83 | + success: true, |
| 84 | + testsRun: 7, |
| 85 | + repoInfo, |
| 86 | + prNumber, |
| 87 | + branchExists, |
| 88 | + }; |
| 89 | + } catch (error) { |
| 90 | + core.error(`❌ E2E test failed: ${error}`); |
| 91 | + core.setFailed(`E2E test failed: ${error}`); |
| 92 | + return { success: false, error: String(error) }; |
| 93 | + } |
| 94 | +} |
0 commit comments