Skip to content

Commit 8e4fba1

Browse files
committed
feat: enhanced user matcher
1 parent c0f2f69 commit 8e4fba1

File tree

19 files changed

+1202
-214
lines changed

19 files changed

+1202
-214
lines changed

.github/workflows/tests.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,19 @@ jobs:
3535
with-test-data: true
3636
- name: Print Output
3737
run: echo "${{ steps.test-action.outputs.response }}"
38+
test-action-2:
39+
runs-on: ubuntu-latest
40+
steps:
41+
- name: Checkout
42+
uses: actions/checkout@v4
43+
- name: Test Action
44+
uses: ./
45+
with:
46+
github-tokens: test, ${{ secrets.GH_TOKEN_GH_NOTIFIER }}
47+
channels: C07L8EWB389
48+
user-mappings: reviewer1:coltenkrauter
49+
slack-token: ${{ secrets.SLACK_TOKEN_GH_NOTIFIER }}
50+
with-test-data: true
51+
- name: Print Output
52+
run: echo "${{ steps.test-action.outputs.response }}"
53+

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ This _GitHub Action_ will query the GitHub (or GitHub Enterprise) org for all re
4343

4444
1. (Optional) Start by creating a repository called `github-notifier`.
4545
1. Whatever repo you use to host this workflow needs to be able to use GitHub Runners.
46-
1. [Generate a GitHub token](https://github.com/settings/tokens?type=beta) – Youll need a fine-grained GitHub token with resource owner being an organization that allows access to either all your repositories or just the ones you want notifications about.
46+
1. [Generate a GitHub token](https://github.com/settings/tokens?type=beta) – You'll need a fine-grained GitHub token with resource owner being an organization that allows access to either all your repositories or just the ones you want notifications about.
4747

4848
Here are the specific permissions the token needs:
4949

@@ -93,6 +93,7 @@ This _GitHub Action_ will query the GitHub (or GitHub Enterprise) org for all re
9393
github-tokens: ${{ secrets.GH_TOKEN_GH_NOTIFIER }}, ${{ secrets.GH_TOKEN_GH_NOTIFIER_FOR_ANOTHER_ORG }}
9494
channels: C07L8EWB389
9595
slack-token: ${{ secrets.SLACK_TOKEN_GH_NOTIFIER }}
96+
user-mappings: github-user1:slack-user1, github-user2:slack-user2
9697
```
9798
9899
For more details about available inputs, you can check out the [action definition file, action.yaml](./action.yaml).
@@ -106,21 +107,37 @@ See [action.yaml](./action.yaml) for more detailed information.
106107
| `github-tokens` | Comma Comma-separated list of fine grained Github tokens (one per GitHub organization) with scopes for administration, PR details, and members.| Yes | |
107108
| `slack-token` | Permissions to post to Slack and perform user lookups. | Yes | |
108109
| `channels` | Comma-separated list of Slack channel IDs to post to. | Yes | |
110+
| `user-mappings` | Comma-separated list of GitHub to Slack username mappings in the format "github:slack". Example: "octocat:slackcat,user1:slack1" | No | |
109111
| `with-archived` | Include PRs from archived repositories. | No | `false` |
110112
| `with-public` | Include PRs from public repositories. | No | `true` |
111113
| `with-drafts` | Include draft PRs. | No | `false` | | No | `false` |
112114
| `with-user-mentions` | Allow Slack user mentions. | No | `true` |
113115
| `repository-filter` | Comma-separated list of repositories to scan. | No | |
114116
| `base-url` | Base GitHub API URL (e.g., https://api.github.com). | No | |
115117

118+
## User Matching
119+
120+
GitHub Notifier attempts to match GitHub users with their corresponding Slack accounts to properly tag users and display avatars in notifications. The matching process works in the following order:
121+
122+
1. **Custom user mappings** - Define explicit GitHub to Slack username mappings using the `user-mappings` parameter (e.g., `github-user:slack-user`). This takes highest priority.
123+
124+
2. **Fallback matching methods** - If no mapping is found or if the mapped Slack username doesn't exist, the system automatically tries to match users by:
125+
- User ID (if provided)
126+
- Email address
127+
- Username contained in email
128+
- Display name
129+
- Real name
130+
131+
This flexible matching system helps ensure that users are properly identified across both platforms, even when usernames don't match exactly.
132+
116133
## Troubleshooting
117134

118135
```
119136
Error: An API error occurred: channel_not_found
120137
```
121138
122139
123-
This error means the Slack app probably wasnt added to the channel youre trying to post in.
140+
This error means the Slack app probably wasn't added to the channel you're trying to post in.
124141
125142
## Husky
126143
@@ -134,7 +151,7 @@ This project uses a custom pre-commit hook to run `npm run bundle`. This ensures
134151
135152
## Contributing
136153
137-
The goal of this project is to continually evolve and improve its core features, making it more efficient and easier to use. Development happens openly here on GitHub, and were thankful to the community for contributing bug fixes, enhancements, and fresh ideas. Whether you're fixing a small bug or suggesting a major improvement, your input is invaluable.
154+
The goal of this project is to continually evolve and improve its core features, making it more efficient and easier to use. Development happens openly here on GitHub, and we're thankful to the community for contributing bug fixes, enhancements, and fresh ideas. Whether you're fixing a small bug or suggesting a major improvement, your input is invaluable.
138155
139156
## License
140157

action.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ inputs:
2828
channels:
2929
required: true
3030
description: Comma-separated list of Slack channel IDs to post to.
31+
user-mappings:
32+
required: false
33+
description: |
34+
Comma-separated list of GitHub to Slack username mappings in the format "github:slack".
35+
These mappings are PRIORITIZED over automatic matching between GitHub and Slack users.
36+
If a mapping is defined but the Slack username doesn't exist, it will fall back to automatic matching.
37+
The automatic matching tries to match by email and username when custom mapping fails.
38+
Used specifically during Slack user lookup for @mentions and avatars in notifications.
39+
Example: "octocat:slackcat,user1:slack1" would map GitHub username "octocat" to Slack username "slackcat".
40+
default: ""
3141
with-test-data:
3242
description: Append some test data to the Slack post.
3343
required: false

0 commit comments

Comments
 (0)