Skip to content

Commit af0716c

Browse files
committed
fix: just use relative time
1 parent 4003f29 commit af0716c

File tree

3 files changed

+63
-124
lines changed

3 files changed

+63
-124
lines changed

dist/index.js

Lines changed: 29 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -89302,7 +89302,6 @@ var __importStar = (this && this.__importStar) || (function () {
8930289302
Object.defineProperty(exports, "__esModule", ({ value: true }));
8930389303
exports.postInitialComment = postInitialComment;
8930489304
exports.updateComment = updateComment;
89305-
exports.postComment = postComment;
8930689305
const github = __importStar(__nccwpck_require__(75380));
8930789306
const logger_1 = __nccwpck_require__(61661);
8930889307
const COMMENT_MARKER = '<!-- auto-pr-screenshots -->';
@@ -89320,14 +89319,35 @@ async function postInitialComment(options) {
8932089319
logger_1.commentLogger.info(`💬 Posting initial comment to PR #${prNumber}`);
8932189320
try {
8932289321
const commentBody = generateInitialCommentBody(commitSha);
89323-
const { data: comment } = await octokit.rest.issues.createComment({
89322+
// Find existing comment
89323+
const { data: comments } = await octokit.rest.issues.listComments({
8932489324
owner,
8932589325
repo,
8932689326
issue_number: prNumber,
89327-
body: commentBody,
8932889327
});
89329-
logger_1.commentLogger.success('✅ Created initial comment');
89330-
return comment.id;
89328+
const existingComment = comments.find((comment) => comment.body?.includes(COMMENT_MARKER) && comment.user?.type === 'Bot');
89329+
if (existingComment) {
89330+
// Update existing comment
89331+
await octokit.rest.issues.updateComment({
89332+
owner,
89333+
repo,
89334+
comment_id: existingComment.id,
89335+
body: commentBody,
89336+
});
89337+
logger_1.commentLogger.success('✅ Updated existing comment with initial status');
89338+
return existingComment.id;
89339+
}
89340+
else {
89341+
// Create new comment
89342+
const { data: comment } = await octokit.rest.issues.createComment({
89343+
owner,
89344+
repo,
89345+
issue_number: prNumber,
89346+
body: commentBody,
89347+
});
89348+
logger_1.commentLogger.success('✅ Created initial comment');
89349+
return comment.id;
89350+
}
8933189351
}
8933289352
catch (error) {
8933389353
logger_1.commentLogger.error('Failed to post initial comment:', error instanceof Error ? error.message : String(error));
@@ -89356,57 +89376,12 @@ async function updateComment(commentId, screenshots, errors, options, status) {
8935689376
logger_1.commentLogger.error('Failed to update comment:', error instanceof Error ? error.message : String(error));
8935789377
}
8935889378
}
89359-
async function postComment(screenshots, errors, options) {
89360-
const { token, context, config } = options;
89361-
// Only post comments on pull requests
89362-
if (context.eventName !== 'pull_request' || !context.payload.pull_request) {
89363-
logger_1.commentLogger.warn('Not in a pull request context, skipping comment');
89364-
return;
89365-
}
89366-
const octokit = github.getOctokit(token);
89367-
const { owner, repo } = context.repo;
89368-
const prNumber = context.payload.pull_request.number;
89369-
logger_1.commentLogger.info(`💬 Posting comment to PR #${prNumber}`);
89370-
try {
89371-
// Find existing comment
89372-
const { data: comments } = await octokit.rest.issues.listComments({
89373-
owner,
89374-
repo,
89375-
issue_number: prNumber,
89376-
});
89377-
const existingComment = comments.find((comment) => comment.body?.includes(COMMENT_MARKER) && comment.user?.type === 'Bot');
89378-
// Generate comment body
89379-
const commentBody = generateCommentBody(screenshots, errors, context, config, options.showAttribution);
89380-
if (existingComment) {
89381-
// Update existing comment
89382-
await octokit.rest.issues.updateComment({
89383-
owner,
89384-
repo,
89385-
comment_id: existingComment.id,
89386-
body: commentBody,
89387-
});
89388-
logger_1.commentLogger.success('✅ Updated existing comment');
89389-
}
89390-
else {
89391-
// Create new comment
89392-
await octokit.rest.issues.createComment({
89393-
owner,
89394-
repo,
89395-
issue_number: prNumber,
89396-
body: commentBody,
89397-
});
89398-
logger_1.commentLogger.success('✅ Created new comment');
89399-
}
89400-
}
89401-
catch (error) {
89402-
logger_1.commentLogger.error('Failed to post comment:', error instanceof Error ? error.message : String(error));
89403-
throw error;
89404-
}
89405-
}
8940689379
function generateInitialCommentBody(commitSha) {
89380+
const timestamp = new Date().toISOString();
8940789381
let body = `${COMMENT_MARKER}\n`;
8940889382
body += '## 📸 Auto PR Screenshots\n\n';
8940989383
body += `🔄 Screenshot capture has started for commit \`${commitSha}\`\n\n`;
89384+
body += `*Started <relative-time datetime="${timestamp}">${timestamp}</relative-time>*\n\n`;
8941089385
body += '*Capturing screenshots...*';
8941189386
return body;
8941289387
}
@@ -89417,10 +89392,11 @@ function generateCommentBody(screenshots, errors, context, config, showAttributi
8941789392
body += '## 📸 Auto PR Screenshots\n\n';
8941889393
if (status === 'in_progress') {
8941989394
body += `🔄 Screenshot capture in progress for commit \`${commitSha}\`\n\n`;
89395+
body += `*Last updated <relative-time datetime="${timestamp}">${timestamp}</relative-time>*\n\n`;
8942089396
}
8942189397
else {
8942289398
body += `✅ Screenshot capture complete for commit \`${commitSha}\`\n\n`;
89423-
body += `*Completed: ${timestamp}*\n\n`;
89399+
body += `*Completed <relative-time datetime="${timestamp}">${timestamp}</relative-time>*\n\n`;
8942489400
}
8942589401
if (screenshots.length === 0 && errors.length === 0) {
8942689402
body += `⚠️ No screenshots were captured. Check the [action logs](${runUrl}) for details.\n`;

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/comment-poster.ts

Lines changed: 33 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,39 @@ export async function postInitialComment(options: CommentOptions): Promise<numbe
2929

3030
try {
3131
const commentBody = generateInitialCommentBody(commitSha);
32-
const { data: comment } = await octokit.rest.issues.createComment({
32+
33+
// Find existing comment
34+
const { data: comments } = await octokit.rest.issues.listComments({
3335
owner,
3436
repo,
3537
issue_number: prNumber,
36-
body: commentBody,
3738
});
38-
logger.success('✅ Created initial comment');
39-
return comment.id;
39+
40+
const existingComment = comments.find(
41+
(comment) => comment.body?.includes(COMMENT_MARKER) && comment.user?.type === 'Bot',
42+
);
43+
44+
if (existingComment) {
45+
// Update existing comment
46+
await octokit.rest.issues.updateComment({
47+
owner,
48+
repo,
49+
comment_id: existingComment.id,
50+
body: commentBody,
51+
});
52+
logger.success('✅ Updated existing comment with initial status');
53+
return existingComment.id;
54+
} else {
55+
// Create new comment
56+
const { data: comment } = await octokit.rest.issues.createComment({
57+
owner,
58+
repo,
59+
issue_number: prNumber,
60+
body: commentBody,
61+
});
62+
logger.success('✅ Created initial comment');
63+
return comment.id;
64+
}
4065
} catch (error) {
4166
logger.error(
4267
'Failed to post initial comment:',
@@ -89,75 +114,12 @@ export async function updateComment(
89114
}
90115
}
91116

92-
export async function postComment(
93-
screenshots: UploadedScreenshot[],
94-
errors: ScreenshotError[],
95-
options: CommentOptions,
96-
): Promise<void> {
97-
const { token, context, config } = options;
98-
99-
// Only post comments on pull requests
100-
if (context.eventName !== 'pull_request' || !context.payload.pull_request) {
101-
logger.warn('Not in a pull request context, skipping comment');
102-
return;
103-
}
104-
105-
const octokit = github.getOctokit(token);
106-
const { owner, repo } = context.repo;
107-
const prNumber = context.payload.pull_request.number;
108-
109-
logger.info(`💬 Posting comment to PR #${prNumber}`);
110-
111-
try {
112-
// Find existing comment
113-
const { data: comments } = await octokit.rest.issues.listComments({
114-
owner,
115-
repo,
116-
issue_number: prNumber,
117-
});
118-
119-
const existingComment = comments.find(
120-
(comment) => comment.body?.includes(COMMENT_MARKER) && comment.user?.type === 'Bot',
121-
);
122-
123-
// Generate comment body
124-
const commentBody = generateCommentBody(
125-
screenshots,
126-
errors,
127-
context,
128-
config,
129-
options.showAttribution,
130-
);
131-
132-
if (existingComment) {
133-
// Update existing comment
134-
await octokit.rest.issues.updateComment({
135-
owner,
136-
repo,
137-
comment_id: existingComment.id,
138-
body: commentBody,
139-
});
140-
logger.success('✅ Updated existing comment');
141-
} else {
142-
// Create new comment
143-
await octokit.rest.issues.createComment({
144-
owner,
145-
repo,
146-
issue_number: prNumber,
147-
body: commentBody,
148-
});
149-
logger.success('✅ Created new comment');
150-
}
151-
} catch (error) {
152-
logger.error('Failed to post comment:', error instanceof Error ? error.message : String(error));
153-
throw error;
154-
}
155-
}
156-
157117
function generateInitialCommentBody(commitSha: string): string {
118+
const timestamp = new Date().toISOString();
158119
let body = `${COMMENT_MARKER}\n`;
159120
body += '## 📸 Auto PR Screenshots\n\n';
160121
body += `🔄 Screenshot capture has started for commit \`${commitSha}\`\n\n`;
122+
body += `*Started <relative-time datetime="${timestamp}">${timestamp}</relative-time>*\n\n`;
161123
body += '*Capturing screenshots...*';
162124
return body;
163125
}
@@ -179,9 +141,10 @@ function generateCommentBody(
179141

180142
if (status === 'in_progress') {
181143
body += `🔄 Screenshot capture in progress for commit \`${commitSha}\`\n\n`;
144+
body += `*Last updated <relative-time datetime="${timestamp}">${timestamp}</relative-time>*\n\n`;
182145
} else {
183146
body += `✅ Screenshot capture complete for commit \`${commitSha}\`\n\n`;
184-
body += `*Completed: ${timestamp}*\n\n`;
147+
body += `*Completed <relative-time datetime="${timestamp}">${timestamp}</relative-time>*\n\n`;
185148
}
186149

187150
if (screenshots.length === 0 && errors.length === 0) {

0 commit comments

Comments
 (0)