TBD54566975 / web5-spec

Web5 Spec
https://tbd54566975.github.io/web5-spec/
Apache License 2.0
7 stars 5 forks source link

Script to add repetitive issues to multiple repos #51

Open leordev opened 10 months ago

leordev commented 10 months ago

Also adds the label for cicd in the main script

frankhinek commented 9 months ago

@leordev Per the discussion here: https://github.com/TBD54566975/sdk-development/issues/19#issuecomment-1805066695

...we might need two scripts since the web5-* and tbdex-* repos have different label sets.

leordev commented 9 months ago

I was hoping the user would change the script parameters here:

https://github.com/TBD54566975/sdk-development/blob/9ca13e1e668ab027d1b4b9a23fdf5c7712866786/scripts/github/github-create-issues.js#L12-L25

And then execute the scripts... So it would set the proper repos/labels depending on their use case.

If I add that as instructions above these parameters would suffice?

mistermoe commented 9 months ago

@leordev somewhat related, i wrote this script last week to create issues quickly. lmk what you think:

// github-create-issues.js

import 'dotenv/config';

import prompts from 'prompts';
import { Octokit } from '@octokit/core';

const octokit = new Octokit({
  auth: process.env['GH_TOKEN']
});

const owner = process.env['GH_OWNER'];
const repo = process.env['GH_REPO'];

const getIssueDetails = async () => {
  const questions = [
    {
      type: 'text',
      name: 'title',
      message: 'Issue title?',
      validate: title => title.length < 5 ? `Title must be at least 5 characters long.` : true
    },
    {
      type: 'text',
      name: 'description',
      message: 'Issue description?',
      initial: '',
      format: val => {
        if (val) {
          return val;
        } else {
          return undefined;
        }
      }
    },
    {
      type: 'list',
      name: 'assignees',
      message: 'Assignees? (separate with commas)',
      initial: process.env['ISSUE_ASSIGNEES'] || '',
      separator: ','
    },
    {
      type: 'list',
      name: 'labels',
      message: 'Labels? (separate with commas)',
      separator: ',',
      format: val => {
        if (val.length === 1 && val[0] === '') {
          return undefined
        } else {
          return val
        }
      }
    },
    {
      type: 'confirm',
      name: 'continue',
      message: 'Would you like to enter another issue?',
      initial: true
    }
  ];

  return await prompts(questions);
};

// Function to collect all issues
const collectIssues = async () => {
  let issues = [];
  let addMore = true;

  while (addMore) {
    console.log('\nPlease enter the issue details:');
    const issueDetails = await getIssueDetails();
    if (issueDetails.title) { // Making sure the title is entered
      issues.push({
        title: issueDetails.title,
        description: issueDetails.description,
        assignees: issueDetails.assignees,
        labels: issueDetails.labels
      });
    }

    if (!issueDetails.continue) {
      addMore = false;
    }
  }

  return issues;
};

// Main function to start the process
const main = async () => {
  const issues = await collectIssues();
  for (let issue of issues) {
    await octokit.request('POST /repos/{owner}/{repo}/issues', {
      owner: owner,
      repo: repo,
      title: issue.title,
      body: issue.description,
      assignees: issue.assignees,
      labels: issue.labels,
      headers: { 'X-GitHub-Api-Version': '2022-11-28' }
    })
  }
};

main();

works like so:

https://github.com/TBD54566975/sdk-development/assets/4887440/25a5807b-476e-4025-ab40-f48378c8b299

the script continues prompting until you say you're done creating issues and then creates all of them at once

assignees, labels, and repo can be pre-configured as environment variables or a .env file. Was thinking we could adjust the script to look for a predetermined file name in the directory e.g. issues.json. if that's present it skips the prompts, otherwise it jumps into prompting.

leordev commented 9 months ago

Was thinking we could adjust the script to look for a predetermined file name in the directory e.g. issues.json. if that's present it skips the prompts, otherwise it jumps into prompting.

Love this. I was a bit nervous of just entering a bunch of issues and in the end batching it up, because maybe I'd have lose something I entered that didn't go through, but since we have this json input, I'm fine with it because I will probably use my code editor to enter all of them there.

Another thing that should be included is the project (can be copied from my script functions)

decentralgabe commented 3 weeks ago

@leordev can this be closed?