Skip to content

Commit

Permalink
fix: Add comment identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Laura Warr authored and laurawarr committed Sep 8, 2023
1 parent 4f56d56 commit 449d559
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions __tests__/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe('run', () => {
octokit.rest.issues.listComments = jest.fn().mockReturnValue({ data: [{
id: 'exisitng-comment-id',
user: { login: 'github-actions[bot]' },
body: `${commentContent} \n Last Updated: Wed, 29 Mar 2023 18:30:39 GMT`
body: `${commentContent} \n Last Updated: Wed, 29 Mar 2023 18:30:39 GMT \n <!-- Generated by DevCycle PR Insights -->`
}] })

await action.run()
Expand Down Expand Up @@ -209,7 +209,7 @@ describe('run', () => {
octokit.rest.issues.listComments = jest.fn().mockReturnValue({ data: [{
id: 'exisitng-comment-id',
user: { login: 'github-actions[bot]' },
body: 'DevCycle Variable Changes \n Last Updated: Wed, 29 Mar 2023 18:30:39 GMT'
body: 'DevCycle Variable Changes \n Last Updated: Wed, 29 Mar 2023 18:30:39 GMT \n <!-- Generated by DevCycle PR Insights -->'
}] })

await action.run()
Expand Down
9 changes: 6 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function run() {
...authArgs
]);
const pullRequestNumber = pullRequest.number;
const changeIdentifier = 'DevCycle Variable Changes';
const commentIdentifier = '<!-- Generated by DevCycle PR Insights -->';
const noChangeIdentifier = 'No DevCycle Variables Changed';
try {
const existingComments = yield octokit.rest.issues.listComments({
Expand All @@ -87,7 +87,9 @@ function run() {
issue_number: pullRequestNumber,
});
const commentToUpdate = existingComments === null || existingComments === void 0 ? void 0 : existingComments.data.find((comment) => (comment.user.login === 'github-actions[bot]' &&
(comment.body.includes(changeIdentifier) || comment.body.includes(noChangeIdentifier))));
(comment.body.includes(commentIdentifier) ||
comment.body.includes('DevCycle Variable Changes') // old comment identifier
)));
const noChanges = output.stdout.includes(noChangeIdentifier);
if (noChanges && onlyCommentOnChange) {
if (commentToUpdate) {
Expand All @@ -99,7 +101,8 @@ function run() {
}
return;
}
const commentBody = `${output.stdout} \n\n Last Updated: ${(new Date()).toUTCString()}`;
let commentBody = `${output.stdout} \n\n Last Updated: ${(new Date()).toUTCString()}`;
commentBody += `\n${commentIdentifier}`;
if (commentToUpdate) {
yield octokit.rest.issues.updateComment({
owner,
Expand Down
10 changes: 7 additions & 3 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function run() {
)

const pullRequestNumber = pullRequest.number
const changeIdentifier = 'DevCycle Variable Changes'
const commentIdentifier = '<!-- Generated by DevCycle PR Insights -->'
const noChangeIdentifier = 'No DevCycle Variables Changed'

try {
Expand All @@ -65,7 +65,10 @@ export async function run() {

const commentToUpdate = existingComments?.data.find((comment: any) => (
comment.user.login === 'github-actions[bot]' &&
(comment.body.includes(changeIdentifier) || comment.body.includes(noChangeIdentifier))
(
comment.body.includes(commentIdentifier) ||
comment.body.includes('DevCycle Variable Changes') // old comment identifier
)
))

const noChanges = output.stdout.includes(noChangeIdentifier)
Expand All @@ -80,7 +83,8 @@ export async function run() {
return
}

const commentBody = `${output.stdout} \n\n Last Updated: ${(new Date()).toUTCString()}`
let commentBody = `${output.stdout} \n\n Last Updated: ${(new Date()).toUTCString()}`
commentBody += `\n${commentIdentifier}`
if (commentToUpdate) {
await octokit.rest.issues.updateComment({
owner,
Expand Down

0 comments on commit 449d559

Please sign in to comment.