Skip to content

[WIP] Add GitHub Actions workflow for applying labels to issues#3

Merged
Mj0ed merged 1 commit intomainfrom
copilot/add-label-for-project-items
Nov 10, 2025
Merged

[WIP] Add GitHub Actions workflow for applying labels to issues#3
Mj0ed merged 1 commit intomainfrom
copilot/add-label-for-project-items

Conversation

Copy link
Contributor

Copilot AI commented Nov 10, 2025

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.

Original prompt

Create a GitHub Actions workflow .github/workflows/add-label-for-project-items.yml that automatically applies a label to issues when they are added to a specific Project v2 board using the project's Node ID. The workflow must:

  • Trigger on the project_v2_item event with types: [created], and support workflow_dispatch for manual runs.
  • Use a mapping between Project v2 node IDs and label names.
  • Only act if the item added is an issue and the project node ID is in the mapping.
  • For now, map 'PVT_kwDOA49l9c4BHulN' → 'app: YoLauncher Website' but ensure other IDs/labels can be added.
  • Log if the project node is not in the mapping.

Add the following file:

name: Add Label Based on Project v2

on:
  project_v2_item:
    types: [created]
  workflow_dispatch:

jobs:
  label-by-project:
    runs-on: ubuntu-latest
    permissions:
      issues: write
      contents: read
      pull-requests: read
    steps:
      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '20'
      - name: Download dependencies
        run: npm install @octokit/core
      - name: Add dynamic label based on Project v2 Node ID
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          node <<'EOF'
          const { Octokit } = require("@octokit/core");
          const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });

          (async () => {
            const payload = require(process.env.GITHUB_EVENT_PATH);

            // Map Project v2 node IDs to label names
            const labelMap = {
              "PVT_kwDOA49l9c4BHulN": "app: YoLauncher Website"
              // Add more project node IDs and labels here as needed
            };

            // Only proceed if the content is an Issue
            if (payload.project_v2_item.content?.type !== "Issue") {
              console.log("Not an issue, skipping");
              return;
            }

            const nodeId =
              payload.project_v2_item.project_node_id ||
              payload.project_v2_item.project_id ||
              payload.project_v2_item.projectNodeId;
            const labelToAdd = labelMap[nodeId];

            if (!labelToAdd) {
              console.log(`No label mapping for project node ID: ${nodeId}, skipping`);
              return;
            }

            const owner = "LiF-x";
            const repo = "Projects";
            const issueNumber = payload.project_v2_item.content.number;

            await octokit.request('POST /repos/{owner}/{repo}/issues/{issue_number}/labels', {
              owner,
              repo,
              issue_number: issueNumber,
              labels: [labelToAdd]
            });
            console.log(`Label '${labelToAdd}' added to issue #${issueNumber}`);
          })().catch(e => { console.error(e); process.exit(1); });
          EOF

This pull request was created as a result of the following prompt from Copilot chat.

Create a GitHub Actions workflow .github/workflows/add-label-for-project-items.yml that automatically applies a label to issues when they are added to a specific Project v2 board using the project's Node ID. The workflow must:

  • Trigger on the project_v2_item event with types: [created], and support workflow_dispatch for manual runs.
  • Use a mapping between Project v2 node IDs and label names.
  • Only act if the item added is an issue and the project node ID is in the mapping.
  • For now, map 'PVT_kwDOA49l9c4BHulN' → 'app: YoLauncher Website' but ensure other IDs/labels can be added.
  • Log if the project node is not in the mapping.

Add the following file:

name: Add Label Based on Project v2

on:
  project_v2_item:
    types: [created]
  workflow_dispatch:

jobs:
  label-by-project:
    runs-on: ubuntu-latest
    permissions:
      issues: write
      contents: read
      pull-requests: read
    steps:
      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '20'
      - name: Download dependencies
        run: npm install @octokit/core
      - name: Add dynamic label based on Project v2 Node ID
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          node <<'EOF'
          const { Octokit } = require("@octokit/core");
          const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });

          (async () => {
            const payload = require(process.env.GITHUB_EVENT_PATH);

            // Map Project v2 node IDs to label names
            const labelMap = {
              "PVT_kwDOA49l9c4BHulN": "app: YoLauncher Website"
              // Add more project node IDs and labels here as needed
            };

            // Only proceed if the content is an Issue
            if (payload.project_v2_item.content?.type !== "Issue") {
              console.log("Not an issue, skipping");
              return;
            }

            const nodeId =
              payload.project_v2_item.project_node_id ||
              payload.project_v2_item.project_id ||
              payload.project_v2_item.projectNodeId;
            const labelToAdd = labelMap[nodeId];

            if (!labelToAdd) {
              console.log(`No label mapping for project node ID: ${nodeId}, skipping`);
              return;
            }

            const owner = "LiF-x";
            const repo = "Projects";
            const issueNumber = payload.project_v2_item.content.number;

            await octokit.request('POST /repos/{owner}/{repo}/issues/{issue_number}/labels', {
              owner,
              repo,
              issue_number: issueNumber,
              labels: [labelToAdd]
            });
            console.log(`Label '${labelToAdd}' added to issue #${issueNumber}`);
          })().catch(e => { console.error(e); process.exit(1); });
          EOF

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Mj0ed Mj0ed marked this pull request as ready for review November 10, 2025 12:34
@Mj0ed Mj0ed merged commit acc3e02 into main Nov 10, 2025
1 check failed
Copilot AI requested a review from Mj0ed November 10, 2025 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants