Skip to content
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

Add tests and improve JIRA auth via API key #4

Merged
merged 4 commits into from
Aug 12, 2024
Merged
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
33 changes: 33 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Linters

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn

- name: Install
run: yarn install

- name: Build
run: yarn build

- name: Prettier
run: yarn run format-check
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ web_modules/
.env.test.local
.env.production.local
.env.local
.env.storypointer

# parcel-bundler cache (https://parceljs.org/)
.cache
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
"chalk": "^5.3.0",
"commander": "^12.1.0",
"dotenv": "^16.4.5",
"inquirer": "^10.1.8",
"jira.js": "^4.0.1",
"ora": "^8.0.1",
"zod": "^3.23.8"
},
"devDependencies": {
Expand Down
14 changes: 11 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
import chalk from 'chalk';
import { Command } from 'commander';
import select, { Separator } from '@inquirer/select';
import path from 'path';

Check warning on line 5 in src/main.ts

View check run for this annotation

Codecov / codecov/patch

src/main.ts#L5

Added line #L5 was not covered by tests
import { z } from 'zod';

import 'dotenv/config';
import dotenv from 'dotenv';

Check warning on line 8 in src/main.ts

View check run for this annotation

Codecov / codecov/patch

src/main.ts#L8

Added line #L8 was not covered by tests
import '@total-typescript/ts-reset';

import { Jira } from './jira';
import { raise } from './util';
import { raise, tokenUnavailable } from './util';

Check warning on line 12 in src/main.ts

View check run for this annotation

Codecov / codecov/patch

src/main.ts#L12

Added line #L12 was not covered by tests
import {
colorPrioritySchema,
colorSizeSchema,
Expand All @@ -21,6 +22,13 @@
SizeWithExit,
} from './schema/jira';

dotenv.config({
path: [
`${path.resolve(process.cwd(), '.env.storypointer')}`,
`${path.resolve(process.cwd(), '.env')}`,
],
});

Check warning on line 30 in src/main.ts

View check run for this annotation

Codecov / codecov/patch

src/main.ts#L25-L30

Added lines #L25 - L30 were not covered by tests

const cli = async () => {
const program = new Command();

Expand All @@ -37,7 +45,7 @@

program.parse();

const token = process.env.JIRA_API_TOKEN ?? raise('JIRA_API_TOKEN not set.');
const token = process.env.JIRA_API_TOKEN ?? tokenUnavailable();

Check warning on line 48 in src/main.ts

View check run for this annotation

Codecov / codecov/patch

src/main.ts#L48

Added line #L48 was not covered by tests
const jira = new Jira('https://issues.redhat.com', token);

const version = await jira.getVersion();
Expand Down
6 changes: 6 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export function raise(error: string): never {
throw new Error(error);
}

export function tokenUnavailable(): never {
return raise(
`JIRA_API_TOKEN not set.\nPlease set the JIRA_API_TOKEN environment variable in ~/.env.storypointer or ~/.env.`
);
}

Check warning on line 9 in src/util.ts

View check run for this annotation

Codecov / codecov/patch

src/util.ts#L6-L9

Added lines #L6 - L9 were not covered by tests
9 changes: 9 additions & 0 deletions test/unit/util.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { describe, expect, test } from 'vitest';

import { raise } from '../../src/util';

describe('Utility functions', () => {
test('raise()', () => {
expect(() => raise('error')).toThrow('error');
});
});
Loading