Repository navigation
chore: sync workflow templates #1198
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.
Avoid a second label API read in the guarded-merge loop.
At Line 1736,
assertRuntimeAcMergeAllowedre-fetches labels even thoughpr.labelsis already available from the PR fetch in this loop. That adds an unnecessary network dependency and can fail merges on transient label-read errors despite already having label data. Passpr.labelsinto the guard and only fall back to API fetch when labels are missing.Suggested patch
try { + const knownLabels = Array.isArray(pr.labels) ? pr.labels : undefined; await assertRuntimeAcMergeAllowed({ github, core, owner, repo, prNumber, + labels: knownLabels, withRetry, source: 'agents-81-gate-followups guarded merge', });🤖 Prompt for AI Agents