Skip to content

Commit

Permalink
Import jira scripts (#16)
Browse files Browse the repository at this point in the history
Co-authored-by: Heiko Theißen <[email protected]>
  • Loading branch information
ralfhandl and HeikoTheissen authored Mar 21, 2024
1 parent be912f4 commit 9a2f2bc
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 15 deletions.
14 changes: 9 additions & 5 deletions lib/readJiraIssues.js
Original file line number Diff line number Diff line change
@@ -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));
Expand All @@ -12,16 +16,16 @@ async function jiraIssues(jql) {
"https://issues.oasis-open.org/rest/api/2/search",
{
jql: jql,
// fields: ["summary"],
maxResults: 500,
maxResults: 100,
startAt: start,
},
);

if (res.status != 200) console.dir(res);

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;
Expand Down
42 changes: 34 additions & 8 deletions lib/transformJiraIssues.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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]) {
Expand All @@ -53,17 +81,15 @@ 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);
}

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 "";
Expand Down
13 changes: 11 additions & 2 deletions lib/writeGithubIssues.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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) {
Expand Down

0 comments on commit 9a2f2bc

Please sign in to comment.