Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ken-matsui/slack-cleaner

slack-cleaner for GitHub Actions
https://github.com/ken-matsui/slack-cleaner

github-actions slack

Last synced: 23 days ago
JSON representation

slack-cleaner for GitHub Actions

Awesome Lists containing this project

README

        

# slack-cleaner

This action is [kfei/slack-cleaner](https://github.com/kfei/slack-cleaner) for GitHub Actions.

Generated from [actions/container-action](https://github.com/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.

```yml
# .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

```yml
# .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

```yml
# .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

```yml
# .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

```yml
# .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.**

```yml
# .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

```yml
# .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

```yml
# .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

```yml
# .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

```yml
# .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

```yml
# .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

```yml
# .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](LICENSE).