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 support for skip gif flag #6

Merged
merged 8 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ When a PR passes the above check, `jira-lint` will also add the issue details to
| `jira-base-url` | The subdomain of JIRA cloud that you use to access it. Ex: "https://your-domain.atlassian.net". | true | null |
| `skip-branches` | A regex to ignore running `jira-lint` on certain branches, like production etc. | false | ' ' |
| `skip-comments` | A `Boolean` if set to `true` then `jira-lint` will skip adding lint comments for PR title. | false | false |
| `skip-gifs` | A `Boolean` if set to `true` then `jira-lint` will skip adding any gifs. | false | false |
| `pr-threshold` | An `Integer` based on which `jira-lint` will add a comment discouraging huge PRs. | false | 800 |

Since tokens are private, we suggest adding them as [GitHub secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets).
Expand Down
17 changes: 15 additions & 2 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
shouldSkipBranchLint,
shouldUpdatePRDescription,
getJIRAClient,
getPRTitleComment,
} from '../src/utils';
import { HIDDEN_MARKER } from '../src/constants';
import { JIRADetails } from '../src/types';
Expand Down Expand Up @@ -205,11 +206,23 @@ describe('getNoIdComment()', () => {

describe('getHugePrComment()', () => {
it('should return the comment content with additions and threshold', () => {
expect(getHugePrComment(1000, 800)).toContain(1000);
expect(getHugePrComment(1000, 800)).toContain(800);
expect(getHugePrComment(1000, 800, 'true')).toContain(1000);
expect(getHugePrComment(1000, 800, 'true')).toContain(800);
});
it('should return no gifs if they are skipped', () => {
expect(getHugePrComment(1000, 800, 'true')).not.toContain('giphy.com');
expect(getHugePrComment(1000, 800, 'false')).toContain('giphy.com');
});
});

describe('getPRTitleComment()', () => {
it('should return no gifs if they are skipped', () => {
expect(getPRTitleComment('title', 'title', 'true')).not.toContain('giphy.com');
expect(getPRTitleComment('title', 'title', 'false')).toContain('giphy.com');
});
});


describe('getLabelsForDisplay()', () => {
it('generates label markup without spaces', () => {
expect(getLabelsForDisplay([
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ inputs:
description: 'A boolean if set to true, will skip adding lint comments for PR title.'
required: false
default: false
skip-gifs:
description: 'A boolean if set to true, will skip adding gifs to comments.'
required: false
default: false
pr-threshold:
description: 'An `Integer` based on which jira-lint add a comment discouraging huge PRs. Is disabled by `skip-comments`'
required: false
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,23 @@ const getInputs = () => {
const GITHUB_TOKEN: string = core.getInput('github-token', { required: true });
const BRANCH_IGNORE_PATTERN: string = core.getInput('skip-branches', { required: false }) || '';
const SKIP_COMMENTS: string = core.getInput('skip-comments', { required: false }) || 'false';
const SKIP_GIFS: string = core.getInput('skip-gifs', { required: false }) || 'false';
const PR_THRESHOLD: string = core.getInput('pr-threshold', { required: false }) || '';

return {
JIRA_TOKEN,
GITHUB_TOKEN,
BRANCH_IGNORE_PATTERN,
SKIP_COMMENTS,
SKIP_GIFS,
PR_THRESHOLD,
JIRA_BASE_URL: JIRA_BASE_URL.endsWith('/') ? JIRA_BASE_URL.replace(/\/$/, '') : JIRA_BASE_URL,
};
};

async function run() {
try {
const { JIRA_TOKEN, JIRA_BASE_URL, GITHUB_TOKEN, BRANCH_IGNORE_PATTERN, SKIP_COMMENTS, PR_THRESHOLD } = getInputs();
const { JIRA_TOKEN, JIRA_BASE_URL, GITHUB_TOKEN, BRANCH_IGNORE_PATTERN, SKIP_COMMENTS, SKIP_GIFS, PR_THRESHOLD } = getInputs();

const defaultAdditionsCount = 800;
const prThreshold: number = PR_THRESHOLD ? Number(PR_THRESHOLD) : defaultAdditionsCount;
Expand Down Expand Up @@ -137,7 +139,7 @@ async function run() {
if (shouldAddComments(SKIP_COMMENTS)) {
const prTitleComment: IssuesCreateCommentParams = {
...commonPayload,
body: getPRTitleComment(details.summary, title),
body: getPRTitleComment(details.summary, title, SKIP_GIFS),
};
console.log('Adding comment for the PR title');
addComment(client, prTitleComment);
Expand All @@ -146,7 +148,7 @@ async function run() {
if (isHumongousPR(additions, prThreshold)) {
const hugePrComment: IssuesCreateCommentParams = {
...commonPayload,
body: getHugePrComment(additions, prThreshold),
body: getHugePrComment(additions, prThreshold, SKIP_GIFS),
};
console.log('Adding comment for huge PR');
addComment(client, hugePrComment);
Expand Down
23 changes: 17 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const addComment = async (client: github.GitHub, comment: IssuesCreateCom
/**
* Get a comment based on story title and PR title similarity
*/
export const getPRTitleComment = (storyTitle: string, prTitle: string): string => {
export const getPRTitleComment = (storyTitle: string, prTitle: string, skipGifs: string): string => {
const matchRange: number = similarity.compareTwoStrings(storyTitle, prTitle);
if (matchRange < 0.2) {
return `<p>
Expand Down Expand Up @@ -209,9 +209,14 @@ export const getPRTitleComment = (storyTitle: string, prTitle: string): string =
</p>
`;
}
return `<p>I'm a bot and I 👍 this PR title. 🤖</p>

<img src="https://media.giphy.com/media/XreQmk7ETCak0/giphy.gif" width="400" />`;
let s = `<p>I'm a bot and I 👍 this PR title. 🤖</p>`;
rheaditi marked this conversation as resolved.
Show resolved Hide resolved
if (skipGifs !== 'true') {
s += `

<img src="https://media.giphy.com/media/XreQmk7ETCak0/giphy.gif" width="400" />`;
}
return s
rheaditi marked this conversation as resolved.
Show resolved Hide resolved
};

/**
Expand Down Expand Up @@ -322,9 +327,13 @@ export const isHumongousPR = (additions: number, threshold: number): boolean =>
* @param {number} addtions
* @return {string}
*/
export const getHugePrComment = (additions: number, threshold: number): string =>
`<p>This PR is too huge for one to review :broken_heart: </p>
<img src="https://media.giphy.com/media/26tPskka6guetcHle/giphy.gif" width="400" />
export const getHugePrComment = (additions: number, threshold: number, skipGifs: string): string => {
let s = `<p>This PR is too huge for one to review :broken_heart: </p>`
if (skipGifs !== 'true') {
s += `
<img src="https://media.giphy.com/media/26tPskka6guetcHle/giphy.gif" width="400" />`
}
s += `
rheaditi marked this conversation as resolved.
Show resolved Hide resolved
<table>
<tr>
<th>Additions</th>
Expand All @@ -342,6 +351,8 @@ export const getHugePrComment = (additions: number, threshold: number): string =
Check out this <a href="https://www.atlassian.com/blog/git/written-unwritten-guide-pull-requests">guide</a> to learn more about PR best-practices.
</p>
`;
return s
rheaditi marked this conversation as resolved.
Show resolved Hide resolved
};

/**
* Get the comment body for pr with no JIRA id in the branch name
Expand Down