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

fix comment debug #23

Merged
merged 6 commits into from
Mar 20, 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
85 changes: 40 additions & 45 deletions dist/index.js
Copy link
Owner Author

@tnyo43 tnyo43 Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test comment 1


showed message that recommending comment is not needed yet 👍

******* DEBUG is ENABLED *******
option {
token: '***',
prNumber: 23,
threshold: 4,
debug: true
}
number of the obtained comments is 1
It's not necessary to send a recommending comment yet.
https://github.com/tnyo43/recommend-mobpro-action/actions/runs/8361118686/job/22888426490

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test comment 2

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test comment 3

Copy link
Owner Author

@tnyo43 tnyo43 Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test comment 4


showed a message that a recommending comment is posted 👍

******* DEBUG is ENABLED *******
option {
token: '***',
prNumber: 23,
threshold: 4,
debug: true
}
number of the obtained comments is 4
a recommending comment has been posted: h\ttps://github.com/tnyo43/recommend-mobpro-action/pull/23#issuecomment-2009785989
https://github.com/tnyo43/recommend-mobpro-action/actions/runs/8361154113/job/22888547437

Copy link
Owner Author

@tnyo43 tnyo43 Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test comment 5


showed a message that a recommending comment has been already been posted 👍

******* DEBUG is ENABLED *******
option {
token: '***',
prNumber: 23,
threshold: 4,
debug: true
}
a recommending comment has already been posted: h\ttps://github.com/tnyo43/recommend-mobpro-action/pull/23#issuecomment-2009785989
https://github.com/tnyo43/recommend-mobpro-action/actions/runs/8361203552/job/22888707267

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

22 changes: 12 additions & 10 deletions src/comments/getCommentContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ import {
type User,
} from './types';
import { getLoginNames } from './getLoginNames';
import { isAlreadyCommented } from './isAlreadyCommented';

type Args = {
threshold: number;
};
import { getExistingCommentUrl } from './getExistingCommentUrl';

export async function getCommentContent(
octokit: Octokit,
octokitContext: OctokitContext,
args: Args,
threshold: number,
): Promise<CommentContent | null> {
const { owner, repo, prNumber } = octokitContext;

Expand All @@ -26,7 +22,12 @@ export async function getCommentContent(
})
).data;

if (isAlreadyCommented(comments)) {
const existingCommentUrl = getExistingCommentUrl(comments);
if (existingCommentUrl) {
console.log(
'a recommending comment has already been posted: ',
existingCommentUrl,
);
return null;
}

Expand All @@ -39,7 +40,10 @@ export async function getCommentContent(
).data;

const numberOfComments = comments.length + reviewComments.length;
if (numberOfComments < args.threshold) {
console.log('number of the obtained comments is ', numberOfComments);

if (numberOfComments < threshold) {
console.log("It's not necessary to send a recommending comment yet.");
return null;
}

Expand All @@ -54,7 +58,5 @@ export async function getCommentContent(

return {
logins,
numberOfComments,
threshold: args.threshold,
};
}
9 changes: 9 additions & 0 deletions src/comments/getExistingCommentUrl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { type Comment } from './types';
import { ACTION_IDENTIFY_TEXT } from './constants';

export function getExistingCommentUrl(comments: Comment[]): string | undefined {
const comment = comments.find((comment) =>
comment.body?.startsWith(ACTION_IDENTIFY_TEXT),
);
return comment?.html_url;
}
8 changes: 0 additions & 8 deletions src/comments/isAlreadyCommented.ts

This file was deleted.

34 changes: 17 additions & 17 deletions src/comments/postComment.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setFailed } from '@actions/core';
import { ACTION_IDENTIFY_TEXT } from './constants';
import {
type CommentContent,
Expand All @@ -12,22 +13,11 @@ Hey ${content.logins.map((login) => '@' + login).join(', ')}!
It seems the discussion is dragging on. Perhaps instead of text communication, you could try having a conversation via face-to-face or video call, or even try mob programming?
`;
}
function debugText(content: CommentContent) {
return `
<details>
<summary>number of comments</summary>
the number of the comments is ${content.numberOfComments}
threshold: ${content.threshold}
</details>
`;
}

function getText(content: CommentContent) {
return `${ACTION_IDENTIFY_TEXT}

${MainText(content)}

${debugText(content)}
`;
}

Expand All @@ -38,10 +28,20 @@ export async function postComment(
) {
const { owner, repo, prNumber } = octokitContext;

await octokit.rest.issues.createComment({
owner,
repo,
issue_number: prNumber,
body: getText(content),
});
try {
const result = await octokit.rest.issues.createComment({
owner,
repo,
issue_number: prNumber,
body: getText(content),
});

console.log(
'a recommending comment has been posted: ',
result.data.html_url,
);
} catch (error) {
console.error(error);
setFailed('failed to post comment');
}
}
4 changes: 1 addition & 3 deletions src/comments/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ export type User = {
export type Comment = {
user: User | null;
body?: string;
html_url: string;
};

export type CommentContent = {
logins: string[];

numberOfComments: number;
threshold: number;
};
10 changes: 4 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,17 @@ export async function run(): Promise<void> {
const { token, prNumber, threshold } = getOption();

const octokit = getOctokit(token);
const owner = context.repo.owner;
const repo = context.repo.repo;
const octokitContext: OctokitContext = {
owner: context.repo.owner,
repo: context.repo.repo,
prNumber,
};

core.debug(`owner: ${owner}, repo: ${repo}, PR #${prNumber}`);

const commentContent = await getCommentContent(octokit, octokitContext, {
const commentContent = await getCommentContent(
octokit,
octokitContext,
threshold,
});
);

if (commentContent) {
await postComment(octokit, octokitContext, commentContent);
Expand Down
Loading