APP-211: Streamline Bulk Approval Implementation #1
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: Streamline-Approve | |
on: | |
pull_request: | |
branches: ["master", "main"] | |
jobs: | |
run-streamlined-approval: | |
if: github.event.pull_request.user.login == 'hs-pr-bot' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get Labels | |
id: getLabels | |
run: | | |
labels="$(gh api repos/$OWNER/$REPO_NAME/pulls/$PULL_REQUEST_NUMBER --jq '.labels.[].name')" | |
echo "allLabels=$(echo $labels)" >> $GITHUB_OUTPUT | |
shell: bash | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
OWNER: ${{ github.repository_owner }} | |
REPO_NAME: ${{ github.event.repository.name }} | |
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }} | |
- name: Checkout | |
if: "${{ contains(steps.getLabels.outputs.allLabels, 'auto-approve') }}" | |
uses: actions/[email protected] | |
- name: Was PR Opened at least Two Weeks Ago | |
id: twoWeeksAgo | |
if: "${{ contains(steps.getLabels.outputs.allLabels, 'auto-approve') }}" | |
run: | | |
created_at="$(gh api repos/$OWNER/$REPO_NAME/pulls/$PULL_REQUEST_NUMBER --jq '.created_at')" | |
created_at="$(date --date="${created_at}" +%Y-%m-%d)" | |
echo "CREATED AT: $(echo $created_at)" | |
date="$(date '+%Y-%m-%d')" | |
two_weeks_ago="$(date --date="${date} -14 day" +%Y-%m-%d)" | |
echo "Two Weeks Ago: $(echo $two_weeks_ago)" | |
if [[ "$two_weeks_ago" > "$created_at" ]]; | |
then | |
echo "was_two_weeks_ago="TRUE"" >> $GITHUB_OUTPUT | |
else | |
echo "was_two_weeks_ago="FALSE"" >> $GITHUB_OUTPUT | |
fi | |
shell: bash | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
OWNER: ${{ github.repository_owner }} | |
REPO_NAME: ${{ github.event.repository.name }} | |
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }} | |
- name: Auto Approve | |
if: "${{ contains(steps.getLabels.outputs.allLabels, 'auto-approve') && steps.twoWeeksAgo.outputs.was_two_weeks_ago == 'TRUE'}}" | |
uses: hmarr/auto-approve-action@v4 | |
with: | |
github-token: ${{secrets.HS_APPROVER_BOT_TOKEN}} |