diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 21d23a0..56bbf1f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,13 +30,6 @@ jobs: directory: ${{ env.CONFIG_DIRECTORY }} speculative: true - - name: Initialize Terraform Backend - run: terraform init -reconfigure - env: - TF_CLOUD_ORGANIZATION: ${{ env.TF_CLOUD_ORGANIZATION }} - TF_API_TOKEN: ${{ secrets.TF_API_TOKEN }} - TF_WORKSPACE: ${{ env.TF_WORKSPACE }} - - name: Create Plan Run uses: hashicorp/tfc-workflows-github/actions/create-run@v1.0.0 id: plan-run @@ -65,23 +58,29 @@ jobs: *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; - if (context.payload.pull_request) { - await github.rest.issues.updateComment({ - comment_id: context.payload.pull_request.issue_url.split('/').pop(), - owner: context.repo.owner, - repo: context.repo.repo, + const { owner, repo } = context.repo; + const { number } = context.payload.pull_request || {}; + + if (number) { + await github.rest.issues.createComment({ + issue_number: number, + owner, + repo, body: output }); } else { - const response = await github.rest.pulls.create({ - owner: context.repo.owner, - repo: context.repo.repo, - title: 'Automated Pull Request', - head: '${{ github.actor }}:main', - base: 'main', - body: output + console.log('No pull request context found. Creating a new pull request...'); + + const newPullRequest = await github.rest.pulls.create({ + owner, + repo, + title: 'Your pull request title here', + head: 'main', // Replace with the name of your branch + base: 'main', // Replace with the name of the base branch + body: 'Your pull request description here' }); - console.log('Pull request created:', response.data.html_url); + + console.log('New pull request created:', newPullRequest.data); } - name: Terraform Plan Status