-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathcollaborators.yml
More file actions
59 lines (54 loc) · 2.25 KB
/
collaborators.yml
File metadata and controls
59 lines (54 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: Manage a collaborator
on:
workflow_dispatch:
inputs:
email:
description: "The collaborator's email address"
required: true
type: string
add:
description: "Checked to add, unchecked to remove"
required: false
default: true
type: boolean
jobs:
collaborator:
name: Add or remove a collaborator
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Look up the Slack user by email
id: email
uses: slackapi/slack-github-action@v3.0.1
with:
method: users.lookupByEmail # https://docs.slack.dev/reference/methods/users.lookupByEmail/
token: ${{ secrets.SLACK_BOT_TOKEN }}
payload: |
email: ${{ inputs.email }}
- name: Gather the display name
if: ${{ steps.email.outputs.ok }}
run: |
SLACK_USER_ID=$(echo '${{ steps.email.outputs.response }}' | jq -r '.user.id')
SLACK_DISPLAY_NAME=$(echo '${{ steps.email.outputs.response }}' | jq -r '(.user.profile.display_name | select(. != "")) // .user.real_name')
echo "SLACK_USER_ID=$SLACK_USER_ID" >> "$GITHUB_ENV"
echo "SLACK_DISPLAY_NAME=$SLACK_DISPLAY_NAME" >> "$GITHUB_ENV"
- name: Add or remove the collaborator
if: ${{ steps.email.outputs.ok }}
uses: slackapi/slack-github-action/cli@v3.0.1
with:
command: "collaborators ${{ inputs.add && 'add' || 'remove' }} ${{ inputs.email }} --app ${{ vars.SLACK_APP_ID }}"
token: ${{ secrets.SLACK_SERVICE_TOKEN }}
- name: Post a confirmation message
if: ${{ steps.email.outputs.ok }}
uses: slackapi/slack-github-action@v3.0.1
with:
errors: true
method: chat.postMessage # https://docs.slack.dev/reference/methods/chat.postMessage/
token: ${{ secrets.SLACK_BOT_TOKEN }}
payload: |
channel: ${{ secrets.SLACK_CHANNEL_ID }}
text: "<@${{ env.SLACK_USER_ID }}> (${{ env.SLACK_DISPLAY_NAME }}) was ${{ inputs.add && 'added to' || 'removed from' }} the app collaborators."