MCPcopy Index your code
hub / github.com/promptfoo/promptfoo / getGitHubContext

Function getGitHubContext

code-scan-action/src/github.ts:28–73  ·  view source on GitHub ↗
(token: string)

Source from the content-addressed store, hash-verified

26 * @returns GitHub PR context
27 */
28export async function getGitHubContext(token: string): Promise<PullRequestContext> {
29 const context = github.context;
30
31 // For workflow_dispatch, read pr_number from event inputs
32 if (context.eventName === 'workflow_dispatch') {
33 const prNumberInput = (context.payload.inputs as Record<string, string> | undefined)?.pr_number;
34 if (!prNumberInput) {
35 throw new Error(
36 'workflow_dispatch requires a pr_number input. Add inputs: { pr_number: { required: true } } to your workflow.',
37 );
38 }
39
40 const prNumber = parseInt(prNumberInput, 10);
41 if (isNaN(prNumber)) {
42 throw new Error(`Invalid pr_number input: "${prNumberInput}"`);
43 }
44
45 const octokit = new Octokit({ auth: token });
46 const { data: pr } = await octokit.pulls.get({
47 owner: context.repo.owner,
48 repo: context.repo.repo,
49 pull_number: prNumber,
50 });
51
52 return {
53 owner: context.repo.owner,
54 repo: context.repo.repo,
55 number: pr.number,
56 sha: pr.head.sha,
57 };
58 }
59
60 // Otherwise, get context from pull_request event
61 if (!context.payload.pull_request) {
62 throw new Error(
63 'This action requires a pull_request event or workflow_dispatch with pr_number input',
64 );
65 }
66
67 return {
68 owner: context.repo.owner,
69 repo: context.repo.repo,
70 number: context.payload.pull_request.number,
71 sha: context.payload.pull_request.head.sha,
72 };
73}
74
75/**
76 * Get list of files changed in the PR

Callers 2

runCodeScanFunction · 0.90
github.test.tsFile · 0.90

Calls 1

getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…