Repository navigation
Solution: LP-0000 — workflow test #1
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: Add solutions to project | ||
|
Check warning on line 1 in .github/workflows/add-to-project.yaml
|
||
| # `pull_request_target` is used because solutions are submitted from forks, | ||
| # and `pull_request` runs from forks get no secrets (so no ADD_TO_PROJECT_PAT). | ||
| # It runs the workflow from the default branch and never checks out or | ||
| # executes the fork's tree: the only PR input used is the title, in the `if:` | ||
| # expression below. This workflow only adds the PR to the board and sets two | ||
| # fields; it never edits, closes, or merges the PR. | ||
| on: | ||
| pull_request_target: | ||
| types: | ||
| - opened | ||
| # validate-submission tells contributors with a wrong title to rename | ||
| # the PR, so a rename into `Solution:` must be picked up too. | ||
| - edited | ||
| permissions: | ||
| contents: read | ||
| jobs: | ||
| add-to-project: | ||
| name: Add solution PR to project | ||
| # Solution PRs are titled `Solution: LP-xxxx — <name>`. Anchor on the | ||
| # prefix only: other PRs mention LP numbers without being submissions. | ||
| # On `edited`, only fire when the title changes into the prefix, so body | ||
| # edits don't re-run and reset Status. | ||
| if: >- | ||
| startsWith(github.event.pull_request.title, 'Solution:') && | ||
| (github.event.action == 'opened' || | ||
| (github.event.changes.title.from != null && | ||
| !startsWith(github.event.changes.title.from, 'Solution:'))) | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - id: add-to-project | ||
| uses: actions/add-to-project@v1.0.2 | ||
| with: | ||
| # Organization project URL | ||
| # Format: https://github.com/orgs/<org>/projects/<number> | ||
| project-url: https://github.com/orgs/logos-co/projects/18 | ||
| # A GitHub PAT or app token with `project` scope is required | ||
| # Create a fine-grained PAT with "Projects" read/write access | ||
| # or use a GitHub App with "Organization projects" permissions | ||
| github-token: ${{ secrets.ADD_TO_PROJECT_PAT }} | ||
| - name: Set Category and Status fields | ||
| if: steps.add-to-project.outputs.itemId != '' | ||
| uses: actions/github-script@v7 | ||
| env: | ||
| ITEM_ID: ${{ steps.add-to-project.outputs.itemId }} | ||
| with: | ||
| github-token: ${{ secrets.ADD_TO_PROJECT_PAT }} | ||
| script: | | ||
| const projectId = "PVT_kwDOBmg7884BfoPW"; | ||
| const categoryFieldId = "PVTSSF_lADOBmg7884BfoPWzhZ5zSM"; | ||
| const categoryOptionId = "0ea4a665"; // LPrize | ||
| const statusFieldId = "PVTSSF_lADOBmg7884BfoPWzhZ5zQ0"; | ||
| // Status option: "Proposals & Submissions to review" | ||
| const statusOptionId = "f8d53801"; | ||
| const setField = (fieldId, optionId) => github.graphql(` | ||
| mutation( | ||
| $projectId: ID! | ||
| $itemId: ID! | ||
| $fieldId: ID! | ||
| $optionId: String! | ||
| ) { | ||
| updateProjectV2ItemFieldValue(input: { | ||
| projectId: $projectId | ||
| itemId: $itemId | ||
| fieldId: $fieldId | ||
| value: { singleSelectOptionId: $optionId } | ||
| }) { | ||
| projectV2Item { id } | ||
| } | ||
| } | ||
| `, { | ||
| projectId, | ||
| itemId: process.env.ITEM_ID, | ||
| fieldId, | ||
| optionId, | ||
| }); | ||
| await setField(categoryFieldId, categoryOptionId); | ||
| await setField(statusFieldId, statusOptionId); | ||