diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cafe3cb..a6b8516 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -on: [push] +on: [push, pull_request] jobs: hello_world_job: diff --git a/action.yml b/action.yml index 896bbd6..c245d51 100644 --- a/action.yml +++ b/action.yml @@ -33,7 +33,7 @@ runs: LINK: "https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }}" BRANCH: ${{ env.BRANCH }} PR_TITLE: ${{ github.event.pull_request.title }} - PR_NUMBER: ${{ github.event.pull_request.number }} + PR_NUMBER: ${{ github.event.number }} PR_REPO: ${{ github.repository }} PR_OWNER: ${{ github.repository_owner }} CLARIFAI_PAT: ${{ inputs.CLARIFAI_PAT }} diff --git a/dist/index.js b/dist/index.js index ff29ce7..db76eed 100644 --- a/dist/index.js +++ b/dist/index.js @@ -9815,29 +9815,33 @@ async function reviewPR() { try { const octokit = github.getOctokit(process.env.GITHUB_TOKEN) - console.log("Using this data for PR check", { - PR_OWNER: process.env.PR_OWNER, - PR_NUMBER: process.env.PR_NUMBER, - PR_REPO: process.env.PR_REPO - }) - - const {data: pullRequest} = await octokit.rest.pulls.get({ + const ctx = { owner: process.env.PR_OWNER, repo: process.env.PR_REPO, pull_number: process.env.PR_NUMBER, + } + console.log("Using this data for PR check", ctx) + + if(!process.env.PR_NUMBER){ + core.setFailed("No PR number detected. Wrong event type?"); + return + } + + const {data: pullRequest} = await octokit.rest.pulls.get({ + ...ctx, mediaType: { format: 'diff' } }); + console.log("Received this PR data:", pullRequest); + } catch (error) { console.error("Failed at getting PR data") core.setFailed(error.message); } try{ - console.log("Received this PR data:", pullRequest); - // `who-to-greet` input defined in action metadata file // const nameToGreet = core.getInput('who-to-greet'); // console.log(`Hello ${nameToGreet}!`); diff --git a/index.js b/index.js index af86e4f..ff090ed 100644 --- a/index.js +++ b/index.js @@ -5,29 +5,33 @@ async function reviewPR() { try { const octokit = github.getOctokit(process.env.GITHUB_TOKEN) - console.log("Using this data for PR check", { - PR_OWNER: process.env.PR_OWNER, - PR_NUMBER: process.env.PR_NUMBER, - PR_REPO: process.env.PR_REPO - }) - - const {data: pullRequest} = await octokit.rest.pulls.get({ + const ctx = { owner: process.env.PR_OWNER, repo: process.env.PR_REPO, pull_number: process.env.PR_NUMBER, + } + console.log("Using this data for PR check", ctx) + + if(!process.env.PR_NUMBER){ + core.setFailed("No PR number detected. Wrong event type?"); + return + } + + const {data: pullRequest} = await octokit.rest.pulls.get({ + ...ctx, mediaType: { format: 'diff' } }); + console.log("Received this PR data:", pullRequest); + } catch (error) { console.error("Failed at getting PR data") core.setFailed(error.message); } try{ - console.log("Received this PR data:", pullRequest); - // `who-to-greet` input defined in action metadata file // const nameToGreet = core.getInput('who-to-greet'); // console.log(`Hello ${nameToGreet}!`);