mirror of
https://github.com/appium/appium.git
synced 2026-05-11 21:39:45 -05:00
ci: Simplify slack table format (#21686)
This commit is contained in:
@@ -18,32 +18,6 @@ function extractDatePart(isoString) {
|
||||
return isoString.split('T')[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Pad text to a specific width, truncating if necessary
|
||||
* Handles Slack link syntax by preserving link structure
|
||||
* @param {string} str - Text to pad
|
||||
* @param {number} width - Target width
|
||||
* @returns {string} Padded string
|
||||
*/
|
||||
function pad(str, width) {
|
||||
const s = String(str || '');
|
||||
if (s.length <= width) {
|
||||
return s.padEnd(width);
|
||||
}
|
||||
// For Slack links, try to preserve the link structure
|
||||
const linkMatch = s.match(/^<(.+?)\|(.+?)>$/);
|
||||
if (linkMatch) {
|
||||
const [, url, text] = linkMatch;
|
||||
const maxTextLen = width - url.length - 5; // Account for < > | characters
|
||||
if (maxTextLen > 0) {
|
||||
const truncatedText = text.length > maxTextLen ? text.substring(0, maxTextLen - 1) + '…' : text;
|
||||
return `<${url}|${truncatedText}>`.padEnd(width);
|
||||
}
|
||||
}
|
||||
// Fallback: truncate the whole string
|
||||
return s.substring(0, width - 3) + '…';
|
||||
}
|
||||
|
||||
// Internal exclusion list - usernames to exclude from reports
|
||||
const INTERNAL_EXCLUSION_LIST = [
|
||||
'dependabot',
|
||||
@@ -222,34 +196,8 @@ function formatSlackMessage(pullRequests, from, to, generatedAt) {
|
||||
},
|
||||
});
|
||||
} else {
|
||||
// Column widths
|
||||
const colWidths = {
|
||||
num: 4,
|
||||
created: 9,
|
||||
merged: 9,
|
||||
author: 20,
|
||||
repo: 25,
|
||||
title: 68,
|
||||
complexity: 4,
|
||||
};
|
||||
|
||||
// Create table header
|
||||
const tableHeader = [
|
||||
pad('#', colWidths.num),
|
||||
pad('Created', colWidths.created),
|
||||
pad('Merged', colWidths.merged),
|
||||
pad('Author', colWidths.author),
|
||||
pad('Repository', colWidths.repo),
|
||||
pad('Title', colWidths.title),
|
||||
pad('Complexity', colWidths.complexity),
|
||||
].join(' | ');
|
||||
|
||||
const separator = ['─'.repeat(colWidths.num), '─'.repeat(colWidths.created), '─'.repeat(colWidths.merged),
|
||||
'─'.repeat(colWidths.author), '─'.repeat(colWidths.repo), '─'.repeat(colWidths.title),
|
||||
'─'.repeat(colWidths.complexity)].join(' | ');
|
||||
|
||||
// Create table rows
|
||||
const tableRowLines = pullRequests.map((pr, index) => {
|
||||
// Create simple markdown rows with links
|
||||
const rowLines = pullRequests.map((pr, index) => {
|
||||
// Format created date (when PR was created)
|
||||
const createdDate = new Date(pr.created_at).toLocaleDateString('en-US', {
|
||||
month: 'short',
|
||||
@@ -264,43 +212,39 @@ function formatSlackMessage(pullRequests, from, to, generatedAt) {
|
||||
|
||||
const authorName = pr.author?.login || 'Unknown';
|
||||
const authorUrl = pr.author?.html_url || `https://github.com/${authorName}`;
|
||||
|
||||
// Use pull request title directly
|
||||
let prTitle = pr.commit.message; // This is the PR title from our data mapping
|
||||
if (prTitle.length > MAX_TITLE_LENGTH) {
|
||||
prTitle = prTitle.substring(0, MAX_TITLE_LENGTH - 1) + '…';
|
||||
}
|
||||
|
||||
return [
|
||||
pad(index + 1, colWidths.num),
|
||||
pad(createdDate, colWidths.created),
|
||||
pad(mergedDate, colWidths.merged),
|
||||
pad(`<${authorUrl}|${authorName}>`, colWidths.author),
|
||||
pad(pr.repository, colWidths.repo),
|
||||
pad(`<${pr.html_url}|${prTitle}>`, colWidths.title),
|
||||
pad('', colWidths.complexity),
|
||||
].join(' | ');
|
||||
// Construct repository URL
|
||||
const repoUrl = `https://github.com/${GITHUB_ORG}/${pr.repository}`;
|
||||
|
||||
// Format as simple markdown row with Slack-formatted links
|
||||
return `${index + 1} • <${pr.html_url}|${prTitle}> • <${authorUrl}|${authorName}> • <${repoUrl}|${pr.repository}> • Created: ${createdDate} • Merged: ${mergedDate}`;
|
||||
});
|
||||
|
||||
// Slack section text has a 3000 character limit. Keep under ~2900 to be safe.
|
||||
const MAX_SECTION_CHARS = 2900;
|
||||
let currentLines = [];
|
||||
const headerWithSeparator = `${tableHeader}\n${separator}`;
|
||||
let currentLen = headerWithSeparator.length + 6; // include code fence/newlines overhead
|
||||
let currentLen = 0;
|
||||
|
||||
const flushSection = () => {
|
||||
if (currentLines.length === 0) {
|
||||
return;
|
||||
}
|
||||
const content = `\`\`\`\n${headerWithSeparator}\n${currentLines.join('\n')}\n\`\`\``;
|
||||
const content = currentLines.join('\n');
|
||||
blocks.push({
|
||||
type: 'section',
|
||||
text: {type: 'mrkdwn', text: content},
|
||||
});
|
||||
currentLines = [];
|
||||
currentLen = headerWithSeparator.length + 6;
|
||||
currentLen = 0;
|
||||
};
|
||||
|
||||
for (const line of tableRowLines) {
|
||||
for (const line of rowLines) {
|
||||
const addLen = line.length + 1; // plus newline
|
||||
if (currentLen + addLen > MAX_SECTION_CHARS) {
|
||||
flushSection();
|
||||
|
||||
Reference in New Issue
Block a user