MCPcopy Create free account
hub / github.com/github/gh-aw / searchForExistingParent

Function searchForExistingParent

actions/setup/js/create_issue.cjs:81–122  ·  view source on GitHub ↗

* Searches for an existing parent issue that can accept more sub-issues * @param {string} owner - Repository owner * @param {string} repo - Repository name * @param {string} markerComment - The HTML comment marker to search for * @returns {Promise } - Parent issue number or null if n

(githubClient, owner, repo, markerComment)

Source from the content-addressed store, hash-verified

79 * @returns {Promise<number|null>} - Parent issue number or null if none found
80 */
81async function searchForExistingParent(githubClient, owner, repo, markerComment) {
82 try {
83 const searchQuery = `repo:${owner}/${repo} is:issue "${markerComment}" in:body`;
84 const searchResults = await githubClient.rest.search.issuesAndPullRequests({
85 q: searchQuery,
86 per_page: MAX_PARENT_ISSUES_TO_CHECK,
87 sort: "created",
88 order: "desc",
89 });
90
91 if (searchResults.data.total_count === 0) {
92 return null;
93 }
94
95 // Check each found issue to see if it can accept more sub-issues
96 for (const issue of searchResults.data.items) {
97 core.info(`Found potential parent issue #${issue.number}: ${issue.title}`);
98
99 if (issue.state !== "open") {
100 core.info(`Parent issue #${issue.number} is ${issue.state}, skipping`);
101 continue;
102 }
103
104 const subIssueCount = await getSubIssueCount(owner, repo, issue.number);
105 if (subIssueCount === null) {
106 continue; // Skip if we couldn't get the count
107 }
108
109 if (subIssueCount < MAX_SUB_ISSUES_PER_PARENT) {
110 core.info(`Using existing parent issue #${issue.number} (has ${subIssueCount}/${MAX_SUB_ISSUES_PER_PARENT} sub-issues)`);
111 return issue.number;
112 }
113
114 core.info(`Parent issue #${issue.number} is full (${subIssueCount}/${MAX_SUB_ISSUES_PER_PARENT} sub-issues), skipping`);
115 }
116
117 return null;
118 } catch (error) {
119 core.warning(`Could not search for existing parent issues: ${getErrorMessage(error)}`);
120 return null;
121 }
122}
123
124/**
125 * Finds an existing parent issue for a group, or creates a new one if needed

Callers 2

findOrCreateParentIssueFunction · 0.85

Calls 2

getSubIssueCountFunction · 0.85
getErrorMessageFunction · 0.70

Tested by

no test coverage detected