diff --git a/.github/workflows/assets/turing_team_pr_bot.png b/.github/workflows/assets/turing_team_pr_bot.png new file mode 100644 index 00000000..905659cb Binary files /dev/null and b/.github/workflows/assets/turing_team_pr_bot.png differ diff --git a/.github/workflows/notify-pr-closed.yaml b/.github/workflows/notify-pr-closed.yaml new file mode 100644 index 00000000..4aafd73c --- /dev/null +++ b/.github/workflows/notify-pr-closed.yaml @@ -0,0 +1,41 @@ +name: Notify Teams on PR + +on: + pull_request: + types: [closed] + +jobs: + notify-teams: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + with: + fetch-depth: 0 + - name: Compute added/removed lines for notification + id: diff + run: | + PR_DATA=$(gh pr view "${{ github.event.pull_request.number }}" --json additions,deletions -q '.') + ADDITIONS=$(echo "$PR_DATA" | jq '.additions') + DELETIONS=$(echo "$PR_DATA" | jq '.deletions') + echo "additions=$ADDITIONS" >> $GITHUB_OUTPUT + echo "deletions=$DELETIONS" >> $GITHUB_OUTPUT + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Notify Microsoft Teams + uses: softwareone-platform/notify-pr-teams-action@v4 + with: + webhook_url: ${{ secrets.TEAMS_WEBHOOK_URL }} + bot_image_url: https://raw.githubusercontent.com/softwareone-platform/mpt-api-python-client/main/.github/workflows/assets/turing_team_pr_bot.png + repo: ${{ github.repository }} + pr_url: ${{ github.event.pull_request.html_url }} + pr_title: ${{ github.event.pull_request.title }} + pr_author: ${{ github.event.pull_request.user.login }} + head_ref: ${{ github.event.pull_request.head.ref }} + base_ref: ${{ github.event.pull_request.base.ref }} + commits: ${{ github.event.pull_request.commits }} + changed_files: ${{ github.event.pull_request.changed_files }} + additions: ${{ steps.diff.outputs.additions }} + deletions: ${{ steps.diff.outputs.deletions }} + pr_number: ${{ github.event.pull_request.number }} + pr_status: ${{ github.event.pull_request.state }} + is_merged: ${{ github.event.pull_request.merged }} diff --git a/.github/workflows/notify-pr-reviewed.yml b/.github/workflows/notify-pr-reviewed.yml new file mode 100644 index 00000000..1d088162 --- /dev/null +++ b/.github/workflows/notify-pr-reviewed.yml @@ -0,0 +1,34 @@ +name: PR Review Notification + +on: + pull_request_review: + types: [submitted, edited, dismissed] + +jobs: + notify-teams: + if: ${{ github.actor != 'coderabbitai[bot]' }} + runs-on: ubuntu-latest + steps: + - name: Get Review Comments Count + id: comments + run: | + COMMENTS_COUNT=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews/${{ github.event.review.id }}/comments" | jq 'length') + echo "count=$COMMENTS_COUNT" >> $GITHUB_OUTPUT + + - name: Notify Teams + uses: softwareone-platform/notify-pr-reviews-teams-action@v2 + with: + webhook_url: ${{ secrets.TEAMS_WEBHOOK_URL }} + bot_image_url: https://raw.githubusercontent.com/softwareone-platform/mpt-api-python-client/main/.github/workflows/assets/turing_team_pr_bot.png + repo: ${{ github.repository }} + pr_number: ${{ github.event.pull_request.number }} + pr_title: ${{ github.event.pull_request.title }} + reviewer: ${{ github.event.review.user.login }} + review_state: ${{ github.event.review.state }} + global_comment: ${{ github.event.review.body || 'No comment provided' }} + comments_count: ${{ steps.comments.outputs.count }} + head_ref: ${{ github.event.pull_request.head.ref }} + base_ref: ${{ github.event.pull_request.base.ref }} + event: ${{ github.event.action }} + pr_url: ${{ github.event.pull_request.html_url }} diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 2d663576..00a8067e 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -36,6 +36,38 @@ jobs: - name: "Run validation & test" run: make check-all + - name: "Compute added/removed lines for notification" + if: ${{ github.event_name == 'pull_request' && github.actor != 'dependabot[bot]' }} + id: diff + run: | + PR_DATA=$(gh pr view "${{ github.event.pull_request.number }}" --json additions,deletions -q '.') + ADDITIONS=$(echo "$PR_DATA" | jq '.additions') + DELETIONS=$(echo "$PR_DATA" | jq '.deletions') + echo "additions=$ADDITIONS" >> $GITHUB_OUTPUT + echo "deletions=$DELETIONS" >> $GITHUB_OUTPUT + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: "Notify Microsoft Teams" + if: ${{ github.event_name == 'pull_request' && github.actor != 'dependabot[bot]' }} + uses: softwareone-platform/notify-pr-teams-action@v4 + with: + webhook_url: ${{ secrets.TEAMS_WEBHOOK_URL }} + bot_image_url: https://raw.githubusercontent.com/softwareone-platform/mpt-api-python-client/main/.github/workflows/assets/turing_team_pr_bot.png + repo: ${{ github.repository }} + pr_url: ${{ github.event.pull_request.html_url }} + pr_title: ${{ github.event.pull_request.title }} + pr_author: ${{ github.event.pull_request.user.login }} + head_ref: ${{ github.event.pull_request.head.ref }} + base_ref: ${{ github.event.pull_request.base.ref }} + commits: ${{ github.event.pull_request.commits }} + changed_files: ${{ github.event.pull_request.changed_files }} + additions: ${{ steps.diff.outputs.additions }} + deletions: ${{ steps.diff.outputs.deletions }} + pr_number: ${{ github.event.pull_request.number }} + pr_status: ${{ github.event.pull_request.state }} + is_merged: ${{ github.event.pull_request.merged }} + - name: "Run SonarCloud Scan" uses: SonarSource/sonarqube-scan-action@v8.2.2 env: