Skip to content

Add GitHub Actions workflow to auto-label issues added to Project v2 boards#2

Closed
Copilot wants to merge 2 commits intomainfrom
copilot/add-github-actions-workflow
Closed

Add GitHub Actions workflow to auto-label issues added to Project v2 boards#2
Copilot wants to merge 2 commits intomainfrom
copilot/add-github-actions-workflow

Conversation

Copy link
Contributor

Copilot AI commented Nov 10, 2025

Description

Adds automation to apply labels when issues are added to specific Project v2 boards. Currently configured for "Bug Tracker: YoLauncher Website" → "app: YoLauncher Website" label.

Type of Change

  • Other (please describe): GitHub Actions workflow automation

Changes Made

  • Added .github/workflows/add-label-when-added-to-project-v2.yml workflow
  • Triggers on project_v2_item created events
  • Queries GitHub API to match project by name
  • Applies configured label only to issues (skips PRs)
  • Uses environment variables for easy extension to additional project/label pairs

Motivation

Automates labeling for project-specific issue triage. Reduces manual labeling overhead when issues are added to project boards. Architecture supports future migration to hardcoded project nodeIds.

Related Issues

Fixes #
Related to #

Checklist

  • I have read the CONTRIBUTING.md guidelines
  • My changes follow the style and conventions of this project
  • I have checked for typos and grammatical errors
  • I have tested my changes (if applicable)
  • My changes don't break existing functionality

Additional Context

Workflow uses Node.js 20 with @octokit/core. Extensible design: add more project/label pairs by duplicating the job with different environment variables. Security scan passed (CodeQL: 0 alerts).

Original prompt

Add a GitHub Actions workflow to automatically add the label app: YoLauncher Website when an issue is added to the Project v2 board named 'Bug Tracker: YoLauncher Website'. The workflow should:

  • Trigger on the project_v2_item event (type: created).
  • Use the GitHub API to identify the target project by name (for now; plan for nodeId hardcoding).
  • Only act on issues added to this specific project.
  • Add the label to the associated issue.
  • Permit easy extension for more projectName/label pairs.

Add the following workflow file at .github/workflows/add-label-when-added-to-project-v2.yml:

name: Add Label for Issues in Bug Tracker: YoLauncher Website

on:
  project_v2_item:
    types: [created]
  workflow_dispatch:

jobs:
  add-label:
    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 label if issue in specific Project v2
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          PROJECT_NAME: "Bug Tracker: YoLauncher Website"
          LABEL_NAME: "app: YoLauncher Website"
        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);
            const owner = "LiF-x";
            const repo = "Projects";
            const projectName = process.env.PROJECT_NAME;
            const labelToAdd = process.env.LABEL_NAME;

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

            // Fetch all org projects v2 (for now, will hardcode node ID later)
            const projectsResp = await octokit.request('GET /orgs/{org}/projects', {
              org: owner
            });
            const project = projectsResp.data.find(prj => prj.name === projectName);
            if (!project) {
              console.log('Project not found');
              return;
            }
            if (payload.project_v2_item.project_id !== project.id) {
              console.log('Project does not match');
              return;
            }

            // Add label
            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

The workflow should be functional and ready for extension when switching to project nodeId mode.

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

Add a GitHub Actions workflow to automatically add the label app: YoLauncher Website when an issue is added to the Project v2 board named 'Bug Tracker: YoLauncher Website'. The workflow should:

  • Trigger on the project_v2_item event (type: created).
  • Use the GitHub API to identify the target project by name (for now; plan for nodeId hardcoding).
  • Only act on issues added to this specific project.
  • Add the label to the associated issue.
  • Permit easy extension for more projectName/label pairs.

Add the following workflow file at .github/workflows/add-label-when-added-to-project-v2.yml:

name: Add Label for Issues in Bug Tracker: YoLauncher Website

on:
  project_v2_item:
    types: [created]
  workflow_dispatch:

jobs:
  add-label:
    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 label if issue in specific Project v2
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          PROJECT_NAME: "Bug Tracker: YoLauncher Website"
          LABEL_NAME: "app: YoLauncher Website"
        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);
            const owner = "LiF-x";
            const repo = "Projects";
            const projectName = process.env.PROJECT_NAME;
            const labelToAdd = process.env.LABEL_NAME;

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

            // Fetch all org projects v2 (for now, will hardcode node ID later)
            const projectsResp = await octokit.request('GET /orgs/{org}/projects', {
              org: owner
            });
            const project = projectsResp.data.find(prj => prj.name === projectName);
            if (!project) {
              console.log('Project not found');
              return;
            }
            if (payload.project_v2_item.project_id !== project.id) {
              console.log('Project does not match');
              return;
            }

            // Add label
            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

The workflow should be functional and ready for extension when switching to project nodeId mode.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: ChristopheRoblin <1260186+ChristopheRoblin@users.noreply.github.com>
Copilot AI changed the title [WIP] Add GitHub Actions workflow for issue labeling Add GitHub Actions workflow to auto-label issues added to Project v2 boards Nov 10, 2025
Copilot AI requested a review from Mj0ed November 10, 2025 12:32
@Mj0ed Mj0ed marked this pull request as ready for review November 10, 2025 12:32
@Mj0ed Mj0ed closed this Nov 10, 2025
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