From e5197846dbdc17e6ed8a71b3a8f01bd65818f408 Mon Sep 17 00:00:00 2001 From: chronark Date: Wed, 23 Oct 2024 15:36:48 +0200 Subject: [PATCH] ci: add campsite bot --- .github/workflows/pr-alerts-campsite.yml | 53 ++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/pr-alerts-campsite.yml diff --git a/.github/workflows/pr-alerts-campsite.yml b/.github/workflows/pr-alerts-campsite.yml new file mode 100644 index 0000000000..9587de0368 --- /dev/null +++ b/.github/workflows/pr-alerts-campsite.yml @@ -0,0 +1,53 @@ +name: Campsite PR Alerts + +on: + pull_request: + types: [opened, closed, merged, ready_for_review, reopened] + +jobs: + post_to_campsite: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '20' + + - name: Post to Campsite + id: post_to_campsite + run: | + if [[ "${{ github.event.pull_request.draft }}" == "true" ]]; then + STATUS_EMOJI="⚪" + elif [[ "${{ github.event.action }}" == "opened" || "${{ github.event.action }}" == "reopened" || "${{ github.event.action }}" == "ready_for_review" ]]; then + STATUS_EMOJI="🟢" + elif [[ "${{ github.event.action }}" == "closed" && "${{ github.event.pull_request.merged }}" == "true" ]]; then + STATUS_EMOJI="🟣" + elif [[ "${{ github.event.action }}" == "closed" ]]; then + STATUS_EMOJI="🔴" + fi + + ACTION=${{ github.event.action }} + if [[ "${ACTION}" == "ready_for_review" ]]; then + ACTION="ready for review" + elif [[ "${ACTION}" == "reopened" ]]; then + ACTION="reopened" + elif [[ "${ACTION}" == "closed" && "${{ github.event.pull_request.merged }}" == "true" ]]; then + ACTION="merged" + fi + + ESCAPED_TITLE=$(echo "${{ github.event.pull_request.title }}" | jq -Rr @json) + + CONTENT="${STATUS_EMOJI} Pull request ${ACTION} by ${{ github.event.pull_request.user.login }}: [#${{ github.event.pull_request.number }} ${ESCAPED_TITLE}](${{ github.event.pull_request.html_url }})" + + echo "content=${CONTENT}" >> $GITHUB_OUTPUT + - name: Create Campsite message + uses: campsite/campsite-github-action@v1 + with: + api_key: ${{ secrets.CAMPSITE_API_KEY }} + action_type: create_message + thread_id: ${{ secrets.CAMPSITE_PR_ALERTS_THREAD_ID }} + content: ${{ steps.post_to_campsite.outputs.content }}