Git Product home page Git Product logo

slack-cleaner's Introduction

slack-cleaner

This action is kfei/slack-cleaner for GitHub Actions.

Generated from actions/container-action template.

Usage

Here is an example workflow setting of this action.

  1. Create a .github/workflows/slack-cleaner.yml file in your GitHub repository you want setup.

  2. Add the following code to the slack-cleaner.yml file.

# .github/workflows/slack-cleaner.yml

name: Slack Cleaner
on:
  schedule:
    - cron:  '0 0 1 * *'
jobs:
  clean:
    runs-on: ubuntu-latest
    steps:
      - uses: ken-matsui/slack-cleaner@v1
        with:
          token: ${{ secrets.SLACK_LEGACY_TOKEN }}
          message: true
          channel: 'general'
          user: '*'
          before: '20191201'
          perform: true

Input parameters

The only required parameter is token. It should be a Slack legacy token, and you can get it from https://api.slack.com/custom-integrations/legacy-tokens.

It should start with xoxp, not like bot token with xoxb.

And you need to set it to your GitHub repository secrets.

Please refer https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets to know how to do that and for more details.

Parameter Name Required Default Description
token N/A Slack API legacy token
rate × N/A Delay between API calls (in seconds)
message × false Delete messages
file × false Delete files
channel × N/A Channel name's, e.g., general
direct × N/A Direct message's name, e.g., sherry
group × N/A Private group's name
mpdirect × N/A Multiparty direct message's name, e.g., sherry,james,johndoe
user × N/A Delete messages/files from certain user
bot × false Delete messages from bots
after × N/A Delete messages/files newer than this time (YYYYMMDD)
before × N/A Delete messages/files older than this time (YYYYMMDD)
types × N/A Delete files of a certain type, e.g., posts,pdfs
perform × false Perform the task

Examples

Progammatic Parameter

Expand to see an example workflow
# .github/workflows/slack-cleaner.yml

name: Slack Cleaner
on:
  schedule:
    - cron:  '0 0 1 * *'
jobs:
  clean:
    runs-on: ubuntu-latest
    steps:
      - name: Get datetime
        id: datetime
        run: echo "::set-output name=value::$(date -d '-5 days' '+%Y%m%d')"
      - uses: ken-matsui/slack-cleaner@v1
        with:
          token: ${{ secrets.SLACK_LEGACY_TOKEN }}
          rate: '1'
          message: true
          channel: 'notifications'
          user: '*'
          before: ${{ steps.datetime.outputs.value }}
          perform: true

Delete all messages from a channel

Expand to see an example workflow
# .github/workflows/slack-cleaner.yml

name: Slack Cleaner
on: push
jobs:
  clean:
    runs-on: ubuntu-latest
    steps:
      - uses: ken-matsui/slack-cleaner@v1
        with:
          token: ${{ secrets.SLACK_LEGACY_TOKEN }}
          message: true
          channel: 'general'
          user: '*'
          perform: true

Delete all messages from a private group

Expand to see an example workflow
# .github/workflows/slack-cleaner.yml

name: Slack Cleaner
on: push
jobs:
  clean:
    runs-on: ubuntu-latest
    steps:
      - uses: ken-matsui/slack-cleaner@v1
        with:
          token: ${{ secrets.SLACK_LEGACY_TOKEN }}
          message: true
          group: 'hr'
          user: '*'
          perform: true

Delete all messages from a direct message channel

Expand to see an example workflow
# .github/workflows/slack-cleaner.yml

name: Slack Cleaner
on: push
jobs:
  clean:
    runs-on: ubuntu-latest
    steps:
      - uses: ken-matsui/slack-cleaner@v1
        with:
          token: ${{ secrets.SLACK_LEGACY_TOKEN }}
          message: true
          direct: 'sherry'
          user: 'johndoe'
          perform: true

Delete all messages from a multiparty direct message channel

Expand to see an example workflow

Note: that the list of usernames must contains yourself.

# .github/workflows/slack-cleaner.yml

name: Slack Cleaner
on: push
jobs:
  clean:
    runs-on: ubuntu-latest
    steps:
      - uses: ken-matsui/slack-cleaner@v1
        with:
          token: ${{ secrets.SLACK_LEGACY_TOKEN }}
          message: true
          mpdirect: 'sherry,james,johndoe'
          user: '*'
          perform: true

Delete all messages from certain user

Expand to see an example workflow
# .github/workflows/slack-cleaner.yml

name: Slack Cleaner
on: push
jobs:
  clean:
    runs-on: ubuntu-latest
    steps:
      - uses: ken-matsui/slack-cleaner@v1
        with:
          token: ${{ secrets.SLACK_LEGACY_TOKEN }}
          message: true
          channel: 'gossip'
          user: 'johndoe'
          perform: true

Delete all messages from bots (especially flooding CI updates)

Expand to see an example workflow
# .github/workflows/slack-cleaner.yml

name: Slack Cleaner
on: push
jobs:
  clean:
    runs-on: ubuntu-latest
    steps:
      - uses: ken-matsui/slack-cleaner@v1
        with:
          token: ${{ secrets.SLACK_LEGACY_TOKEN }}
          message: true
          channel: 'auto-build'
          bot: true
          perform: true

Delete all messages older than 2015/09/19

Expand to see an example workflow
# .github/workflows/slack-cleaner.yml

name: Slack Cleaner
on: push
jobs:
  clean:
    runs-on: ubuntu-latest
    steps:
      - uses: ken-matsui/slack-cleaner@v1
        with:
          token: ${{ secrets.SLACK_LEGACY_TOKEN }}
          message: true
          channel: 'general'
          user: '*'
          before: '20150919'
          perform: true

Delete all files

Expand to see an example workflow
# .github/workflows/slack-cleaner.yml

name: Slack Cleaner
on: push
jobs:
  clean:
    runs-on: ubuntu-latest
    steps:
      - uses: ken-matsui/slack-cleaner@v1
        with:
          token: ${{ secrets.SLACK_LEGACY_TOKEN }}
          file: true
          user: '*'
          perform: true

Delete all files from certain user

Expand to see an example workflow
# .github/workflows/slack-cleaner.yml

name: Slack Cleaner
on: push
jobs:
  clean:
    runs-on: ubuntu-latest
    steps:
      - uses: ken-matsui/slack-cleaner@v1
        with:
          token: ${{ secrets.SLACK_LEGACY_TOKEN }}
          file: true
          user: 'johndoe'
          perform: true

Delete all snippets and images

Expand to see an example workflow
# .github/workflows/slack-cleaner.yml

name: Slack Cleaner
on: push
jobs:
  clean:
    runs-on: ubuntu-latest
    steps:
      - uses: ken-matsui/slack-cleaner@v1
        with:
          token: ${{ secrets.SLACK_LEGACY_TOKEN }}
          file: true
          types: 'snippets,images'
          perform: true

LICENSE

This project is licensed under the MIT License.

slack-cleaner's People

Contributors

ken-matsui avatar

Stargazers

Dustin Falgout avatar

Watchers

 avatar

Forkers

jaredh159

slack-cleaner's Issues

programatic "before" example doesn't work

in the README.md it says we can do this:

before: "$(date -v -1m '+%Y%m%d')"  # You can use bash style command.

But I found that this did not work. First of all the -v date offset, is for BSD date which works on a Mac, but not on Ubuntu.

Second, even after correcting the date syntax, it wasn't getting passed through to the command correctly inside the Docker container. I tried a bunch of things, but I finally got it working by doing this:

# .github/workflows/slack-cleaner.yml

name: Slack Cleaner
on:
  schedule:
    - cron:  '0 0 1 * *'
jobs:
  clean:
    runs-on: ubuntu-latest
    steps:
      - name: Set env
        run: echo ::set-env name=BEFORE::$(date -d '-5 days' '+%Y%m%d') # <-- set env
      - uses: matken11235/slack-cleaner@v1
        with:
          group: mychannel
          before: ${{ env.BEFORE }} # <-- use env
          rate: '1'
          message: true
          bot: true
          perform: true
          token: ${{ secrets.SLACK_LEGACY_TOKEN }

I'd be happy to PR the change to the readme, if you'd like.

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.