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

Adds PR Body to Content Checked, and an Issue Key Prefix #67

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 14.14.0
8 changes: 6 additions & 2 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,12 @@ describe('isHumongousPR()', () => {
});

describe('getNoIdComment()', () => {
it('should return the comment content with the branch name', () => {
expect(getNoIdComment('test_new_feature')).toContain('test_new_feature');
it('should return the comment content with the branch name, title and body', () => {
expect(getNoIdComment('test_new_feature', 'new feature', 'this is a new feature')).toContain('test_new_feature');
expect(getNoIdComment('test_new_feature', 'new feature', 'this is a new feature')).toContain('new feature');
expect(getNoIdComment('test_new_feature', 'new feature', 'this is a new feature')).toContain(
'this is a new feature'
);
});
});

Expand Down
2 changes: 1 addition & 1 deletion lib/index.js

Large diffs are not rendered by default.

13,319 changes: 12,826 additions & 493 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ export const BOT_BRANCH_PATTERNS: RegExp[] = [/^dependabot/, /^all-contributors/
*/
export const DEFAULT_BRANCH_PATTERNS: RegExp[] = [/^master$/, /^production$/, /^gh-pages$/];

/**
* Regex to match JIRA issue keys.
*/
export const JIRA_REGEX_MATCHER = /\d+-(([A-Z0-9]{1,10})|[a-z0-9]{1,10})/g;

/**
* Default total maximum number of additions after which jira-lint will discourage the PR as it is
* considered "too huge to review".
Expand Down
9 changes: 6 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const getInputs = (): JIRALintActionInputs => {
const PR_THRESHOLD = parseInt(core.getInput('pr-threshold', { required: false }), 10);
const VALIDATE_ISSUE_STATUS: boolean = core.getInput('validate_issue_status', { required: false }) === 'true';
const ALLOWED_ISSUE_STATUSES: string = core.getInput('allowed_issue_statuses');
const ISSUE_KEY_PREFIX: string = core.getInput('issue-key-prefix', { required: true });

return {
JIRA_TOKEN,
Expand All @@ -42,6 +43,7 @@ const getInputs = (): JIRALintActionInputs => {
JIRA_BASE_URL: JIRA_BASE_URL.endsWith('/') ? JIRA_BASE_URL.replace(/\/$/, '') : JIRA_BASE_URL,
VALIDATE_ISSUE_STATUS,
ALLOWED_ISSUE_STATUSES,
ISSUE_KEY_PREFIX,
};
};

Expand All @@ -56,6 +58,7 @@ async function run(): Promise<void> {
PR_THRESHOLD,
VALIDATE_ISSUE_STATUS,
ALLOWED_ISSUE_STATUSES,
ISSUE_KEY_PREFIX,
} = getInputs();

const defaultAdditionsCount = 800;
Expand Down Expand Up @@ -114,11 +117,11 @@ async function run(): Promise<void> {
process.exit(0);
}

const issueKeys = getJIRAIssueKeys(headBranch);
const issueKeys = getJIRAIssueKeys(`${headBranch} ${title} ${prBody}`, ISSUE_KEY_PREFIX);
if (!issueKeys.length) {
const comment: IssuesCreateCommentParams = {
...commonPayload,
body: getNoIdComment(headBranch),
body: getNoIdComment(headBranch, title, prBody),
};
await addComment(client, comment);

Expand Down Expand Up @@ -189,7 +192,7 @@ async function run(): Promise<void> {
} else {
const comment: IssuesCreateCommentParams = {
...commonPayload,
body: getNoIdComment(headBranch),
body: getNoIdComment(headBranch, title, prBody),
};
await addComment(client, comment);

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export interface JIRALintActionInputs {
PR_THRESHOLD: number;
VALIDATE_ISSUE_STATUS: boolean;
ALLOWED_ISSUE_STATUSES: string;
ISSUE_KEY_PREFIX: string;
}

export interface JIRAClient {
Expand Down
17 changes: 7 additions & 10 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ import * as core from '@actions/core';
import * as github from '@actions/github';
import similarity from 'string-similarity';
import { IssuesAddLabelsParams, PullsUpdateParams, IssuesCreateCommentParams } from '@octokit/rest';
import {
MARKER_REGEX,
BOT_BRANCH_PATTERNS,
DEFAULT_BRANCH_PATTERNS,
JIRA_REGEX_MATCHER,
HIDDEN_MARKER,
} from './constants';
import { MARKER_REGEX, BOT_BRANCH_PATTERNS, DEFAULT_BRANCH_PATTERNS, HIDDEN_MARKER } from './constants';
import { JIRA, JIRADetails, JIRAClient } from './types';

export const isBlank = (input: string): boolean => input.trim().length === 0;
Expand All @@ -19,7 +13,8 @@ export const isNotBlank = (input: string): boolean => !isBlank(input);
export const reverseString = (input: string): string => input.split('').reverse().join('');

/** Extract JIRA issue keys from a string. */
export const getJIRAIssueKeys = (input: string): string[] => {
export const getJIRAIssueKeys = (input: string, issueKeyPrefix: string): string[] => {
const JIRA_REGEX_MATCHER = new RegExp(`\\d+-${reverseString(issueKeyPrefix)}`, 'gi');
const matches = reverseString(input).toUpperCase().match(JIRA_REGEX_MATCHER);
if (matches?.length) {
return matches.map(reverseString).reverse();
Expand Down Expand Up @@ -319,9 +314,11 @@ export const getHugePrComment = (
`;

/** Get the comment body for pr with no JIRA id in the branch name. */
export const getNoIdComment = (branch: string): string => {
return `<p> A JIRA Issue ID is missing from your branch name! 🦄</p>
export const getNoIdComment = (branch: string, title: string, prBody: string): string => {
return `<p> A JIRA Issue ID is missing from your branch name, PR title and PR description! 🦄</p>
<p>Your branch: ${branch}</p>
<p>Your PR title: ${title}</p>
<p>Your PR description: ${prBody}</p>
<p>If this is your first time contributing to this repository - welcome!</p>
<hr />
<p>Please refer to <a href="https://github.com/cleartax/jira-lint">jira-lint</a> to get started.
Expand Down