-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: main
Are you sure you want to change the base?
Conversation
c16477b
to
9ca13e1
Compare
@leordev Per the discussion here: #19 (comment) ...we might need two scripts since the |
I was hoping the user would change the script parameters here: 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? |
@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.movthe 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 |
There was a problem hiding this 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
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) |
@leordev can this be closed? |
Also adds the label for cicd in the main script