Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
victoralfaro-dotcms committed Sep 12, 2024
1 parent 8e28e8e commit 3001595
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 33 deletions.
30 changes: 16 additions & 14 deletions .github/workflows/cicd_scheduled_notify-seated-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
- name: Filter execution
id: filter-execution
uses: actions/github-script@v7
with:
result-encoding: string
Expand All @@ -33,11 +34,13 @@ jobs:
console.log(new Date());
if (day === 0 || day === 6) {
console.log('It\'s (happy) weekend, not sending any notifications');
process.exit(1);
process.exit(0);
}
core.setOutput('continue', 'true');
- id: fetch-seated-prs
name: Fetch Seated PRs
if: success()
if: success() && steps.filter-execution.outputs.continue == 'true'
uses: actions/github-script@v7
with:
result-encoding: string
Expand Down Expand Up @@ -152,24 +155,23 @@ jobs:
result-encoding: string
script: |
const urlMapper = (pr) => `- ${pr.url}`;
const prDayThreshold = ${{ env.PR_DAY_THRESHOLD }};
const draftPrDayThreshold = ${{ env.DRAFT_PR_DAY_THRESHOLD }};
const seatedPrs = ${{ needs.resolve-seated-prs.outputs.seated_prs }}
const memberIds = ${{ needs.resolve-seated-prs.outputs.members_json }}
const missingGithubUsers = ${{ needs.slack-channel-resolver.outputs.missing_github_users }}
const members = memberIds.filter(id => !missingGithubUsers.includes(id));
const mappings = ${{ fromJSON(needs.slack-channel-resolver.outputs.mappings_json) }};
const foundMapping = mappings.find(mapping => mapping.slack_id === member)
if (!found) {
core.warning(`Slack user Id [${member}] cannot be found, exiting`);
process.exit(0);
}

const members = ${{ needs.resolve-seated-prs.outputs.members_json }}
const channels = ${{ needs.slack-channel-resolver.outputs.channel_ids }}
console.log(JSON.stringify(members, null, 2));
console.log(JSON.stringify(channels, null, 2));

const idx = channels.findIndex(channel => channel === '${{ matrix.member }}');
if (idx === -1) {
console.log('Could not find channel [${{ matrix.member }}], skipping this');
process.exit(2);
}
const login = members[idx];
const login = foundMapping.github_user;
const userPrs = seatedPrs.find(pr => pr.login === login);
const prs = userPrs.prs.filter(pr => !pr.draft).map(urlMapper);
const draftPrs = userPrs.prs.filter(pr => pr.draft).map(urlMapper);
Expand All @@ -190,7 +192,7 @@ jobs:

core.setOutput('message', message);
- name: Notify member
if: success()
if: success() && steps.build-message.outputs.message != ''
shell: bash
run: |
channel=${{ matrix.member }}
Expand Down
23 changes: 4 additions & 19 deletions .github/workflows/utility_slack-channel-resolver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ on:
outputs:
channel_ids:
value: ${{ jobs.slack-channel-resolver.outputs.channel_ids }}
missing_github_users:
value: ${{ jobs.slack-channel-resolver.outputs.missing_github_users }}
mappings_json:
value: ${{ jobs.slack-channel-resolver.outputs.mappings_json }}
secrets:
CI_MACHINE_USER:
description: 'CI machine user'
Expand All @@ -47,7 +47,7 @@ jobs:
runs-on: ubuntu-20.04
outputs:
channel_ids: ${{ steps.resolve-channels.outputs.channel_ids }}
missing_github_users: ${{ steps.resolve-channels.outputs.missing_github_users }}
mappings_json: ${{ steps.resolve-channels.outputs.mappings_json }}
steps:
- name: Resolve Users
id: resolve-users
Expand Down Expand Up @@ -77,7 +77,6 @@ jobs:
echo "Looking for [${github_user}]"
channel_ids=
missing_github_users=
for github_user in "${github_users_array[@]}"; do
channel_id=$( \
jq ".[] | select(.github_user == \"${github_user}\")" <<< "${json}" | \
Expand Down Expand Up @@ -121,8 +120,6 @@ jobs:
if [[ -n "${channel_id}" && "${channel_id}" != 'null' ]]; then
channel_ids="${channel_ids} ${channel_id}"
else
missing_github_users="${missing_github_users} ${github_user}"
fi
done
Expand All @@ -143,18 +140,6 @@ jobs:
channel_ids=$(printf '%s\n' "${deduped_channel_ids[@]}" | jq -R . | jq -s . | tr -d '\n' | tr -d ' ')
fi
if [[ -n "${missing_github_users}" ]]; then
missing_github_users_array=(${missing_github_users})
declare -A github_user_deduped_array
for element in "${missing_github_users_array[@]}"; do
github_user_deduped_array["$element"]=1
done
deduped_github_users=("${!github_user_deduped_array[@]}")
missing_github_users=$(printf '%s\n' "${deduped_github_users[@]}" | jq -R . | jq -s . | tr -d '\n' | tr -d ' ')
fi
echo "channel_ids: [${channel_ids}]"
echo "channel_ids=${channel_ids}" >> $GITHUB_OUTPUT
echo "missing_github_users: [${missing_github_users}]"
echo "missing_github_users=${missing_github_users}" >> $GITHUB_OUTPUT
echo "mappings_json=${json}" >> $GITHUB_OUTPUT

0 comments on commit 3001595

Please sign in to comment.