diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 10045f9..6a59416 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -47,23 +47,21 @@ jobs: run: env - name: "Cleanup PR" - continue-on-error: true env: GH_TOKEN: ${{ secrets.TEST_PULL_TOKEN }} run: | - pull="$(gh api /repos/${{ env.repository }}/pulls \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - --jq '.[0].number' + number="$(gh pr list \ + --repo "${{ env.repository }}" --json number \ + --template '{{if gt (len .) 0}}{{(index . 0).number}}{{end}}' \ )" - [ -z "${pull}" ] && exit 0 - echo "Closing PR: ${pull}" - gh api --method PATCH "/repos/${{ env.repository }}/pulls/${pull}" \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - -f "state=closed" --silent - echo "Waiting 3 Seconds..." - sleep 3 + if [ -n "${number}" ];then + echo "Closing Pull Request: ${number}" + gh pr close --repo "${{ env.repository }}" "${number}" + echo "Waiting 3 Seconds..." + sleep 3 + else + echo "No PR's found: ${{ github.server_url }}/${{ env.repository }}/pulls" + fi - name: "Test Local Action" id: test @@ -71,9 +69,6 @@ jobs: with: repository: ${{ env.repository }} head: test1 - #base: master - #title: Ralf Broke It - #body: Broken ${{ github.run_number }} times. token: ${{ secrets.TEST_PULL_TOKEN }} - name: "Validate Outputs" diff --git a/dist/index.js b/dist/index.js index 1bb2e95..04742b4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -31528,11 +31528,12 @@ class GitHub { this.octokit = githubExports.getOctokit(token); } async createPull(data) { - console.log('createPull:', data); + coreExports.debug(`createPull: ${JSON.stringify(data)}`); const response = await this.octokit.rest.pulls.create(data); return response.data; } async getRepository(data) { + coreExports.debug(`getRepository: ${JSON.stringify(data)}`); const response = await this.octokit.rest.repos.get(data); return response.data; } @@ -31574,13 +31575,15 @@ async function main() { const repository = await api.getRepository(data); data.base = repository.default_branch; } - console.log('data:', data); + coreExports.startGroup('Request data'); + console.log(data); + coreExports.endGroup(); coreExports.info('⌛ Creating Pull Request...'); const pull = await api.createPull(data); - coreExports.startGroup('pull'); + coreExports.startGroup('Response data'); console.log(JSON.stringify(pull, null, 2)); coreExports.endGroup(); - coreExports.info(`🚀 Pull Request Created: ${pull.number}`); + coreExports.info(`🚀 Pull Request Created: ${pull.html_url}`); if (inputs.summary) { coreExports.info('📝 Writing Job Summary'); try { diff --git a/package-lock.json b/package-lock.json index a2f0152..ae50eff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "@rollup/plugin-commonjs": "^29.0.0", "@rollup/plugin-node-resolve": "^16.0.3", "@rollup/plugin-typescript": "^12.3.0", - "@types/node": "^25.0.3", + "@types/node": "^25.0.5", "@typescript-eslint/eslint-plugin": "^8.52.0", "@typescript-eslint/parser": "^8.52.0", "eslint": "^9.39.2", @@ -956,9 +956,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "25.0.3", - "resolved": "https://registry.npmjs.org/@types/node/-/node-25.0.3.tgz", - "integrity": "sha512-W609buLVRVmeW693xKfzHeIV6nJGGz98uCPfeXI1ELMLXVeKYZ9m15fAMSaUPBHYLGFsVRcMmSCksQOrZV9BYA==", + "version": "25.0.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-25.0.5.tgz", + "integrity": "sha512-FuLxeLuSVOqHPxSN1fkcD8DLU21gAP7nCKqGRJ/FglbCUBs0NYN6TpHcdmyLeh8C0KwGIaZQJSv+OYG+KZz+Gw==", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 28f7ba9..8cd77d3 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "@rollup/plugin-commonjs": "^29.0.0", "@rollup/plugin-node-resolve": "^16.0.3", "@rollup/plugin-typescript": "^12.3.0", - "@types/node": "^25.0.3", + "@types/node": "^25.0.5", "@typescript-eslint/eslint-plugin": "^8.52.0", "@typescript-eslint/parser": "^8.52.0", "eslint": "^9.39.2", diff --git a/src/github.ts b/src/github.ts index 9c55637..613d321 100644 --- a/src/github.ts +++ b/src/github.ts @@ -1,3 +1,4 @@ +import * as core from '@actions/core' import * as github from '@actions/github' import { RestEndpointMethodTypes } from '@octokit/plugin-rest-endpoint-methods/dist-types/generated/parameters-and-response-types.js' @@ -14,12 +15,13 @@ export class GitHub { } async createPull(data: PullRequest) { - console.log('createPull:', data) + core.debug(`createPull: ${JSON.stringify(data)}`) const response = await this.octokit.rest.pulls.create(data) return response.data } async getRepository(data: { owner: string; repo: string }) { + core.debug(`getRepository: ${JSON.stringify(data)}`) const response = await this.octokit.rest.repos.get(data) return response.data } diff --git a/src/index.ts b/src/index.ts index 8448e9d..bb00b3f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -47,15 +47,17 @@ async function main() { const repository = await api.getRepository(data) data.base = repository.default_branch } - console.log('data:', data) + core.startGroup('Request data') + console.log(data) + core.endGroup() // data // Processing core.info('⌛ Creating Pull Request...') const pull = await api.createPull(data) - core.startGroup('pull') + core.startGroup('Response data') console.log(JSON.stringify(pull, null, 2)) core.endGroup() // pull - core.info(`🚀 Pull Request Created: ${pull.number}`) + core.info(`🚀 Pull Request Created: ${pull.html_url}`) // Summary if (inputs.summary) {