Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.
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
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ inputs:
default: "In Progress"

runs:
using: 'node12'
using: 'node16'
main: 'lib/index.js'
branding:
icon: 'check-square'
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js

Large diffs are not rendered by default.

14 changes: 3 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
getHugePrComment,
getJIRAClient,
getJIRAIssueKeys,
getNoIdComment,
addNoIdComment,
getPRDescription,
getPRTitleComment,
isHumongousPR,
Expand Down Expand Up @@ -116,11 +116,7 @@ async function run(): Promise<void> {

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

core.setFailed('JIRA issue id is missing in your branch.');
process.exit(1);
Expand Down Expand Up @@ -187,11 +183,7 @@ async function run(): Promise<void> {
}
}
} else {
const comment: IssuesCreateCommentParams = {
...commonPayload,
body: getNoIdComment(headBranch),
};
await addComment(client, comment);
await addNoIdComment(client, headBranch, commonPayload);

core.setFailed('Invalid JIRA key. Please create a branch with a valid JIRA issue key.');
process.exit(1);
Expand Down
39 changes: 37 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import axios from 'axios';
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 { IssuesAddLabelsParams, PullsUpdateParams, IssuesCreateCommentParams, IssuesListCommentsParams
} from '@octokit/rest';
import {
MARKER_REGEX,
BOT_BRANCH_PATTERNS,
Expand Down Expand Up @@ -287,6 +288,40 @@ export const getPRDescription = (body = '', details: JIRADetails): string => {
${body}`;
};

/**
* Helpful function to add a comment that we couldn't find the Pivotal ID
* of this comment. Will attempt to only add once.
*/
export const addNoIdComment = async (
client: github.GitHub,
branch: string,
params: IssuesListCommentsParams
) => {
const { data: comments } = await client.issues.listComments(params);

const noIdComment = getNoIdComment(branch);

// Find a previously created comment by our bot
const previousComments = comments.filter(
comment => comment.body.includes(noIdComment),
);

if (previousComments.length > 0) {
// Update existing comment
const { id } = previousComments[0];
console.log(`Comment already exists as comment #${id}`);
} else {
// Insert a new comment
console.log('Adding a new comment');
const comment: IssuesCreateCommentParams = {
...params,
body: noIdComment
};
await addComment(client, comment);
}
}


/** Check if a PR is considered "huge". */
export const isHumongousPR = (additions: number, threshold: number): boolean =>
typeof additions === 'number' && additions > threshold;
Expand Down Expand Up @@ -355,7 +390,7 @@ export const getInvalidIssueStatusComment = (
/** Threshold of additions allowed. */
allowedStatuses: string
): string =>
`<p>:broken_heart: The detected issue is not in one of the allowed statuses :broken_heart: </p>
`<p>:broken_heart: The detected issue is not in one of the allowed statuses :broken_heart: </p>
<table>
<tr>
<th>Detected Status</th>
Expand Down