Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import { z } from 'zod';
import { Jira } from './jira';
import { getLegend } from './legend';
import { Logger } from './logger';
import { getDefaultValue, getOptions, raise, tokenUnavailable } from './util';
import {
getDefaultValue,
getOptions,
raise,
tokenUnavailable,
getUserFromLogin,
} from './util';

import {
colorPrioritySchema,
Expand All @@ -23,7 +29,7 @@ import {
SizeWithControls,
} from './schema/jira';

import { Issue } from 'jira.js/dist/esm/types/version2/models/issue';
import { Issue } from 'jira.js/dist/esm/types/version3/models/issue';

export function cli(): Command {
const program = new Command();
Expand Down Expand Up @@ -83,7 +89,11 @@ const runProgram = async () => {
}

const token = process.env.JIRA_API_TOKEN ?? tokenUnavailable();
const jira = new Jira('https://issues.redhat.com', token);
const jira = new Jira(
'https://redhat.atlassian.net/jira',
token,
getUserFromLogin()
);

const version = await jira.getVersion();
console.debug(`JIRA Version: ${version}`);
Expand Down
20 changes: 11 additions & 9 deletions src/jira.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import { Version2Client } from 'jira.js';
import { Issue } from 'jira.js/dist/esm/types/version2/models';
import { Version3Client } from 'jira.js';
import { Issue } from 'jira.js/dist/esm/types/version3/models/issue';

import { raise } from './util';
import { Priority, Severity, Size } from './schema/jira';

export class Jira {
readonly api: Version2Client;
readonly api: Version3Client;
readonly fields = {
storyPoints: 'customfield_12310243',
storyPoints: 'customfield_10194',
priority: 'priority',
severity: 'customfield_12316142',
severity: 'customfield_10442',
};
readonly baseJQL =
'Project in (RHEL, "RHEL Miscellaneous", Fedora) AND (type in (Story, Task) AND ("Story Points" is EMPTY OR priority is EMPTY) OR type not in (Story, Task) AND ("Story Points" is EMPTY OR priority is EMPTY OR Severity is EMPTY)) AND status != Closed';
JQL = '';

constructor(
readonly instance: string,
apiToken: string
apiToken: string,
email: string
) {
this.api = new Version2Client({
this.api = new Version3Client({
host: instance,
authentication: {
oauth2: {
accessToken: apiToken,
basic: {
email,
apiToken,
},
},
});
Expand Down
20 changes: 10 additions & 10 deletions test/unit/jira.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const mocks = vi.hoisted(() => {
});

vi.mock('jira.js', () => {
const Version2Client = vi.fn(function () {
const Version3Client = vi.fn(function () {
return {
serverInfo: {
getServerInfo: mocks.getServerInfo,
Expand All @@ -26,15 +26,15 @@ vi.mock('jira.js', () => {
};
});
return {
Version2Client,
Version3Client,
};
});

describe('Jira functions', () => {
let jira: Jira;

beforeEach(() => {
jira = new Jira('https://issues.redhat.com', 'token');
jira = new Jira('https://issues.redhat.com', 'token', 'email');

mocks.getServerInfo.mockReturnValue({
version: '8.0.0',
Expand Down Expand Up @@ -118,7 +118,7 @@ describe('Jira functions', () => {
'components',
'summary',
'assignee',
'customfield_12310243',
'customfield_10194',
'priority',
],
jql: 'issue in (RHEL-1234,RHEL-1235) ORDER BY id DESC',
Expand All @@ -130,7 +130,7 @@ describe('Jira functions', () => {
"assignee": {
"displayName": "assignee",
},
"customfield_12310243": 3,
"customfield_10194": 3,
"issuetype": {
"name": "Story",
},
Expand All @@ -149,7 +149,7 @@ describe('Jira functions', () => {
"assignee": {
"displayName": "assignee",
},
"customfield_12310243": 5,
"customfield_10194": 5,
"issuetype": {
"name": "Story",
},
Expand Down Expand Up @@ -188,7 +188,7 @@ describe('Jira functions', () => {
'components',
'summary',
'assignee',
'customfield_12310243',
'customfield_10194',
'priority',
],
jql: 'Project in (RHEL, "RHEL Miscellaneous", Fedora) AND (type in (Story, Task) AND ("Story Points" is EMPTY OR priority is EMPTY) OR type not in (Story, Task) AND ("Story Points" is EMPTY OR priority is EMPTY OR Severity is EMPTY)) AND status != Closed ORDER BY id DESC',
Expand All @@ -200,7 +200,7 @@ describe('Jira functions', () => {
"assignee": {
"displayName": "assignee",
},
"customfield_12310243": 3,
"customfield_10194": 3,
"issuetype": {
"name": "Story",
},
Expand All @@ -219,7 +219,7 @@ describe('Jira functions', () => {
"assignee": {
"displayName": "assignee",
},
"customfield_12310243": 5,
"customfield_10194": 5,
"issuetype": {
"name": "Story",
},
Expand Down Expand Up @@ -310,7 +310,7 @@ describe('Jira functions', () => {
expect(mocks.editIssue).toHaveBeenCalledWith({
issueIdOrKey: 'RHEL-1234',
fields: {
customfield_12310243: 5,
customfield_10194: 5,
priority: {
name: 'Minor',
},
Expand Down