* Format GitHub pull request data as Slack message blocks * @param {GitHubPullRequest[]} pullRequests - Array of pull request objects * @param {string} from - Start date in ISO 8601 format * @param {string} to - End date in ISO 8601 format * @param {string} generatedAt - Generation timestamp in
(pullRequests, from, to, generatedAt)
| 189 | * @returns {object} Slack message payload with blocks |
| 190 | */ |
| 191 | function formatSlackMessage(pullRequests, from, to, generatedAt) { |
| 192 | const monthName = new Date(from).toLocaleString('en-US', {month: 'long', year: 'numeric'}); |
| 193 | const fromDate = extractDatePart(from); |
| 194 | const toDate = extractDatePart(to); |
| 195 | |
| 196 | const blocks = [ |
| 197 | { |
| 198 | type: 'header', |
| 199 | text: { |
| 200 | type: 'plain_text', |
| 201 | text: `🚀 GitHub Contribution Report for ${monthName}`, |
| 202 | emoji: true, |
| 203 | }, |
| 204 | }, |
| 205 | { |
| 206 | type: 'section', |
| 207 | text: { |
| 208 | type: 'mrkdwn', |
| 209 | text: `*Organization:* @${GITHUB_ORG}\n*Period:* ${fromDate} to ${toDate}\n*Total Merged Pull Requests:* ${pullRequests.length}`, |
| 210 | }, |
| 211 | }, |
| 212 | { |
| 213 | type: 'divider', |
| 214 | }, |
| 215 | ]; |
| 216 | |
| 217 | if (pullRequests.length === 0) { |
| 218 | blocks.push({ |
| 219 | type: 'section', |
| 220 | text: { |
| 221 | type: 'mrkdwn', |
| 222 | text: '❌ No merged pull requests found for this period.', |
| 223 | }, |
| 224 | }); |
| 225 | } else { |
| 226 | // Create simple markdown rows with links |
| 227 | const rowLines = pullRequests.map((pr, index) => { |
| 228 | // Format created date (when PR was created) |
| 229 | const createdDate = new Date(pr.created_at).toLocaleDateString('en-US', { |
| 230 | month: 'short', |
| 231 | day: 'numeric', |
| 232 | }); |
| 233 | |
| 234 | // Format merged date (when PR was merged) |
| 235 | const mergedDate = new Date(pr.merged_at).toLocaleDateString('en-US', { |
| 236 | month: 'short', |
| 237 | day: 'numeric', |
| 238 | }); |
| 239 | |
| 240 | const authorName = pr.author?.login || 'Unknown'; |
| 241 | const authorUrl = pr.author?.html_url || `https://github.com/${authorName}`; |
| 242 | |
| 243 | // Use pull request title directly |
| 244 | let prTitle = pr.commit.message; // This is the PR title from our data mapping |
| 245 | if (prTitle.length > MAX_TITLE_LENGTH) { |
| 246 | prTitle = prTitle.substring(0, MAX_TITLE_LENGTH - 1) + '…'; |
| 247 | } |
| 248 |
no test coverage detected