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 tips for tracker approval 💡 #91

Merged
merged 1 commit into from
May 22, 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
3 changes: 3 additions & 0 deletions dist/bugzilla.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions dist/controller.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/jira.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/util.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { PullRequestMetadata } from './schema/input';
import {
getFailedMessage,
getSuccessMessage,
getTipMessage,
raise,
removeLabel,
setLabels,
Expand Down Expand Up @@ -57,6 +58,7 @@ async function action(

let message: string[] = [];
let err: string[] = [];
let tip: string[] = [];
let labels: { add: string[]; remove: string[] } = { add: [], remove: [] };

const labelsFromPR = z
Expand Down Expand Up @@ -160,6 +162,7 @@ async function action(
err.push(
`🔴 Tracker ${trackerController.adapter.getMarkdownUrl()} has not been approved`
);
tip.push(`🔵 ${trackerController.adapter.tips.approval}`);
} else {
if (labelsFromPR.includes(config.labels.unapproved)) {
removeLabel(octokit, prMetadata.number, config.labels.unapproved);
Expand All @@ -185,7 +188,13 @@ async function action(
setLabels(octokit, prMetadata.number, labels.add);

if (err.length > 0) {
raise(getFailedMessage(err) + '\n\n' + getSuccessMessage(message));
raise(
getFailedMessage(err) +
'\n\n' +
getSuccessMessage(message) +
'\n\n' +
getTipMessage(tip)
);
}

return getSuccessMessage(message);
Expand Down
4 changes: 4 additions & 0 deletions src/bugzilla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export class Bugzilla implements Adapter<BugzillaAPI> {
readonly api: BugzillaAPI;
issueDetails: IssueDetails | undefined;

readonly tips = {
approval: 'Bugzilla is approved if it has `release` flag set to `+`',
};

constructor(
readonly instance: string,
private apiToken: string
Expand Down
5 changes: 5 additions & 0 deletions src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Jira } from './jira';
export interface Adapter<T> {
readonly api: T;
readonly instance: string;
readonly tips: Tips;

getIssueDetails(id: string): Promise<IssueDetails>;

Expand All @@ -20,6 +21,10 @@ export interface Adapter<T> {
addLink(urlType: string, bugId: string): Promise<string>;
}

export type Tips = {
approval: string;
};

export type IssueDetails = {
id: string;
product: string;
Expand Down
4 changes: 4 additions & 0 deletions src/jira.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export class Jira implements Adapter<Version2Client> {
readonly api: Version2Client;
issueDetails: IssueDetails | undefined;

readonly tips = {
approval: 'Jira is approved if it has set Fix Version/s',
};

constructor(
readonly instance: string,
apiToken: string
Expand Down
8 changes: 8 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ export function getSuccessMessage(message: string[]): string {
return '#### Success' + '\n\n' + message.join('\n');
}

export function getTipMessage(tip: string[]): string {
if (tip.length === 0) {
return '';
}

return '> [!TIP]' + '\n>\n' + tip.map(t => `> ${t}`).join('\n');
}

export async function setLabels(
octokit: Octokit,
issueNumber: number,
Expand Down
4 changes: 2 additions & 2 deletions test/bugzilla.test.ts → test/unit/bugzilla.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { beforeEach, describe, expect, test } from 'vitest';

import { Bugzilla } from '../src/bugzilla';
import { Bugzilla } from '../../src/bugzilla';
import BugzillaAPI from 'bugzilla';
import { IssueDetails, Flag } from '../src/controller';
import { IssueDetails, Flag } from '../../src/controller';

interface TestContext {
bugzilla: Bugzilla;
Expand Down
6 changes: 3 additions & 3 deletions test/controller.test.ts → test/unit/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
Controller,
SupportedAdapters,
SupportedControllers,
} from '../src/controller';
} from '../../src/controller';

import { Bugzilla } from '../src/bugzilla';
import { Jira } from '../src/jira';
import { Bugzilla } from '../../src/bugzilla';
import { Jira } from '../../src/jira';

describe('test class Controller', () => {
test('type SupportedControllers', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/jira.test.ts → test/unit/jira.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { beforeEach, describe, expect, test } from 'vitest';

import { Jira } from '../src/jira';
import { Jira } from '../../src/jira';
import { Version2Client } from 'jira.js';
import { IssueDetails, Flag } from '../src/controller';
import { IssueDetails, Flag } from '../../src/controller';

interface TestContext {
jira: Jira;
Expand Down
24 changes: 23 additions & 1 deletion test/util.test.ts → test/unit/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { describe, expect, test } from 'vitest';

import { getFailedMessage, getSuccessMessage, raise } from '../src/util';
import {
getFailedMessage,
getSuccessMessage,
getTipMessage,
raise,
} from '../../src/util';

describe('test basic utility functions', () => {
test.todo('updateStatusCheck()', async () => {});
Expand Down Expand Up @@ -39,6 +44,23 @@ describe('test basic utility functions', () => {
`);
});

test('getTipMessage()', () => {
let tip: string[] = [];
let message = getTipMessage(tip);

expect(message).toEqual('');

tip = ['success1', 'success2'];
message = getTipMessage(tip);

expect(message).toMatchInlineSnapshot(`
"> [!TIP]
>
> success1
> success2"
`);
});

test('raise()', () =>
expect(() => raise('new error')).toThrow(new Error('new error')));

Expand Down