Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script to add repetitive issues to multiple repos #51

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

leordev
Copy link
Member

@leordev leordev commented Nov 10, 2023

Also adds the label for cicd in the main script

@leordev leordev changed the title Script to add repetitive tasks to multiple repos Script to add repetitive issues to multiple repos Nov 11, 2023
@frankhinek
Copy link
Contributor

@leordev Per the discussion here: #19 (comment)

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

@leordev
Copy link
Member Author

leordev commented Nov 14, 2023

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
Copy link
Member

@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:

create-issue-script.mov

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.

Copy link
Member

@decentralgabe decentralgabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to have a readme that shows how this script is intended to be run

@leordev
Copy link
Member Author

leordev commented Nov 21, 2023

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
Copy link
Member

@leordev can this be closed?

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.

4 participants