From 8145ea05e8416c21adba4726fc4d557f1c93a46a Mon Sep 17 00:00:00 2001 From: Mark Karle Date: Mon, 18 Sep 2023 15:42:05 -0700 Subject: [PATCH] Adding Generate PR Description workflow (#18) This adds a PR comment-triggered workflow that uses the action [mkarle/skonsole-generate-pr-description](https://github.com/mkarle/skonsole-generate-pr-description). That action uses [mkarle/pr-update](https://github.com/mkarle/pr-update) to update the PR. To use, create a comment on a PR with: `/sk generate-pr-description ` Since it's triggered from a pull request comment, it only runs if it's in the default branch of the repo. [See this PR for an example of it working.](https://github.com/mkarle/skonsole/pull/4) You'll need to add the following environment variables to the repo: - variable: AZURE_OPENAI_CHAT_DEPLOYMENT_NAME - secret: AZURE_OPENAI_API_ENDPOINT - secret: AZURE_OPENAI_API_KEY --- .github/workflows/generate-pr-description.yml | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 .github/workflows/generate-pr-description.yml diff --git a/.github/workflows/generate-pr-description.yml b/.github/workflows/generate-pr-description.yml new file mode 100644 index 0000000..c33417e --- /dev/null +++ b/.github/workflows/generate-pr-description.yml @@ -0,0 +1,60 @@ +name: Generate PR Description + +# Usage: Comment on a pull request with "/sk generate-pr-description " + +on: + issue_comment: + types: [created] + +jobs: + generate-pr-description: + runs-on: ubuntu-latest + if: github.event.issue.pull_request && contains(github.event.comment.body, '/sk generate-pr-description') + steps: + - name: Get PR branch + uses: xt0rted/pull-request-comment-branch@v1 + id: comment-branch + + - name: Set latest commit status as pending + uses: myrotvorets/set-commit-status-action@master + with: + sha: ${{ steps.comment-branch.outputs.head_sha }} + token: ${{ secrets.GITHUB_TOKEN }} + status: pending + + - name: Generate PR description + uses: mkarle/skonsole-generate-pr-description@v1 + with: + pull-request-number: ${{ github.event.issue.number }} + pull-request-diff-url: ${{ github.event.issue.pull_request.diff_url }} + token: ${{ secrets.GITHUB_TOKEN }} + update-type: ${{ contains(github.event.comment.body, 'replace') && 'replace' || (contains(github.event.comment.body, 'prefix') && 'prefix' || 'suffix') }} + env: # Set Azure credentials secret as an input + AZURE_OPENAI_CHAT_DEPLOYMENT_NAME: ${{ vars.AZURE_OPENAI_CHAT_DEPLOYMENT_NAME }} + AZURE_OPENAI_API_ENDPOINT: ${{ secrets.AZURE_OPENAI_API_ENDPOINT }} + AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }} + + - name: Set latest commit status as ${{ job.status }} + uses: myrotvorets/set-commit-status-action@master + if: always() + with: + sha: ${{ steps.comment-branch.outputs.head_sha }} + token: ${{ secrets.GITHUB_TOKEN }} + status: ${{ job.status }} + + - name: Add comment to PR + uses: actions/github-script@v6 + if: always() + with: + script: | + const name = '${{ github.workflow }}'; + const url = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'; + const success = '${{ job.status }}' === 'success'; + const body = `${name}: ${success ? 'succeeded ✅' : 'failed ❌'}\n${url}`; + + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: body + }) \ No newline at end of file