Skip to content

Commit

Permalink
#28718: small fix for when github users are not the same resolved cha…
Browse files Browse the repository at this point in the history
…nnels (#29975)
  • Loading branch information
victoralfaro-dotcms authored Sep 13, 2024
1 parent 9981b91 commit 8040597
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 40 deletions.
50 changes: 32 additions & 18 deletions .github/workflows/cicd_scheduled_notify-seated-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ on:
schedule:
- cron: '0 10 * * *'
workflow_dispatch:
inputs:
current_user:
description: 'Limit execution of this workflow to the current user'
type: string
required: false
default: U0125JCDSSE
env:
PR_DAY_THRESHOLD: 3
DRAFT_PR_DAY_THRESHOLD: 5
Expand All @@ -20,6 +26,7 @@ jobs:
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
- name: Filter execution
id: filter-execution
uses: actions/github-script@v7
with:
result-encoding: string
Expand All @@ -28,11 +35,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 @@ -146,23 +155,25 @@ jobs:
with:
result-encoding: string
script: |
const member = '${{ matrix.member }}';
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 mappings = ${{ needs.slack-channel-resolver.outputs.mappings_json }};
const foundMapping = mappings.find(mapping => mapping.slack_id === member)
if (!foundMapping) {
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 @@ -183,14 +194,17 @@ jobs:

core.setOutput('message', message);
- name: Notify member
if: success()
if: success() && steps.build-message.outputs.message != ''
shell: bash
run: |
channel=${{ matrix.member }}
curl -X POST \
-H "Content-type: application/json" \
-H "Authorization: Bearer ${{ secrets.SLACK_BOT_TOKEN }}" \
-d "{ \"channel\":\"${channel}\",\"text\":\"${{ steps.build-message.outputs.message }}\"}" \
-s \
https://slack.com/api/chat.postMessage
echo "Sending notification to ${channel}"
if [[ -x '${{ inputs.current_user }}' || "${channel}" == '${{ inputs.current_user }}' ]]; then
curl -X POST \
-H "Content-type: application/json" \
-H "Authorization: Bearer ${{ secrets.SLACK_BOT_TOKEN }}" \
-d "{ \"channel\":\"${channel}\",\"text\":\"${{ steps.build-message.outputs.message }}\" }" \
-s \
https://slack.com/api/chat.postMessage
fi
36 changes: 16 additions & 20 deletions .github/workflows/issue_comp_next-release-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,38 @@ jobs:
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
- name: Validate inputs
id: validate-inputs
uses: actions/github-script@v7
with:
result-encoding: string
script: |
let issueNumber;
const issue = context.payload.issue;
if (!issue && '${{ inputs.issue_number }}'.trim() === '') {
console.log('Issue number is not provided');
process.exit(1);
core.warn('Issue number is not provided');
process.exit(0);
}
let label = context.payload.label;
if (!label) {
if (!'${{ inputs.label }}') {
console.log('Label is missing, exiting');
process.exit(2);
core.warn('Label is missing, exiting');
process.exit(0);
}
label = '${{ inputs.label }}';
} else {
label = label.name;
}
if (label !== '${{ env.QA_NOT_NEEDED_LABEL }}') {
console.log('Label is not [${{ env.QA_NOT_NEEDED_LABEL }}], exiting');
process.exit(3);
core.warn('Label is not [${{ env.QA_NOT_NEEDED_LABEL }}], exiting');
process.exit(0);
}
core.setOutput('label', label);
- name: Add Next Release label
uses: actions/github-script@v7
if: success()
if: success() && steps.validate-inputs.outputs.label != ''
with:
result-encoding: string
retries: 3
Expand All @@ -81,25 +82,25 @@ jobs:
}
if (!issue) {
console.log('Issue [${{ inputs.issue_number }}] not found');
process.exit(4);
core.warn('Issue [${{ inputs.issue_number }}] not found');
process.exit(0);
}
}
console.log(`Issue: ${JSON.stringify(issue, null, 2)}`);
const issueNumber = issue.number;
const dropAndLearnText = 'Drop Everything & Learn';
if (issue.title.includes(dropAndLearnText)) {
console.log(`Issue does have "${dropAndLearnText}" text in title, exiting`);
process.exit(5);
const dropAndLearnText = 'Drop Everything & Learn'.toLowerCase();
if (issue.title.toLowerCase().includes(dropAndLearnText)) {
core.warn(`Issue does have "${dropAndLearnText}" text in title, exiting`);
process.exit(0);
}
const typeCicdLabel = 'Type : CI/CD';
const foundLabel = issue.labels.find(label => label.name === typeCicdLabel);
if (foundLabel) {
console.log(`Issue does have "${typeCicdLabel}" label , exiting`);
process.exit(6);
core.warn(`Issue does have "${typeCicdLabel}" label , exiting`);
process.exit(0);
}
await github.rest.issues.addLabels({
Expand All @@ -111,9 +112,4 @@ jobs:
const updated = await getIssue(issueNumber);
console.log(`Labels: ${JSON.stringify(updated.labels, null, 2)}`);
- name: Finalize
if: always()
run: |
echo 'Finalizing Next release labeling'
exit 0
11 changes: 9 additions & 2 deletions .github/workflows/utility_slack-channel-resolver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ on:
outputs:
channel_ids:
value: ${{ jobs.slack-channel-resolver.outputs.channel_ids }}
mappings_json:
value: ${{ jobs.slack-channel-resolver.outputs.mappings_json }}
secrets:
CI_MACHINE_USER:
description: 'CI machine user'
Expand All @@ -45,6 +47,7 @@ jobs:
runs-on: ubuntu-20.04
outputs:
channel_ids: ${{ steps.resolve-channels.outputs.channel_ids }}
mappings_json: ${{ steps.resolve-channels.outputs.mappings_json }}
steps:
- name: Resolve Users
id: resolve-users
Expand All @@ -70,7 +73,8 @@ jobs:
githack_core_repo_url=https://${githack_host}/${{ github.repository }}
slack_mappings_file=slack-mappings.json
slack_mapping_url=${githack_core_repo_url}/${{ inputs.branch }}/.github/data/${slack_mappings_file}
json=$(curl -s ${slack_mapping_url})
json=$(curl -s ${slack_mapping_url} | jq -c .)
echo "json: ${json}"
echo "Looking for [${github_user}]"
channel_ids=
Expand Down Expand Up @@ -115,7 +119,9 @@ jobs:
fi
fi
[[ -n "${channel_id}" ]] && channel_ids="${channel_ids} ${channel_id}"
if [[ -n "${channel_id}" && "${channel_id}" != 'null' ]]; then
channel_ids="${channel_ids} ${channel_id}"
fi
done
default_channel_id=${{ inputs.default_channel_id }}
Expand All @@ -135,5 +141,6 @@ jobs:
channel_ids=$(printf '%s\n' "${deduped_channel_ids[@]}" | jq -R . | jq -s . | tr -d '\n' | tr -d ' ')
fi
echo "mappings_json=${json}" >> $GITHUB_OUTPUT
echo "channel_ids: [${channel_ids}]"
echo "channel_ids=${channel_ids}" >> $GITHUB_OUTPUT

0 comments on commit 8040597

Please sign in to comment.