Giter VIP home page Giter VIP logo

slack-templates's Introduction

slack-templates

GitHub Action: Try Me Slack Templates Test Workflow Status Copy/Paste: 0%

Automated Updates: Renovate Language: Python Package Management: Poetry Git Hooks: pre-commit Commit Style: Conventional Commits Releases: Semantic Versioning Code Style: Prettier Code Style: Black Code Style: EditorConfig Code Style: Ruff Security: Bandit Editor: Visual Studio Code

Send Informative, Concise Slack Notifications With Minimal Effort

Slack Integration

  • Create a custom Slack app with the chat:write scope.
  • Install the app to your workspace, and copy the provided OAuth access token.
  • Create a GitHub secret to store the bot token.
  • Invite your bot to the desired channel.
  • Secondary-click on the channel, and select โ€œCopy link.โ€
  • Create a GitHub secret to store the final portion of the path. The channel ID is neither the name of the channel nor the URL.

Available Templates

The template parameter controls the structure of the Slack notification. Here are all currently supported templates:

  • result:
    • pull_request event: <workflow> <result> for <PR #> from <branch> on <repository> by <username>.
    • push event:
      • merge of pull request: <workflow> <result> for merge of <PR #> to <branch> on <repository> by <username>.
      • direct push of branch: <workflow> <result> for push of <sha> to <branch> on <repository> by <username>.
  • reviewers:
    • requester != reviewer: <requester> requests review from <reviewers> of <PR #> from <branch> on <repository>.
    • requester == reviewer: <username> self-requests review of <PR #> from <branch> on <repository>.
  • assignee:
    • assignor != assignee: <assignor> assigned <assignee> <PR #> from <branch> on <repository>.
    • assignor == assignee: <username> self-assigned <PR #> from <branch> on <repository>.
  • custom: Pass your custom message via the message parameter.

All usernames refer to GitHub usernames. Users with differing Slack and GitHub usernames may wish to register their GitHub username for Slack keyword notifications. Workflow names, pull request numbers, commit shas, branches, and repositories all link to the pertinent GitHub page. If you would like to see a template added, please open an issue or better still a pull request.

Reliably determining the pull request associated with a push event requires read permissions on the contents scope. Even the restrictive defaults grant this permission. If permissions are granted explicitly and contents: read is excluded, the commit sha will be reported instead of the pull request number, because merges will be indistinguishable from direct pushes.

Usage

Report the status of the current job

  • Add the following step to the bottom of the job:

    - name: Send Slack notification with job status.
      if: always()
      uses: ScribeMD/[email protected]
      with:
        bot-token: ${{ secrets.SLACK_TEMPLATES_BOT_TOKEN }}
        channel-id: ${{ secrets.SLACK_TEMPLATES_CHANNEL_ID }}
        template: result

Summarize the results of an entire workflow

  • Create a new job at the end of the workflow that depends on (a.k.a., needs) all other jobs but always runs.
  • Pass "${{ join(needs.*.result, ' ') }}" as the results.

The result of the entire workflow is the highest ranking of all results given. The ranking is as follows:

  1. failure
  2. cancelled
  3. success
  4. skipped
name: My Workflow
on:
  pull_request:
    branches:
      - main
  push:
    branches:
      - main
jobs:
  job1: ...
  job2: ...
  job3: ...
  notify:
    if: always()
    needs:
      - job1
      - job2
      - job3
    runs-on: ubuntu-latest
    steps:
      - name: Send Slack notification with workflow result.
        uses: ScribeMD/[email protected]
        with:
          bot-token: ${{ secrets.SLACK_TEMPLATES_BOT_TOKEN }}
          channel-id: ${{ secrets.SLACK_TEMPLATES_CHANNEL_ID }}
          template: result
          results: "${{ join(needs.*.result, ' ') }}"

Report a custom result

  • Determine what result to send in preceding steps.
  • Report the result at the bottom of the job as before.
  • Take care to quote results for use as a Bash command line argument.
- name: Detect third-party network outage.
  id: network
  run: |
    ...
    echo "OUTAGE=$OUTAGE" >>"$GITHUB_OUTPUT"
  shell: bash
- name: Send Slack notification with custom result.
  if: always() && steps.network.outputs.OUTAGE == 'true'
  uses: ScribeMD/[email protected]
  with:
    bot-token: ${{ secrets.SLACK_TEMPLATES_BOT_TOKEN }}
    channel-id: ${{ secrets.SLACK_TEMPLATES_CHANNEL_ID }}
    template: result
    results: '"failure caused by third-party network outage"'

Notify reviewers of a pull request

name: Notify Reviewers
on:
  pull_request:
    types:
      - review_requested
jobs:
  notify-reviewers:
    runs-on: ubuntu-latest
    steps:
      - name: Send Slack notification requesting code review.
        uses: ScribeMD/[email protected]
        with:
          bot-token: ${{ secrets.SLACK_TEMPLATES_BOT_TOKEN }}
          channel-id: ${{ secrets.SLACK_TEMPLATES_CHANNEL_ID }}
          template: reviewers

Notify assignee of a pull request

name: Notify Assignee
on:
  pull_request:
    types:
      - assigned
jobs:
  notify-assignee:
    runs-on: ubuntu-latest
    steps:
      - name: Send Slack notification assigning pull request.
        uses: ScribeMD/[email protected]
        with:
          bot-token: ${{ secrets.SLACK_TEMPLATES_BOT_TOKEN }}
          channel-id: ${{ secrets.SLACK_TEMPLATES_CHANNEL_ID }}
          template: assignee

Send a custom notification

- name: Send custom Slack notification.
  if: always()
  uses: ScribeMD/[email protected]
  with:
    bot-token: ${{ secrets.SLACK_TEMPLATES_BOT_TOKEN }}
    channel-id: ${{ secrets.SLACK_TEMPLATES_CHANNEL_ID }}
    message: "${{ github.actor }} requests approval to run workflow."

Inputs

Required

bot-token

The Slack API bot token for your custom app with chat:write scope.

channel-id

The ID of a Slack channel to send notifications to. Your bot should be a member. Secondary-click on the channel in Slack, and select Copy link to copy a URL containing the channel ID.

Optional

template

default: custom

The type of Slack notification to send:

  • assignee
  • custom (requires message)
  • reviewers
  • result

results (template: result only)

default: ${{ job.status }}

The job results to report via Slack. To report the result of an entire workflow, use this action from a final notify job that depends on (a.k.a., needs) all other jobs. Then, pass join(needs.*.result, ' '). The highest ranking result will be reported:

  1. failure
  2. cancelled
  3. success
  4. skipped

Alternatively, a custom result may be passed provided that it is quoted for use as a Bash command line argument.

message (template: custom only)

default: Pass message or template to slack-templates.

A custom Slack message to send.

Relation to slack-send

This action wraps slack-send, its only runtime dependency, inheriting slack-send's support for all GitHub-hosted runners. There are three principal differences between these actions:

  • slack-templates offers some default messages; slack-send presently does not.
  • slack-send supports Slack's Workflow Builder (unavailable on free Slack plan) in addition to Slack apps. slack-templates only supports Slack apps.
  • slack-send accepts the bot token as environment variable SLACK_BOT_TOKEN. slack-templates accepts it as the input parameter bot-token.

Bug Reports

If you are not receiving notifications, please review the Slack Integration section and then file a bug report containing the GitHub Action's logs if that doesn't resolve your issue. If you are receiving nondescript Slack notifications, please file a bug report with the notification you received taking care to preserve the links.

Permissions

The contents:read and pull-requests:read permissions are required in private repositories to determine the pull request associated with a push event since the push event itself doesn't contain this information.

Changelog

Please refer to CHANGELOG.md.

slack-templates's People

Contributors

dependabot[bot] avatar kurt-von-laven avatar mwarres avatar renovate-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

slack-templates's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Pending Approval

These branches will be created by Renovate only once you click their checkbox below.

  • chore(deps): bump poetry from v1.8.2 to v1.8.3
  • chore(deps): bump pre-commit hook princetonuniversity/blocklint to v0.2.5
  • chore(deps): bump scribemd/pre-commit-action action to v0.9.129
  • fix(deps): bump actions/checkout action to v4.1.6
  • fix(engines): bump python from v3.12.2 to v3.12.3
  • chore(deps): bump autopep8 to v2.1.1 (autopep8, hhatto/autopep8)
  • chore(deps): bump commitizen to v3.27.0 (commitizen, commitizen-tools/commitizen)
  • chore(deps): bump node from v20.11.1 to v20.13.1
  • chore(deps): bump pre-commit from v3.6.2 to v3.7.1
  • chore(deps): bump pre-commit hook pre-commit/pre-commit-hooks to v4.6.0
  • chore(deps-dev): bump megalinter (MegaLinter, bandit, black, mypy, pylint, ruff)
  • fix(deps): bump actions/setup-python action to v5.1.0
  • fix(deps): bump slackapi/slack-github-action action to v1.26.0
  • chore(deps): bump pre-commit hook frnmst/md-toc to v9.0.0
  • ๐Ÿ” Create all pending approval PRs at once ๐Ÿ”

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): lock file maintenance

Detected dependencies

asdf
.tool-versions
  • node 20.11.1
  • python 3.12.2
  • poetry 1.8.2
github-actions
.github/workflows/notify-assignee.yaml
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • ubuntu 22.04
.github/workflows/notify-reviewers.yaml
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • ubuntu 22.04
.github/workflows/test.yaml
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • ScribeMD/pre-commit-action 0.9.127@832e026101148e0234fde20eecf91c08942ace4a
  • ubuntu 22.04
action.yaml
  • actions/setup-python v5.0.0@0a5c61591373683505ea898e09a3ea4f39ef2b9c
  • slackapi/slack-github-action v1.24.0@e28cf165c92ffef168d23c5c9000cffc8a25e117
pep621
pyproject.toml
  • poetry-core ==1.9.0
poetry
pyproject.toml
  • python ==3.12.2
  • autopep8 ==2.0.4
  • bandit ==1.7.6
  • black ==24.3.0
  • commitizen ==3.18.4
  • mypy ==1.7.1
  • pre-commit ==3.6.2
  • pycodestyle ==2.11.1
  • pylint ==3.0.3
  • ruff ==0.1.8
pre-commit
.pre-commit-config.yaml
  • ScribeMD/pre-commit-hooks 0.16.3
  • hhatto/autopep8 v2.0.4
  • PyCQA/docformatter v1.7.5
  • frnmst/md-toc 8.2.3
  • pre-commit/pre-commit-hooks v4.5.0
  • PrincetonUniversity/blocklint v0.2.4
  • commitizen-tools/commitizen v3.18.4
  • jumanjihouse/pre-commit-hooks 3.0.0
regex
.github/renovate.json
  • ScribeMD/.github 0.14.16
.pre-commit-config.yaml
  • python 3.12.2
.pre-commit-config.yaml
  • MegaLinter v7.7.0
.mega-linter.yaml
  • ScribeMD/.github 0.14.16

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.