msihorg / operations

Process and Task management for Make Sure It Happens Inc
1 stars 0 forks source link

Create Labels for Issues and Discussion using GitHub Actions #15

Closed msihorg closed 3 weeks ago

msihorg commented 3 weeks ago

Create Issue Labels `name: Create Issue Labels

on: workflow_dispatch: # Allows manual trigger create: # Runs when the repository is created push: paths:

jobs: create-labels:

Only run this job on repository creation or manual trigger

if: github.event_name == 'create' || github.event_name == 'workflow_dispatch' || github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
  issues: write

steps:
  - name: Checkout Repository
    uses: actions/checkout@v4

  - name: Create Labels
    uses: actions/github-script@v7
    with:
      script: |
        const labels = [
          {
            name: 'developer',
            color: '0E8A16',
            description: 'Tasks requiring development work'
          },
          {
            name: 'design',
            color: 'FF69B4',
            description: 'Tasks involving design work'
          },
          {
            name: 'marketing',
            color: 'FFA500',
            description: 'Marketing-related tasks'
          },
          {
            name: 'project manager',
            color: '1D76DB',
            description: 'Tasks for project management'
          },
          {
            name: 'operations',
            color: '5319E7',
            description: 'Operations-related tasks'
          },
          {
            name: 'legal research',
            color: 'FBCA04',
            description: 'Tasks involving legal research'
          }
        ];

        for (const label of labels) {
          try {
            // Try to create the label
            await github.rest.issues.createLabel({
              owner: context.repo.owner,
              repo: context.repo.repo,
              name: label.name,
              color: label.color,
              description: label.description
            });
            console.log(`Created label: ${label.name}`);
          } catch (error) {
            // If label already exists, update it
            if (error.status === 422) {
              await github.rest.issues.updateLabel({
                owner: context.repo.owner,
                repo: context.repo.repo,
                name: label.name,
                color: label.color,
                description: label.description
              });
              console.log(`Updated existing label: ${label.name}`);
            } else {
              console.log(`Error processing label ${label.name}: ${error}`);
            }
          }
        }`

Create Discussion Labels `name: Create Discussion Labels

on: workflow_dispatch: # Allows manual trigger create: # Runs when the repository is created push: paths:

jobs: create-discussion-labels: if: github.event_name == 'create' || github.event_name == 'workflow_dispatch' || github.event_name == 'push' runs-on: ubuntu-latest permissions: discussions: write

steps:
  - name: Checkout Repository
    uses: actions/checkout@v4

  - name: Create Discussion Labels
    uses: actions/github-script@v7
    with:
      script: |
        const labels = [
          {
            name: 'Developer',
            description: 'Topics requiring development expertise'
          },
          {
            name: 'Design',
            description: 'Design-related discussions'
          },
          {
            name: 'Marketing',
            description: 'Marketing strategy discussions'
          },
          {
            name: 'Project Manager',
            description: 'Project management topics'
          },
          {
            name: 'Operations',
            description: 'Operations-related discussions'
          },
          {
            name: 'Legal Research',
            description: 'Legal research and compliance topics'
          }
        ];

        for (const label of labels) {
          try {
            // Create the discussion category/label
            await github.rest.discussions.createCategory({
              owner: context.repo.owner,
              repo: context.repo.repo,
              name: label.name,
              description: label.description,
              format: 'discussion'  // Can be 'discussion' or 'announcement'
            });
            console.log(`Created discussion category: ${label.name}`);
          } catch (error) {
            if (error.status === 422) {
              console.log(`Category ${label.name} already exists`);
              // Note: GitHub API doesn't currently support updating existing discussion categories
            } else {
              console.log(`Error processing category ${label.name}: ${error}`);
            }
          }
        }`
msihorg commented 3 weeks ago

these were created in all repos as of 20241111