diff --git a/.github/workflows/streamline-approval-workflow.yml b/.github/workflows/streamline-approval-workflow.yml new file mode 100644 index 0000000..affd31c --- /dev/null +++ b/.github/workflows/streamline-approval-workflow.yml @@ -0,0 +1,55 @@ +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/checkout@v2.3.4 + + - 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}} \ No newline at end of file