Notify #73
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Notify | |
on: | |
schedule: | |
- cron: '17 0 * * 1' | |
# '0 0,2,10,12,14,16,18,20,22 * * 1-5' | |
workflow_dispatch: | |
jobs: | |
notify_schedule: | |
env: | |
ORG: ${{ github.repository_owner }} | |
REPO: ${{ github.event.repository.name }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Notify PRs No Status | |
uses: octokit/[email protected] | |
id: prs_no_status | |
with: | |
query: | | |
query needreview($queryString:String!) { | |
search(type: ISSUE, query: $queryString, last: 100) { | |
issueCount | |
} | |
} | |
variables: | | |
queryString: "repo:${{ env.ORG }}/${{env.REPO}}, state:open, is:pr, -label:\"on hold\", draft:false, review:none," | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Notify PRs Needing Review | |
uses: octokit/[email protected] | |
id: prs_need_review | |
with: | |
query: | | |
query needreview($queryString:String!) { | |
search(type: ISSUE, query: $queryString, last: 100) { | |
issueCount | |
} | |
} | |
variables: | | |
queryString: "repo:${{ env.ORG }}/${{env.REPO}}, state:open, is:pr, -label:\"on hold\", draft:false, review:required," | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Notify PRs With Feedback | |
uses: octokit/[email protected] | |
id: prs_with_feedback | |
with: | |
query: | | |
query withfeedback($queryString:String!) { | |
search(type: ISSUE, query: $queryString, last: 100) { | |
issueCount | |
} | |
} | |
variables: | | |
queryString: "repo:${{env.ORG}}/${{env.REPO}}, state:open, is:pr, -label:\"on hold\", draft:false, review:changes_requested," | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Notify PRs With Approval | |
uses: octokit/[email protected] | |
id: prs_with_approval | |
with: | |
query: | | |
query withapproval($queryString:String!) { | |
search(type: ISSUE, query: $queryString, last: 100) { | |
issueCount | |
} | |
} | |
variables: | | |
queryString: "repo:${{env.ORG}}/${{env.REPO}}, state:open, is:pr, -label:\"on hold\", draft:false, review:approved," | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Format Message | |
id: format_message | |
run: | | |
import os | |
values = [("newly opened", ${{ env.COUNT_OPEN}}), | |
("needing reviews", ${{ env.COUNT_NEED_REVIEW }}), | |
("awaiting replies to reviews", ${{ env.COUNT_WITH_FEEDBACK }}), | |
("approved", ${{ env.COUNT_WITH_APPROVAL }})] | |
notify_message_bits = [f"{v[0]}: {v[1]}" for v in values if v[1] > 0] | |
notify_message = ", ".join(notify_message_bits) | |
with open(os.environ["GITHUB_OUTPUT"], "a") as f: | |
print(f"MESSAGE=${{ env.REPO }} PRs {notify_message}", file=f) | |
shell: python | |
env: | |
COUNT_OPEN: 3 | |
#${{ fromJSON(steps.prs_no_status.outputs.data).search.issueCount }} | |
COUNT_NEED_REVIEW: ${{ fromJSON(steps.prs_need_review.outputs.data).search.issueCount }} | |
COUNT_WITH_FEEDBACK: ${{ fromJSON(steps.prs_with_feedback.outputs.data).search.issueCount }} | |
COUNT_WITH_APPROVAL: ${{ fromJSON(steps.prs_with_approval.outputs.data).search.issueCount }} | |
- name: Format Message (shell) | |
if : 0 | |
id: format_message_sh | |
run: | | |
echo -n MESSAGE=${{ env.REPO }} PRs >> $GITHUB_OUTPUT | |
first=true | |
if test ${{ env.COUNT_OPEN }} -gt 0; then | |
if $first; then first=false; else echo -n , >> $GITHUB_OUTPUT; fi | |
echo -n " newly opened: ${{ env.COUNT_OPEN }}" >> $GITHUB_OUTPUT | |
fi | |
if test ${{ env.COUNT_NEED_REVIEW }} -gt 0; then | |
if $first; then first=false; else echo -n , >> $GITHUB_OUTPUT; fi | |
echo -n " needing reviews: ${{ env.COUNT_NEED_REVIEW }}" >> $GITHUB_OUTPUT | |
fi | |
if test ${{ env.COUNT_WITH_FEEDBACK }} -gt 0; then | |
if $first; then first=false; else echo -n , >> $GITHUB_OUTPUT; fi | |
echo -n " awaiting replies to reviews: ${{ env.COUNT_WITH_FEEDBACK }}" >> $GITHUB_OUTPUT | |
fi | |
if test ${{ env.COUNT_WITH_APPROVAL }} -gt 0; then | |
if $first; then first=false; else echo -n , >> $GITHUB_OUTPUT; fi | |
echo -n " approved: ${{ env.COUNT_WITH_APPROVAL }}" >> $GITHUB_OUTPUT | |
fi | |
env: | |
COUNT_OPEN: ${{ fromJSON(steps.prs_no_status.outputs.data).search.issueCount }} | |
COUNT_NEED_REVIEW: ${{ fromJSON(steps.prs_need_review.outputs.data).search.issueCount }} | |
COUNT_WITH_FEEDBACK: ${{ fromJSON(steps.prs_with_feedback.outputs.data).search.issueCount }} | |
COUNT_WITH_APPROVAL: ${{ fromJSON(steps.prs_with_approval.outputs.data).search.issueCount }} | |
- name: Debug logging | |
run: | | |
echo message: ${{ env.MSG }} | |
env: | |
MSG: ${{ steps.format_message.outputs.MESSAGE }} | |
- uses: slackapi/[email protected] | |
if: 0 | |
# ${{ env.COUNT_OPEN > 0 || env.COUNT_NEED_REVIEW > 0 || env.COUNT_WITH_FEEDBACK > 0 || env.COUNT_WITH_APPROVAL > 0 }} | |
with: | |
# This data can be any valid JSON from a previous step in the GitHub Action. | |
# | |
# The short URL (we used to include | |
# ?q=is%3Apr+is%3Aopen+-label%3A%22on%20hold%22+draft%3Afalse+review%3Aapproved | |
# for example) will include all open PRs including those on | |
# hold, but it'll make the Slack message less messy looking. | |
payload: | | |
{ | |
"PR_MSG": "${{env.MSG}}", | |
"PR_LINK": "https://github.com/${{env.ORG}}/${{env.REPO}}/pulls" | |
} | |
env: | |
MSG: ${{ steps.format_message.outputs.MESSAGE }} | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACKMSG }} | |
COUNT_OPEN: ${{ fromJSON(steps.prs_no_status.outputs.data).search.issueCount }} | |
COUNT_NEED_REVIEW: ${{ fromJSON(steps.prs_need_review.outputs.data).search.issueCount }} | |
COUNT_WITH_FEEDBACK: ${{ fromJSON(steps.prs_with_feedback.outputs.data).search.issueCount }} | |
COUNT_WITH_APPROVAL: ${{ fromJSON(steps.prs_with_approval.outputs.data).search.issueCount }} |