MCPcopy Create free account
hub / github.com/appium/appium / getMergedPullRequestsFromSearch

Function getMergedPullRequestsFromSearch

scripts/github-contrib-stats.mjs:135–181  ·  view source on GitHub ↗

* Get merged pull requests from the Appium organization for the specified date range using GitHub search API * @param {Object} dateRange - Date range object with from and to properties * @param {string} dateRange.from - Start date in ISO format * @param {string} dateRange.to - End date in ISO for

(dateRange, token)

Source from the content-addressed store, hash-verified

133 * @returns {Promise<GitHubPullRequest[]>} Array of pull request objects
134 */
135async function getMergedPullRequestsFromSearch(dateRange, token) {
136 /** @type {GitHubPullRequest[]} */
137 const pullRequests = [];
138 let page = 1;
139 const perPage = ITEMS_PER_PAGE;
140
141 // Convert ISO dates to GitHub's expected format (YYYY-MM-DD)
142 const fromDate = extractDatePart(dateRange.from);
143 const toDate = extractDatePart(dateRange.to);
144
145 // Build search query for merged pull requests in the appium organization
146 // Using GitHub's search syntax: https://docs.github.com/en/search-github/searching-on-github/searching-issues-and-pull-requests
147 const excludedAuthors = INTERNAL_EXCLUSION_LIST.map((author) => `-author:${author}`).join(' ');
148 const searchQuery = `org:${GITHUB_ORG} is:pr is:merged merged:${fromDate}..${toDate} ${excludedAuthors}`;
149 while (true) {
150 // Rely on local sorting; omit API-side sort/order for simplicity
151 const endpoint = `/search/issues?q=${encodeURIComponent(searchQuery)}&page=${page}&per_page=${perPage}`;
152 const {data} = await makeGitHubRequest(endpoint, token);
153 if (!data.items?.length) {
154 break;
155 }
156
157 // Process the search results (pull requests)
158 pullRequests.push(
159 ...data.items.map((pr) => ({
160 sha: pr.merge_commit_sha,
161 author: pr.user,
162 created_at: pr.created_at,
163 merged_at: pr.merged_at || pr.closed_at, // Use closed_at as fallback if merged_at is null
164 commit: {
165 message: pr.title, // Use PR title as the commit message
166 },
167 html_url: pr.html_url,
168 repository: pr.repository_url.split('/').pop(), // Extract repo name from URL
169 })),
170 );
171
172 page++;
173 // Safety check
174 if (page > MAX_PAGE_LIMIT) {
175 log.warn(`Reached maximum page limit (${MAX_PAGE_LIMIT}) for PR search`);
176 break;
177 }
178 }
179
180 return pullRequests;
181}
182
183/**
184 * Format GitHub pull request data as Slack message blocks

Callers 1

mainFunction · 0.85

Calls 4

extractDatePartFunction · 0.85
makeGitHubRequestFunction · 0.85
pushMethod · 0.80
warnMethod · 0.65

Tested by

no test coverage detected