Skip to content

Commit 559c412

Browse files
authored
feat: mention maintainers in the slack security auditing. (#567)
1 parent 18cf161 commit 559c412

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

.github/workflows/security-audit.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,32 @@ jobs:
138138
COMMIT_URL: ${{ github.event.head_commit.url }}
139139
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
140140
COMMIT_AUTHOR: ${{ github.event.head_commit.author.username || github.event.head_commit.author.name }}
141+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
142+
REPO: ${{ github.repository }}
143+
shell: bash
141144
run: |
142145
FINDINGS=$(cat /tmp/audit_result.txt)
143146
COMMIT_TITLE=$(printf '%s\n' "$COMMIT_MESSAGE" | head -n1)
144147
145-
printf -v HEADER '*Security Audit Finding*\n*Commit:* <%s|%s>\n*Author:* %s\n\n---\n\n' \
146-
"$COMMIT_URL" "$COMMIT_TITLE" "$COMMIT_AUTHOR"
148+
# GitHub username -> Slack member ID. Entries here are only tagged
149+
# when the GitHub API confirms the user currently has the admin or
150+
# maintain role on this repo, so stale entries are inert.
151+
declare -A SLACK_IDS=(
152+
["danieldk"]="U072206PXLK"
153+
["drbh"]="U06C9TW7RDY"
154+
["sayakpaul"]="U03AU4E7DJB"
155+
)
156+
157+
MENTION=""
158+
if [ -n "${SLACK_IDS[$COMMIT_AUTHOR]:-}" ]; then
159+
ROLE=$(gh api "repos/${REPO}/collaborators/${COMMIT_AUTHOR}/permission" --jq '.role_name' 2>/dev/null || true)
160+
if [ "$ROLE" = "admin" ] || [ "$ROLE" = "maintain" ]; then
161+
MENTION="<@${SLACK_IDS[$COMMIT_AUTHOR]}> "
162+
fi
163+
fi
164+
165+
printf -v HEADER '%s*Security Audit Finding*\n*Commit:* <%s|%s>\n*Author:* %s\n\n---\n\n' \
166+
"$MENTION" "$COMMIT_URL" "$COMMIT_TITLE" "$COMMIT_AUTHOR"
147167
148168
jq -n \
149169
--arg text "${HEADER}${FINDINGS}" \

0 commit comments

Comments
 (0)