-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add action to get slack name based on email (#117)
- Loading branch information
Showing
4 changed files
with
92 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters