Skip to content

Commit

Permalink
feat: add action to get slack name based on email (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
denieler authored Feb 14, 2023
1 parent 71dc679 commit 0f78c59
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 6 deletions.
9 changes: 9 additions & 0 deletions .changeset/fresh-crabs-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'davinci-github-actions': minor
---

---

### get-user-slack-from-email

- add new github action
42 changes: 42 additions & 0 deletions get-user-slack-from-email/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## Get user slack from email

Get user slack handler based on user email

### Description

This GH Action checks if user login belongs to the team member

### Inputs

The list of arguments, that are used in GH Action:

| name | type | required | default | description |
| ----------------- | ------ | -------- | ------- | -------------------------------------------------------------------------------------------------------- |
| `email` | string || | User email |
| `slack-bot-token` | string || | Slack bot token with scope "users:read.email" **Read-only**. If undefined, `env.SLACK_BOT_TOKEN` is used |

### Outputs

The list of variables, that are returned by GH Action:

| name | type | description |
| -------------- | ------ | ------------- |
| `slack-userId` | string | Slack user id |

### ENV Variables

All ENV Variables, defined in a GH Workflow are also passed to a GH Action. It means, the might be reused as is.
This is a list of ENV Variables that are used in GH Action:

| name | description |
| ----------------- | ------------------------------------------------------------ |
| `SLACK_BOT_TOKEN` | Slack bot token with scope "users:read.email" **Read-only**. |

### Usage

```yaml
- uses: toptal/davinci-github-actions/[email protected]
with:
email: [email protected]
slack-bot-token: slack-bot-token
```
35 changes: 35 additions & 0 deletions get-user-slack-from-email/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Get user slack from email
description: |
Get user slack handler based on user email
****
envInputs:
SLACK_BOT_TOKEN: Slack bot token with scope "users:read.email" **Read-only**.
inputs:
email:
required: true
description: User email
slack-bot-token:
required: true
description: Slack bot token with scope "users:read.email" **Read-only**. If undefined, `env.SLACK_BOT_TOKEN` is used

outputs:
slack-userId:
description: "Slack user id"
value: ${{ steps.slack-user.outputs.slackId }}

runs:
using: composite
steps:
- name: Get slack user name
id: slack-user
shell: bash
env:
SLACK_BOT_TOKEN: ${{ inputs.slack-bot-token || env.SLACK_BOT_TOKEN }}
run: |
data=$(curl -X POST https://slack.com/api/users.lookupByEmail \
-H "Authorization: Bearer ${{ env.SLACK_BOT_TOKEN }}" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'email=${{ inputs.email }}')
echo $data
slackId=$(echo $data | jq -r '.user.id')
echo "slackId=$slackId" >> $GITHUB_OUTPUT
12 changes: 6 additions & 6 deletions yarn-install/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ Installs package dependencies. Caches `node_modules` for faster subsequent insta

The list of arguments, that are used in GH Action:

| name | type | required | default | description |
| --------------- | ------ | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------- |
| `npm-token` | string | | | Access token type **Read-only**. Required for repository with private dependencies. If undefined, `env.NPM_TOKEN` is used |
| `cache-version` | string | | 0.0 | Cache version |
| `path` | string | | . | Relative path under $GITHUB\_WORKSPACE where to run `yarn install` command |
| `checkout-token` | string | | | Repository checkout access token `GITHUB_TOKEN`. Required for self hosted runners command |
| name | type | required | default | description |
| ---------------- | ------ | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------- |
| `npm-token` | string | | | Access token type **Read-only**. Required for repository with private dependencies. If undefined, `env.NPM_TOKEN` is used |
| `cache-version` | string | | 0.0 | Cache version |
| `path` | string | | . | Relative path under $GITHUB\_WORKSPACE where to run `yarn install` command |
| `checkout-token` | string | | | Repository checkout access token `GITHUB_TOKEN`. Required for self hosted runners |

### Outputs

Expand Down

0 comments on commit 0f78c59

Please sign in to comment.