Skip to content

Commit 9e10ef2

Browse files
committed
Externalize Magic Numbers and Strings in SyncService #7582
1 parent 66824ba commit 9e10ef2

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

ai/mcp/server/config.mjs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,32 @@ const aiConfig = {
6060
* The default version directory to use for archiving issues when no release is found.
6161
* @type {string}
6262
*/
63-
defaultArchiveVersion: 'unversioned'
63+
defaultArchiveVersion: 'unversioned',
64+
/**
65+
* The number of characters to pad issue numbers with for filenames (e.g., 4 -> '0042.md').
66+
* @type {number}
67+
*/
68+
issueNumberPadding: 5,
69+
/**
70+
* The maximum number of issues to fetch from the GitHub API in a single sync.
71+
* @type {number}
72+
*/
73+
maxIssues: 10000,
74+
/**
75+
* The maximum number of releases to fetch from the GitHub API.
76+
* @type {number}
77+
*/
78+
maxReleases: 1000,
79+
/**
80+
* The maximum buffer size for the `gh` CLI command output.
81+
* @type {number}
82+
*/
83+
maxGhOutputBuffer: 10 * 1024 * 1024, // 10 MB
84+
/**
85+
* The markdown delimiter used to separate the issue body from the comments section.
86+
* @type {string}
87+
*/
88+
commentSectionDelimiter: '## Comments'
6489
}
6590
},
6691
/**

ai/mcp/server/github-workflow/services/SyncService.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class SyncService extends Base {
180180
*/
181181
async #fetchAndCacheReleases() {
182182
logger.info('Fetching and caching releases...');
183-
const allReleases = await this.#ghCommand('release list --json tagName,publishedAt --limit 1000');
183+
const allReleases = await this.#ghCommand(`release list --json tagName,publishedAt --limit ${issueSyncConfig.maxReleases}`);
184184

185185
this.releases = allReleases
186186
.filter(release => new Date(release.publishedAt) >= new Date(issueSyncConfig.syncStartDate))
@@ -204,7 +204,7 @@ class SyncService extends Base {
204204
async #ghCommand(cmd, json = true) {
205205
try {
206206
// Using a larger maxBuffer in case of large outputs (e.g., many issues)
207-
const { stdout } = await execAsync(`gh ${cmd}`, { encoding: 'utf-8', maxBuffer: 1024 * 1024 * 10 });
207+
const { stdout } = await execAsync(`gh ${cmd}`, { encoding: 'utf-8', maxBuffer: issueSyncConfig.maxGhOutputBuffer });
208208
return json ? JSON.parse(stdout) : stdout;
209209
} catch (error) {
210210
logger.error(`Error executing: gh ${cmd}`);
@@ -280,7 +280,7 @@ class SyncService extends Base {
280280
* @private
281281
*/
282282
#getIssuePath(issue) {
283-
const number = String(issue.number).padStart(4, '0');
283+
const number = String(issue.number).padStart(issueSyncConfig.issueNumberPadding, '0');
284284
const labels = issue.labels.map(l => l.name.toLowerCase());
285285

286286
const isDropped = issueSyncConfig.droppedLabels.some(label => labels.includes(label));
@@ -343,7 +343,7 @@ class SyncService extends Base {
343343
*/
344344
async #pullFromGitHub(metadata) {
345345
logger.info('📥 Fetching issues from GitHub...');
346-
let allIssues = await this.#ghCommand('issue list --limit 10000 --state all --json number,title,state,labels,assignees,milestone,createdAt,updatedAt,closedAt,url,author,body');
346+
let allIssues = await this.#ghCommand(`issue list --limit ${issueSyncConfig.maxIssues} --state all --json number,title,state,labels,assignees,milestone,createdAt,updatedAt,closedAt,url,author,body`);
347347
logger.info(`Found ${allIssues.length} total issues`);
348348

349349
const startDate = new Date(issueSyncConfig.syncStartDate);
@@ -461,7 +461,7 @@ class SyncService extends Base {
461461
logger.info(`📝 Local changes detected for #${issueNumber}`);
462462

463463
try {
464-
const bodyWithoutComments = parsed.content.split('## Comments')[0].trim();
464+
const bodyWithoutComments = parsed.content.split(issueSyncConfig.commentSectionDelimiter)[0].trim();
465465
const titleMatch = bodyWithoutComments.match(/^#\s+(.+)$/m);
466466
const title = titleMatch ? titleMatch[1] : parsed.data.title;
467467

0 commit comments

Comments
 (0)