feat(bulk-import): repository list includes only "Left Overs" #310
Workflow file for this run
This file contains hidden or 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: Comment on PRs that add a workspace | |
| on: | |
| pull_request: | |
| types: [opened, reopened, synchronize] | |
| branches: [main] | |
| permissions: | |
| contents: read | |
| issues: write | |
| pull-requests: write | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number }} | |
| cancel-in-progress: true | |
| jobs: | |
| comment-new-workspace: | |
| name: Notify new workspace directory | |
| if: github.repository == 'redhat-developer/rhdh-plugins' && github.event.pull_request.user.login != 'rhdh-bot' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Harden Runner | |
| uses: step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e # v2.14.2 | |
| with: | |
| egress-policy: audit | |
| - name: Checkout PR head | |
| uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| fetch-depth: 0 | |
| - name: Fetch base commit | |
| run: git fetch --no-tags origin ${{ github.event.pull_request.base.sha }} | |
| - name: Detect new top-level directories under workspaces/ | |
| id: detect | |
| env: | |
| BASE_SHA: ${{ github.event.pull_request.base.sha }} | |
| HEAD_SHA: ${{ github.event.pull_request.head.sha }} | |
| run: | | |
| set -euo pipefail | |
| if git cat-file -e "${BASE_SHA}:workspaces" 2>/dev/null; then | |
| git ls-tree "${BASE_SHA}:workspaces" | awk '$2=="tree" {print $4}' | sort -u > /tmp/base_ws.txt | |
| else | |
| : > /tmp/base_ws.txt | |
| fi | |
| if git cat-file -e "${HEAD_SHA}:workspaces" 2>/dev/null; then | |
| git ls-tree "${HEAD_SHA}:workspaces" | awk '$2=="tree" {print $4}' | sort -u > /tmp/head_ws.txt | |
| else | |
| : > /tmp/head_ws.txt | |
| fi | |
| comm -13 /tmp/base_ws.txt /tmp/head_ws.txt > /tmp/new_ws.txt || true | |
| if [ ! -s /tmp/new_ws.txt ]; then | |
| echo "has_new=false" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "has_new=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Post PR comment | |
| if: steps.detect.outputs.has_new == 'true' | |
| uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7 | |
| with: | |
| script: | | |
| const marker = '<!-- rhdh-new-workspace-pr-comment -->'; | |
| const issue_number = context.payload.pull_request.number; | |
| const comments = await github.paginate(github.rest.issues.listComments, { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number, | |
| per_page: 100, | |
| }); | |
| if (comments.some((c) => c.body?.includes(marker))) { | |
| return; | |
| } | |
| const contributing = `https://github.com/${context.repo.owner}/${context.repo.repo}/blob/main/CONTRIBUTING.md#submitting-a-pull-request-for-a-new-workspace`; | |
| const body = [ | |
| marker, | |
| '', | |
| 'This pull request adds a new top-level directory under `workspaces/`. Please follow **[Submitting a Pull Request for a New Workspace](' + contributing + ')** in `CONTRIBUTING.md`.', | |
| ].join('\n'); | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number, | |
| body, | |
| }); |