diff --git a/lib/readJiraIssues.js b/lib/readJiraIssues.js index 86b9dd6..8395769 100644 --- a/lib/readJiraIssues.js +++ b/lib/readJiraIssues.js @@ -1,8 +1,12 @@ import axios from "axios"; -import { writeFileSync } from "fs"; +import { writeFileSync } from "node:fs"; +import { parseArgs } from "node:util"; + +const args = parseArgs({ allowPositionals: true }); +const start = args.positionals[0] || 0; const issues = await jiraIssues( - "project = ODATA AND status in (Open, Resolved, New, Applied) ORDER BY key ASC", + "project = ODATA AND status in (Closed) ORDER BY key DESC", ); writeFileSync("./jiraIssues.json", JSON.stringify(issues, null, 2)); @@ -12,8 +16,8 @@ async function jiraIssues(jql) { "https://issues.oasis-open.org/rest/api/2/search", { jql: jql, - // fields: ["summary"], - maxResults: 500, + maxResults: 100, + startAt: start, }, ); @@ -21,7 +25,7 @@ async function jiraIssues(jql) { if (res.data.total > res.data.maxResults) console.log( - `WARN: only ${res.data.maxResults} of ${res.data.total} issues retrieved`, + `WARN: only ${res.data.maxResults} of ${res.data.total} issues retrieved, starting at ${res.data.startAt}`, ); return res.data.issues; diff --git a/lib/transformJiraIssues.js b/lib/transformJiraIssues.js index 82b68d4..e0d1ddc 100644 --- a/lib/transformJiraIssues.js +++ b/lib/transformJiraIssues.js @@ -21,8 +21,6 @@ const gitHubIssues = []; const resolution = {}; for (const j of jiraIssues) { - if (j.fields.resolution) resolution[j.fields.resolution.name] = true; - const g = { title: j.fields.summary, body: reformat(j.fields.description), @@ -38,10 +36,40 @@ for (const j of jiraIssues) { g.labels.push(version.name); } - if (!["New", "Open"].includes(j.fields.status.name)) + if (["Resolved", "Applied"].includes(j.fields.status.name)) g.labels.push(j.fields.status.name); - if (j.fields.assignee) { + if (j.fields.status.name === "Deferred") { + g.state = "closed"; + g.state_reason = "not_planned"; + g.labels.push("wontDo"); + } else if (j.fields.status.name === "Closed") { + g.state = "closed"; + + switch (j.fields.resolution?.name) { + case "Done": + case "Fixed": + g.state_reason = "completed"; + break; + case "No Action": + case "Won't Do": + case "Won't Fix": + g.state_reason = "not_planned"; + g.labels.push("wontDo"); + break; + case "Duplicate": + g.state_reason = "not_planned"; + g.labels.push("duplicate"); + break; + default: + if (j.fields.resolution) resolution[j.fields.resolution.name] = true; + } + } + + if ( + j.fields.assignee && + !["Deferred", "Closed"].includes(j.fields.status.name) + ) { const email = j.fields.assignee.emailAddress; g.assignees.push(ASSIGNEE[email] || email); if (!ASSIGNEE[email]) { @@ -53,9 +81,6 @@ for (const j of jiraIssues) { g.body += `\n\n### Proposal\n\n${reformat(j.fields.customfield_10001)}`; } - //TODO: - // - labels for CLOSED and DEFERRED issues, also for resolution other than "Fixed" - g.body += `\n\nImported from [${j.key}](https://issues.oasis-open.org/browse/${j.key})`; gitHubIssues.push(g); @@ -63,7 +88,8 @@ for (const j of jiraIssues) { writeFileSync("./gitHubIssues.json", JSON.stringify(gitHubIssues, null, 2)); -console.log(resolution); +if (Object.keys(resolution).length > 0) + console.log("Resolution names", resolution); function reformat(jiraText) { if (jiraText == null) return ""; diff --git a/lib/writeGithubIssues.js b/lib/writeGithubIssues.js index 788be05..3af688f 100644 --- a/lib/writeGithubIssues.js +++ b/lib/writeGithubIssues.js @@ -22,6 +22,7 @@ for (const issue of gitHubIssues) { const done = await createGithubIssue(REPO, issue); if (done) newIssues++; + else break; } console.log(newIssues, "new issues written to", REPO); @@ -34,9 +35,17 @@ async function readGithubIssues(repo) { } async function createGithubIssue(repo, issue) { - // see https://docs.github.com/en/rest/issues/issues#create-an-issue try { - await octokit.request(`POST /repos/${repo}/issues`, issue); + // see https://docs.github.com/en/rest/issues/issues#create-an-issue + const response = await octokit.request(`POST /repos/${repo}/issues`, issue); + + if (issue.state === "closed") { + // see https://docs.github.com/en/rest/issues/issues#update-an-issue + await octokit.request( + `PATCH /repos/${repo}/issues/${response.data.number}`, + { state: issue.state, state_reason: issue.state_reason }, + ); + } return true; } catch (error) { if (error instanceof RequestError) {