diff --git a/.github/scripts/pr-analyzer.js b/.github/scripts/pr-analyzer.js index cedb6a99..bfcac80c 100644 --- a/.github/scripts/pr-analyzer.js +++ b/.github/scripts/pr-analyzer.js @@ -1,6 +1,4 @@ const axios = require('axios'); -const core = require('@actions/core'); -const github = require('@actions/github'); async function run() { try { @@ -41,7 +39,6 @@ async function run() { const prNumber = process.env.PR_NUMBER; const repo = process.env.GITHUB_REPOSITORY; const token = process.env.GITHUB_TOKEN; - console.log(`Fetching details for PR ${prNumber} in repository ${repo}`); const response = await axios.get(`https://api.github.com/repos/${repo}/pulls/${prNumber}`, { headers: { Authorization: `Bearer ${token}`, @@ -121,14 +118,6 @@ async function run() { ${json_output} \`\`\` ` - - const octokit = new github.getOctokit(process.env.GITHUB_TOKEN); - const new_comment = octokit.issues.createComment({ - owner: 'theballaam96', - repo: payload.repository.name, - issue_number: payload.issue.number, - body: message, - }); // await octokit.issues.update({ // owner: 'theballaam96', // repo: payload.repository.name, @@ -136,7 +125,8 @@ async function run() { // labels: Array.from([...labels, ...newLabels]) // }); - console.log('Commented on pull request successfully.'); + console.log(message); + return message; } catch (error) { console.error('Error:', error.response ? error.response.data : error.message || error); process.exit(1); diff --git a/.github/workflows/pull-open.yml b/.github/workflows/pull-open.yml index f5e43b0b..ff00e320 100644 --- a/.github/workflows/pull-open.yml +++ b/.github/workflows/pull-open.yml @@ -22,12 +22,22 @@ jobs: - name: Install project dependencies run: | npm install - npm install @actions/core - npm install @actions/github npm install axios - name: Analyze Pull Request - run: node .github/scripts/pr-analyzer.js + run: | + PULL_MSG=$(node .github/scripts/pr-analyzer.js) + echo "PULL_MSG=$PULL_MSG" >> $GITHUB_ENV env: PR_NUMBER: ${{ github.event.number }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: actions/github-script@v2 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + github.issues.createComment({ + issue_number: ${{ github.event.number }}, + owner: context.repo.owner, + repo: context.repo.repo, + body: ${{ env.PULL_MSG }} + })