Last active
February 6, 2023 09:57
-
-
Save peacock0803sz/d3dec539d3fdaa3155dc03038666280d to your computer and use it in GitHub Desktop.
Create GitHub issues from a CSV file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env -S deno run --allow-env --allow-read --allow-run --allow-net --allow-write | |
// Description: Create GitHub issues from a CSV file | |
// Usage: ./csv2issue.ts <csv file> [--dry-run|-d|-dry] | |
// CSV format: title, projects(optional), labels(optional), assignee(optional) | |
import * as flags from "https://deno.land/[email protected]/flags/mod.ts"; | |
import { parse as parseCSV } from "https://deno.land/[email protected]/encoding/csv.ts"; | |
import * as path from "https://deno.land/[email protected]/path/mod.ts"; | |
import $ from "https://deno.land/x/[email protected]/mod.ts"; | |
const args = flags.parse(Deno.args, { boolean: ["dry-run", "d", "dry"] }); | |
const isDryRun = args["dry-run"] || args["d"] || args["dry"]; | |
const filename = path.join(Deno.cwd(), args._[0].toString()); | |
const fileReader = await Deno.readTextFile(filename); | |
const csvFile = parseCSV(fileReader, { | |
skipFirstRow: true, | |
columns: ["title", "projects", "labels", "assignee"], | |
}); | |
for (const line of csvFile as Record<string, string>[]) { | |
const { title, projects, labels, assignee } = line; | |
const baseCmd = ["gh", "issue", "create", "--title", title, "--body", title]; | |
const projectsOpt = projects ? ["--project", `${projects}`] : []; | |
const rawLabels = labels.split(","); | |
const labelsOpt = rawLabels.map((s: string) => ["--label", `"${s}"`]).flat(); | |
const assigneeOpt = assignee ? ["--assignee", `${assignee}`] : []; | |
const command = baseCmd.concat(projectsOpt, labelsOpt, assigneeOpt); | |
if (isDryRun) { | |
console.debug(`DEBUG: ${command.join(" ")}`); | |
} else { | |
const result = await $`${command}`.text(); | |
console.log(result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment