|
| 1 | +name: Append API Node PR template |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + types: [opened, reopened, synchronize, edited, ready_for_review] |
| 6 | + paths: |
| 7 | + - 'comfy_api_nodes/**' # only run if these files changed |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + pull-requests: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + inject: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Ensure template exists and append to PR body |
| 18 | + uses: actions/github-script@v7 |
| 19 | + with: |
| 20 | + script: | |
| 21 | + const { owner, repo } = context.repo; |
| 22 | + const number = context.payload.pull_request.number; |
| 23 | + const templatePath = '.github/PULL_REQUEST_TEMPLATE/api-node.md'; |
| 24 | + const marker = '<!-- API_NODE_PR_CHECKLIST: do not remove -->'; |
| 25 | +
|
| 26 | + const { data: pr } = await github.rest.pulls.get({ owner, repo, pull_number: number }); |
| 27 | +
|
| 28 | + let templateText; |
| 29 | + try { |
| 30 | + const res = await github.rest.repos.getContent({ |
| 31 | + owner, |
| 32 | + repo, |
| 33 | + path: templatePath, |
| 34 | + ref: pr.base.ref |
| 35 | + }); |
| 36 | + const buf = Buffer.from(res.data.content, res.data.encoding || 'base64'); |
| 37 | + templateText = buf.toString('utf8'); |
| 38 | + } catch (e) { |
| 39 | + core.setFailed(`Required PR template not found at "${templatePath}" on ${pr.base.ref}. Please add it to the repo.`); |
| 40 | + return; |
| 41 | + } |
| 42 | +
|
| 43 | + // Enforce the presence of the marker inside the template (for idempotence) |
| 44 | + if (!templateText.includes(marker)) { |
| 45 | + core.setFailed(`Template at "${templatePath}" does not contain the required marker:\n${marker}\nAdd it so we can detect duplicates safely.`); |
| 46 | + return; |
| 47 | + } |
| 48 | +
|
| 49 | + // If the PR already contains the marker, do not append again. |
| 50 | + const body = pr.body || ''; |
| 51 | + if (body.includes(marker)) { |
| 52 | + core.info('Template already present in PR body; nothing to inject.'); |
| 53 | + return; |
| 54 | + } |
| 55 | +
|
| 56 | + const newBody = (body ? body + '\n\n' : '') + templateText + '\n'; |
| 57 | + await github.rest.pulls.update({ owner, repo, pull_number: number, body: newBody }); |
| 58 | + core.notice('API Node template appended to PR description.'); |
0 commit comments