-
Notifications
You must be signed in to change notification settings - Fork 0
chore: sync workflow templates #860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| 'use strict'; | ||
|
|
||
| const RUNTIME_AC_REQUIRED_LABELS = new Set([ | ||
| 'runtime-ac', | ||
| 'runtime-verification', | ||
| 'acceptance-criteria', | ||
| 'verification-spec', | ||
| 'verification-plan', | ||
| 'ac-checks', | ||
| 'runtime-checks', | ||
| ]); | ||
|
|
||
| function labelName(label) { | ||
| if (typeof label === 'string') { | ||
| return label; | ||
| } | ||
| if (label && typeof label.name === 'string') { | ||
| return label.name; | ||
| } | ||
| return ''; | ||
| } | ||
|
|
||
| function normalizeLabelName(label) { | ||
| return labelName(label).trim().toLowerCase(); | ||
| } | ||
|
|
||
| function runtimeAcRequirement(labels = []) { | ||
| const matched = []; | ||
| const seen = new Set(); | ||
|
|
||
| for (const label of labels || []) { | ||
| const normalized = normalizeLabelName(label); | ||
| if (!normalized) { | ||
| continue; | ||
| } | ||
| const colonIndex = normalized.indexOf(':'); | ||
| const suffix = | ||
| colonIndex >= 0 && colonIndex < normalized.length - 1 | ||
| ? normalized.slice(colonIndex + 1).trim() | ||
| : ''; | ||
| if ( | ||
| RUNTIME_AC_REQUIRED_LABELS.has(normalized) || | ||
| (suffix && RUNTIME_AC_REQUIRED_LABELS.has(suffix)) | ||
| ) { | ||
| if (!seen.has(normalized)) { | ||
| matched.push(normalized); | ||
| seen.add(normalized); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| required: matched.length > 0, | ||
| labels: matched, | ||
| }; | ||
| } | ||
|
|
||
| function hasRuntimeAcRequirement(labels = []) { | ||
| return runtimeAcRequirement(labels).required; | ||
| } | ||
|
|
||
| // Workflow callers should pass the withRetry function produced by createTokenAwareRetry. | ||
| async function fetchPullRequestLabels({ github, owner, repo, prNumber, withRetry }) { | ||
| if (!github || !github.rest || !github.rest.issues) { | ||
| throw new Error('GitHub client is required to evaluate runtime AC merge labels.'); | ||
| } | ||
| const call = (client = github) => | ||
| client.rest.issues.listLabelsOnIssue({ | ||
| owner, | ||
| repo, | ||
| issue_number: prNumber, | ||
| per_page: 100, | ||
| }); | ||
|
|
||
| try { | ||
| const response = withRetry ? await withRetry(call) : await call(); | ||
| return Array.isArray(response && response.data) ? response.data : []; | ||
| } catch (error) { | ||
| const message = error instanceof Error ? error.message : String(error); | ||
| throw new Error( | ||
| `Unable to evaluate runtime AC merge labels for PR #${prNumber}: ${message}`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| async function assertRuntimeAcMergeAllowed({ | ||
| github, | ||
| core, | ||
| owner, | ||
| repo, | ||
| prNumber, | ||
| labels, | ||
| withRetry, | ||
| source = 'external merge lane', | ||
| } = {}) { | ||
| if (!owner || !repo || !prNumber) { | ||
| throw new Error('owner, repo, and prNumber are required for runtime AC merge guard.'); | ||
| } | ||
|
|
||
| const labelItems = Array.isArray(labels) | ||
| ? labels | ||
| : await fetchPullRequestLabels({ github, owner, repo, prNumber, withRetry }); | ||
| const requirement = runtimeAcRequirement(labelItems); | ||
|
|
||
| if (!requirement.required) { | ||
| if (core && typeof core.info === 'function') { | ||
| core.info(`Runtime AC merge guard passed for PR #${prNumber}.`); | ||
| } | ||
| return { | ||
| allowed: true, | ||
| labels: [], | ||
| }; | ||
| } | ||
|
|
||
| const labelList = requirement.labels.join(', '); | ||
| const message = | ||
| `Runtime AC merge guard blocked ${source} for PR #${prNumber}: ` + | ||
| `label(s) ${labelList} require local Orchestrator runtime acceptance checks. ` + | ||
| 'Merge through Code/Orchestrator/merge_guard.py after the runtime AC spec passes.'; | ||
|
|
||
| if (core && typeof core.warning === 'function') { | ||
| core.warning(message); | ||
| } | ||
|
|
||
| const error = new Error(message); | ||
| error.code = 'runtime_ac_merge_blocked'; | ||
| error.labels = requirement.labels; | ||
| throw error; | ||
| } | ||
|
|
||
| module.exports = { | ||
| RUNTIME_AC_REQUIRED_LABELS, | ||
| assertRuntimeAcMergeAllowed, | ||
| hasRuntimeAcRequirement, | ||
| normalizeLabelName, | ||
| runtimeAcRequirement, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: stranske/Collab-Admin
Length of output: 109
🏁 Script executed:
Repository: stranske/Collab-Admin
Length of output: 4591
🏁 Script executed:
Repository: stranske/Workflows
Length of output: 44
🌐 Web query:
GitHub REST API listLabelsOnIssue pagination behavior per_page limit💡 Result:
The GitHub REST API endpoint for listing labels on an issue (GET /repos/{owner}/{repo}/issues/{issue_number}/labels) supports pagination via the per_page query parameter [1]. The per_page parameter allows you to control the number of results returned per page, with a maximum limit of 100 [1]. By default, this parameter is set to 30 if not specified [1]. For more extensive data retrieval, you can navigate through the paginated results using the page parameter or by utilizing the link header provided in the API response [1][2][3]. Summary of parameters: - per_page: The number of results to return per page. The minimum value is 1, and the maximum is 100 [1][4]. The default is 30 [1]. - page: The page number of the results to fetch [1]. The default is 1 [1].
Citations:
🏁 Script executed:
Repository: stranske/Workflows
Length of output: 3267
🏁 Script executed:
Repository: stranske/Workflows
Length of output: 1816
🌐 Web query:
Octokit GitHub client paginate method JavaScript💡 Result:
The paginate method in the Octokit GitHub client (provided by the
@octokit/plugin-paginate-restplugin) is designed to automatically handle multi-page API responses by fetching subsequent pages until the last page is reached [1][2]. Key aspects of the paginate method: Usage: The method accepts the same arguments as octokit.request, which includes the REST API route as the first argument and parameters as the second [3][1]. You can also pass one of the registered REST endpoint methods (e.g., octokit.rest.issues.listForRepo) as the first argument for better readability and typing [3][4]. Example: const issues = await octokit.paginate("GET /repos/{owner}/{repo}/issues", { owner: "octocat", repo: "hello-world", per_page: 100, }); Mapping and Optimization: You can pass an optional mapping function as the third argument to process or transform the data from each response [3][5]. This is useful for reducing memory usage by storing only the required fields [5][6]. The map function receives a done callback, which allows you to stop pagination prematurely if a certain condition is met [3][6]. Memory Efficiency: While octokit.paginate fetches all items into a single array, for more memory-efficient processing, you can use octokit.paginate.iterator to handle one page of results at a time using an async iterator [4][6]. GraphQL Pagination: Note that Octokit also provides support for GraphQL pagination via octokit.graphql.paginate, which follows a different pattern based on GraphQL cursors [4].Citations:
Paginate PR label reads to keep the runtime AC guard fail-closed.
fetchPullRequestLabelsonly reads the first page of results (per_page: 100). The GitHub REST API for listing issue labels is paginated, and if a PR has more than 100 labels, requirement detection will be incomplete, causing the guard to make incorrect merge decisions. Switch to the Octokitpaginate()method, which is available on the GitHub client provided by@actions/github.Suggested patch
async function fetchPullRequestLabels({ github, owner, repo, prNumber, withRetry }) { if (!github || !github.rest || !github.rest.issues) { throw new Error('GitHub client is required to evaluate runtime AC merge labels.'); } - const call = (client = github) => - client.rest.issues.listLabelsOnIssue({ + const call = async (client = github) => { + if (typeof client.paginate === 'function') { + return client.paginate(client.rest.issues.listLabelsOnIssue, { + owner, + repo, + issue_number: prNumber, + per_page: 100, + }); + } + const response = await client.rest.issues.listLabelsOnIssue({ owner, repo, issue_number: prNumber, per_page: 100, - }); + }); + return Array.isArray(response?.data) ? response.data : []; + }; try { - const response = withRetry ? await withRetry(call) : await call(); - return Array.isArray(response && response.data) ? response.data : []; + const labels = withRetry ? await withRetry(call) : await call(); + return Array.isArray(labels) ? labels : []; } catch (error) {🤖 Prompt for AI Agents