|
| 1 | +const core = require('@actions/core'); |
| 2 | +const github = require('@actions/github'); |
| 3 | +const { exec } = require('child_process'); |
| 4 | + |
| 5 | +async function run() { |
| 6 | + try { |
| 7 | + // Get input parameters |
| 8 | + const openaiApiKey = core.getInput('openai_api_key', { required: true }); |
| 9 | + const githubToken = core.getInput('github_token', { required: true }); |
| 10 | + |
| 11 | + // Get PR context |
| 12 | + const context = github.context; |
| 13 | + if (context.payload.pull_request) { |
| 14 | + const prNumber = context.payload.pull_request.number; |
| 15 | + const repo = context.repo.repo; |
| 16 | + const owner = context.repo.owner; |
| 17 | + |
| 18 | + console.log(`Analyzing PR #${prNumber} in ${owner}/${repo}`); |
| 19 | + |
| 20 | + // Set environment variables |
| 21 | + process.env.OPENAI_API_KEY = openaiApiKey; |
| 22 | + process.env.GITHUB_TOKEN = githubToken; |
| 23 | + |
| 24 | + // Run PR analysis with OpenAI |
| 25 | + // eslint-disable-next-line max-len |
| 26 | + const command = `npx pr-codex review --pr ${prNumber} --repo ${owner}/${repo}`; |
| 27 | + |
| 28 | + exec(command, (error, stdout, stderr) => { |
| 29 | + if (error) { |
| 30 | + core.setFailed(`PR Codex execution failed: ${error.message}`); |
| 31 | + return; |
| 32 | + } |
| 33 | + |
| 34 | + if (stderr) { |
| 35 | + console.error(`PR Codex stderr: ${stderr}`); |
| 36 | + } |
| 37 | + |
| 38 | + console.log(`PR Codex output: ${stdout}`); |
| 39 | + core.info('PR Codex analysis completed successfully'); |
| 40 | + }); |
| 41 | + } else { |
| 42 | + core.info('This action only works on pull requests'); |
| 43 | + } |
| 44 | + } catch (error) { |
| 45 | + core.setFailed(`Action failed: ${error.message}`); |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +run(); |
0 commit comments