Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
victoralfaro-dotcms committed Jun 29, 2024
1 parent ae031ab commit 0bb0f87
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 6 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/frontend-technology-notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,20 @@ jobs:
id: resolve-members
if: steps.evaluate-actions.outputs.issue_number
shell: bash
issue-29032-frontend-notify-when-issue-edited
env:
UIUX_TEAM: 'ui/ux'
run: |
githack_host=raw.githack.com
githack_core_repo_url=https://${githack_host}/${{ github.repository }}
branch=/${{ github.head_ref }}
branch=master
# Remove me
branch=/issue-29032-frontend-notify-when-issue-edited
branch=issue-29032-frontend-notify-when-issue-edited
github_teams_file=github-teams.json
github_teams_path=.github/data/${github_teams_file}
github_teams_url=${githack_core_repo_url}${branch}/${github_teams_path}
github_teams_url=${githack_core_repo_url}/${branch}/${github_teams_path}
json=$(curl -s ${github_teams_url})
members=$(jq -r ".[] | select(.team == \"${{ env.UIUX_TEAM }}\") | .members[]" <<< "${json}" | tr '\n' ' ' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
Expand All @@ -84,6 +86,7 @@ jobs:
uses: ./.github/workflows/slack-channel-resolver.yml
with:
github_users: ${{ needs.resolve-data.outputs.members }}
branch: issue-29032-frontend-notify-when-issue-edited
secrets:
CI_MACHINE_USER: ${{ secrets.CI_MACHINE_USER }}
CI_MACHINE_TOKEN: ${{ secrets.CI_MACHINE_TOKEN }}
Expand Down
130 changes: 130 additions & 0 deletions .github/workflows/github-member-resolver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# action.yml
name: 'Github Members Resolver'
on:
workflow_call:
inputs:
team:
description: 'Team'
type: string
required: true
branch:
description: 'Branch'
type: string
required: false
default: master
outputs:
members:
value: ${{ jobs.github-members-resolver.outputs.members }}

jobs:
github-members-resolver:
runs-on: ubuntu-20.04
outputs:
members: ${{ steps.resolve-members.outputs.members }}
steps:
- name: Resolve Members
id: resolve-members
continue-on-error: true
shell: bash
run: |
githack_host=raw.githack.com
githack_core_repo_url=https://${githack_host}/${{ github.repository }}
github_teams_url=${githack_core_repo_url}/${{ inputs.branch }}/.github/data/github-teams.json
json=$(curl -s ${github_teams_url})
members=$(jq -r ".[] | select(.team == \"${{ inputs.team }}\") | .members[]" <<< "${json}" | tr '\n' ' ' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
echo "Found members: [${members}]"
declare -A deduped_array
for element in "${members[@]}"; do
deduped_array["$element"]=1
done
deduped_members=("${!deduped_array[@]}")
members=$(echo "${deduped_members[@]}")
echo "members=[${members}]"
echo "members=${members}" >> $GITHUB_OUTPUT
- name: Resolve Channels
id: resolve-channels
continue-on-error: true
shell: bash
run: |
github_users=${{ steps.resolve-users.outputs.github_users }}
echo "Found github users: [${github_users}]"
githack_host=raw.githack.com
githack_core_repo_url=https://${githack_host}/${{ github.repository }}
slack_mappings_file=slack-mappings.json
slack_mappings_path=.github/data/${slack_mappings_file}
slack_mapping_url=${githack_core_repo_url}/${{ inputs.branch }}/${slack_mappings_path}
channel_ids=
github_users_array=(${github_users})
for github_user in "${github_users_array[@]}"; do
if [[ -n "${github_user}" ]]; then
json=$(curl -s ${slack_mapping_url})
channel_id=$( \
jq ".[] | select(.github_user == \"${github_user}\")" <<< "${json}" | \
jq -r '.slack_id' \
)
echo "Resolved channel id [${channel_id}] from [${slack_mappings_file}]"
if [[ -z "${channel_id}" ]]; then
echo "Channel id could not be resolved from [${slack_mappings_file}]. Attempting to resolve from Github user email."
user_email=$( \
curl \
-u ${{ secrets.CI_MACHINE_USER }}:${{ secrets.CI_MACHINE_TOKEN }} \
--request GET \
-s \
https://api.github.com/users/${github_user} | \
grep "\"email\":" | \
sed "s/\"email\"://g" | \
tr -d '",[:space:]' \
)
echo "Resolved user email: [${user_email}]"
if [[ -n "${user_email}" ]]; then
channel_id=$( \
curl \
--request GET \
--header "Content-type: application/json" \
--header "Authorization: Bearer ${{ secrets.SLACK_BOT_TOKEN }}" \
-s \
"https://slack.com/api/users.lookupByEmail?email=${user_email}" | \
python3 -m json.tool | \
grep "\"id\":" | \
sed "s/\"id\"://g" | \
tr -d '",[:space:]' \
)
echo "Resolved channel id [${channel_id}] from email [${user_email}]"
fi
fi
fi
[[ -n "${channel_id}" ]] && channel_ids="${channel_ids} ${channel_id}"
done
default_channel_id=${{ inputs.default_channel_id }}
[[ -z "${channel_ids}" && -n "${default_channel_id}" ]] \
&& echo "Channel id could not be resolved, defaulting to channel id: [${default_channel_id}]" \
&& channel_ids=${default_channel_id}
channel_ids=$(echo "${channel_ids}" | tr -d '[:space:]')
if [[ -n "${channel_ids}" ]]; then
channel_ids_array=(${channel_ids})
declare -A deduped_array
for element in "${channel_ids_array[@]}"; do
deduped_array["$element"]=1
done
deduped_channel_ids=("${!deduped_array[@]}")
channel_ids=$(printf '%s\n' "${deduped_channel_ids[@]}" | jq -R . | jq -s .)
fi
echo "channel_ids: [${channel_ids}]"
echo "channel_ids=${channel_ids}" >> $GITHUB_OUTPUT
9 changes: 6 additions & 3 deletions .github/workflows/slack-channel-resolver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ on:
description: 'Default channel ID'
type: string
required: false
branch:
description: 'Branch'
type: string
required: false
default: master
outputs:
channel_ids:
value: ${{ jobs.slack-channel-resolver.outputs.channel_ids }}
Expand Down Expand Up @@ -58,10 +63,8 @@ jobs:
githack_host=raw.githack.com
githack_core_repo_url=https://${githack_host}/${{ github.repository }}
branch=/${{ github.head_ref }}
slack_mappings_file=slack-mappings.json
slack_mappings_path=.github/data/${slack_mappings_file}
slack_mapping_url=${githack_core_repo_url}${branch}/${slack_mappings_path}
slack_mapping_url=${githack_core_repo_url}/${{ inputs.branch }}/.github/data/${slack_mappings_file}
channel_ids=
github_users_array=(${github_users})
Expand Down

0 comments on commit 0bb0f87

Please sign in to comment.