diff --git a/dist/index.js b/dist/index.js index 7a3a573..1bab836 100644 --- a/dist/index.js +++ b/dist/index.js @@ -9401,18 +9401,15 @@ function run(context) { console.error('Can\'t find the bot comment where the voting is taking place'); return; } - const deadlineMatch = (_a = voteComment.body) === null || _a === void 0 ? void 0 : _a.match(//); - if (deadlineMatch) { - const deadline = new Date(deadlineMatch[1]); - if (deadline > new Date()) { - yield octokit_1.default.issues.createComment({ - owner, - repo, - issue_number: number, - body: `The vote is still open until ${deadline.toUTCString()}.`, - }); - return; - } + const deadline = (0, voteSync_1.resolveDeadline)((_a = voteComment.body) !== null && _a !== void 0 ? _a : '', voteComment.created_at); + if (deadline > new Date()) { + yield octokit_1.default.issues.createComment({ + owner, + repo, + issue_number: number, + body: `The vote is still open until ${deadline.toUTCString()}.`, + }); + return; } yield (0, voteSync_1.syncIssueVoteLog)(owner, repo, number); const reactions = yield octokit_1.default.reactions.listForIssueComment({ @@ -9558,10 +9555,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.syncIssueVoteLog = exports.buildUpdatedComment = exports.diffVotes = exports.parseStateMarker = void 0; +exports.syncIssueVoteLog = exports.buildUpdatedComment = exports.diffVotes = exports.parseStateMarker = exports.resolveDeadline = void 0; const config_1 = __nccwpck_require__(6373); const octokit_1 = __importDefault(__nccwpck_require__(6161)); const STATE_MARKER_RE = //; +const DEADLINE_MARKER_RE = //; +function resolveDeadline(body, commentCreatedAt) { + const match = body.match(DEADLINE_MARKER_RE); + if (match) + return new Date(match[1]); + const deadline = new Date(commentCreatedAt); + deadline.setDate(deadline.getDate() + config_1.VOTE_PERIOD_DAYS); + return deadline; +} +exports.resolveDeadline = resolveDeadline; function parseStateMarker(body) { const match = body.match(STATE_MARKER_RE); if (!match || !match[1]) @@ -9646,8 +9653,7 @@ function syncIssueVoteLog(owner, repo, issueNumber, members) { })); const body = (_a = voteComment.body) !== null && _a !== void 0 ? _a : ''; const state = parseStateMarker(body); - const deadlineMatch = body.match(//); - const deadline = deadlineMatch ? new Date(deadlineMatch[1]) : null; + const deadline = resolveDeadline(body, voteComment.created_at); const now = new Date(); const newLines = diffVotes(state, liveReactions, deadline, now); if (newLines.length === 0) diff --git a/src/commands/voteEnd.ts b/src/commands/voteEnd.ts index 0d161d0..b87b45f 100644 --- a/src/commands/voteEnd.ts +++ b/src/commands/voteEnd.ts @@ -5,7 +5,7 @@ import { BOT_USERNAME, MAINTAINERS_TEAM } from '../config'; import { reactToComment, commentToIssue, addLabels, removeLabel, hasLabel, } from '../bot'; -import { syncIssueVoteLog } from './voteSync'; +import { syncIssueVoteLog, resolveDeadline } from './voteSync'; import { LabelName } from '../labels'; import octokit from '../octokit'; @@ -116,19 +116,15 @@ export default async function run(context: Context) { return; } - const deadlineMatch = voteComment.body?.match(//); - if (deadlineMatch) { - const deadline = new Date(deadlineMatch[1]!); - if (deadline > new Date()) { - await octokit.issues.createComment({ - owner, - repo, - issue_number: number, - body: `The vote is still open until ${deadline.toUTCString()}.`, - }); - - return; - } + const deadline = resolveDeadline(voteComment.body ?? '', voteComment.created_at); + if (deadline > new Date()) { + await octokit.issues.createComment({ + owner, + repo, + issue_number: number, + body: `The vote is still open until ${deadline.toUTCString()}.`, + }); + return; } await syncIssueVoteLog(owner, repo, number); diff --git a/src/commands/voteSync.test.ts b/src/commands/voteSync.test.ts index cb1e50b..0c18de8 100644 --- a/src/commands/voteSync.test.ts +++ b/src/commands/voteSync.test.ts @@ -1,4 +1,17 @@ -import { parseStateMarker, diffVotes, buildUpdatedComment } from './voteSync'; +import { + parseStateMarker, diffVotes, buildUpdatedComment, resolveDeadline, +} from './voteSync'; + +test('resolveDeadline reads the marker when present', () => { + const body = 'body\n\n'; + expect(resolveDeadline(body, '2026-06-11T07:00:00Z')) + .toEqual(new Date('2026-06-25T07:00:00.000Z')); +}); + +test('resolveDeadline falls back to comment date plus the vote period', () => { + expect(resolveDeadline('no marker here', '2026-06-11T07:00:00Z')) + .toEqual(new Date('2026-06-25T07:00:00Z')); +}); test('parseStateMarker returns empty object when marker is absent', () => { expect(parseStateMarker('\nsome body')).toEqual({}); diff --git a/src/commands/voteSync.ts b/src/commands/voteSync.ts index 12efbc5..50e98e7 100644 --- a/src/commands/voteSync.ts +++ b/src/commands/voteSync.ts @@ -1,5 +1,5 @@ import { GetResponseDataTypeFromEndpointMethod } from '@octokit/types'; -import { BOT_USERNAME } from '../config'; +import { BOT_USERNAME, VOTE_PERIOD_DAYS } from '../config'; import octokit from '../octokit'; type Comment = GetResponseDataTypeFromEndpointMethod< @@ -15,6 +15,16 @@ export interface LiveReaction { } const STATE_MARKER_RE = //; +const DEADLINE_MARKER_RE = //; + +export function resolveDeadline(body: string, commentCreatedAt: string): Date { + const match = body.match(DEADLINE_MARKER_RE); + if (match) return new Date(match[1]!); + + const deadline = new Date(commentCreatedAt); + deadline.setDate(deadline.getDate() + VOTE_PERIOD_DAYS); + return deadline; +} export function parseStateMarker(body: string): VoteState { const match = body.match(STATE_MARKER_RE); @@ -128,8 +138,7 @@ export async function syncIssueVoteLog( const body = voteComment.body ?? ''; const state = parseStateMarker(body); - const deadlineMatch = body.match(//); - const deadline = deadlineMatch ? new Date(deadlineMatch[1]!) : null; + const deadline = resolveDeadline(body, voteComment.created_at); const now = new Date(); const newLines = diffVotes(state, liveReactions, deadline, now);