[CSR-4184] feat: added azure devops pr info#8
[CSR-4184] feat: added azure devops pr info#8miguelangaranocurrents wants to merge 11 commits intomasterfrom
Conversation
📝 WalkthroughWalkthroughAdds multi-provider PR CI support for GitHub Actions and Azure Pipelines: new provider detection/enrichment, Azure-specific PR extraction and REST enrichment, exposes provider constants and resolver, updates commitInfo to accept options, new tests/snapshots, and Azure Pipelines CI + verification script. Changes
Sequence Diagram(s)sequenceDiagram
participant Pipeline as "Azure Pipeline (env)"
participant Script as "verify-ado-pr-info.js"
participant Library as "commitInfo / pull-request-ci"
participant FS as "fs / GHA event file"
participant ADO as "Azure Dev REST API"
Pipeline->>Script: run PR job (BUILD_REASON=PullRequest)
Script->>Library: commitInfo(folder, { pullRequestProvider: 'azure-pipelines' })
Library->>Library: resolvePullRequestCi({env, fs, provider:'azure-pipelines'})
alt provider == azure-pipelines
Library->>Library: readAzurePipelinesPullRequest(env)
Library->>ADO: (optional) GET PR via REST (token from env)
ADO-->>Library: PR REST response (title, createdBy, commits)
Library->>Library: enrichAzurePullRequestCi(...merge fields...)
Library-->>Script: return info.adoEventData
else provider == github-actions
Library->>FS: read GITHUB_EVENT_PATH
FS-->>Library: event JSON
Library-->>Script: return info.ghaEventData
end
Script->>Script: validate returned adoEventData fields
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
scripts/verify-ado-pr-info.js (1)
11-23: Use the exported provider constant here.Hardcoding
'azure-pipelines'in the verifier duplicates a public API value the package already exports. ImportingPROVIDER_AZURE_PIPELINESkeeps this script aligned if the provider id ever changes.Small cleanup
-const { commitInfo } = require('../src') +const { commitInfo, PROVIDER_AZURE_PIPELINES } = require('../src') @@ -commitInfo(process.cwd(), { pullRequestProvider: 'azure-pipelines' }) +commitInfo(process.cwd(), { pullRequestProvider: PROVIDER_AZURE_PIPELINES })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@scripts/verify-ado-pr-info.js` around lines 11 - 23, Replace the hardcoded 'azure-pipelines' string with the exported provider constant from the package: import PROVIDER_AZURE_PIPELINES from '../src' alongside commitInfo and pass that constant to commitInfo(process.cwd(), { pullRequestProvider: PROVIDER_AZURE_PIPELINES }); update the top require destructuring to include PROVIDER_AZURE_PIPELINES so the script uses the canonical provider id rather than duplicating the literal.src/pull-request-ci-spec.js (1)
43-98: Optional: deduplicate repeated env fixtures to reduce test drift.Several test cases repeat near-identical env objects. A small fixture/helper would make future provider-variable changes safer.
♻️ Example refactor
+ const ghaAndAdoEnv = { + GITHUB_ACTIONS: 'true', + GITHUB_EVENT_PATH: '/tmp/event.json', + BUILD_REASON: 'PullRequest', + SYSTEM_PULLREQUEST_PULLREQUESTID: '99' + } it('auto prefers GitHub Actions when event file is present', () => { const r = resolvePullRequestCi({ - env: { - GITHUB_ACTIONS: 'true', - GITHUB_EVENT_PATH: '/tmp/event.json', - BUILD_REASON: 'PullRequest', - SYSTEM_PULLREQUEST_PULLREQUESTID: '99' - }, + env: ghaAndAdoEnv, fs, provider: 'auto' })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/pull-request-ci-spec.js` around lines 43 - 98, Tests in src/pull-request-ci-spec.js repeat near-identical env objects across cases calling resolvePullRequestCi; extract a shared fixture (e.g., const baseEnv = { GITHUB_ACTIONS: 'true', GITHUB_EVENT_PATH: '/tmp/event.json', BUILD_REASON: 'PullRequest', SYSTEM_PULLREQUEST_PULLREQUESTID: '99' }) and replace inline env literals with shallow copies and overrides (e.g., { ...baseEnv, SYSTEM_PULLREQUEST_PULLREQUESTID: '7', SYSTEM_PULLREQUEST_SOURCEBRANCH: 'refs/heads/f' }) so each it(...) uses the fixture plus only the deltas; update the tests that assert provider constants (PROVIDER_GITHUB_ACTIONS, PROVIDER_AZURE_PIPELINES) accordingly and keep calls to resolvePullRequestCi unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/pull-request-ci.js`:
- Around line 8-11: The function withoutProvider uses object rest destructuring
(const { provider, ...rest } = record) which is unsupported on Node 6; modify
withoutProvider to build and return a new object that excludes the provider key
without using rest/spread—e.g., iterate over record's own properties
(Object.keys or for...in + hasOwnProperty) and copy each key/value into a new
object when the key !== 'provider', keeping the early return if record is falsy
and ensuring the returned value replaces the current rest usage.
---
Nitpick comments:
In `@scripts/verify-ado-pr-info.js`:
- Around line 11-23: Replace the hardcoded 'azure-pipelines' string with the
exported provider constant from the package: import PROVIDER_AZURE_PIPELINES
from '../src' alongside commitInfo and pass that constant to
commitInfo(process.cwd(), { pullRequestProvider: PROVIDER_AZURE_PIPELINES });
update the top require destructuring to include PROVIDER_AZURE_PIPELINES so the
script uses the canonical provider id rather than duplicating the literal.
In `@src/pull-request-ci-spec.js`:
- Around line 43-98: Tests in src/pull-request-ci-spec.js repeat near-identical
env objects across cases calling resolvePullRequestCi; extract a shared fixture
(e.g., const baseEnv = { GITHUB_ACTIONS: 'true', GITHUB_EVENT_PATH:
'/tmp/event.json', BUILD_REASON: 'PullRequest',
SYSTEM_PULLREQUEST_PULLREQUESTID: '99' }) and replace inline env literals with
shallow copies and overrides (e.g., { ...baseEnv,
SYSTEM_PULLREQUEST_PULLREQUESTID: '7', SYSTEM_PULLREQUEST_SOURCEBRANCH:
'refs/heads/f' }) so each it(...) uses the fixture plus only the deltas; update
the tests that assert provider constants (PROVIDER_GITHUB_ACTIONS,
PROVIDER_AZURE_PIPELINES) accordingly and keep calls to resolvePullRequestCi
unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 65e3cf4a-dcac-413f-bef2-322ecd5c252f
📒 Files selected for processing (9)
__snapshots__/commit-info-spec.jsazure-pipelines.ymlpackage.jsonscripts/verify-ado-pr-info.jssrc/index.jssrc/pull-request-ci-spec.jssrc/pull-request-ci.jssrc/utils-spec.jssrc/utils.js
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/pull-request-ci.js`:
- Around line 124-125: The current assignment to headSha uses
env.SYSTEM_PULLREQUEST_SOURCECOMMITID || env.BUILD_SOURCEVERSION || null which
lets BUILD_SOURCEVERSION override null and prevents REST enrichment from
correcting it; change the assignment in src/pull-request-ci.js to only use
SYSTEM_PULLREQUEST_SOURCECOMMITID and null (i.e., remove the BUILD_SOURCEVERSION
fallback) so headSha is null when not provided and can be populated later by
REST enrichment (adjust or remove the "falls back headSha to
BUILD_SOURCEVERSION" test in src/utils-spec.js accordingly).
- Around line 226-264: The httpGetJson function can hang forever on stalled
connections; update httpGetJson to call req.setTimeout(...) (e.g. 30_000 ms) and
in the timeout handler call req.destroy() and reject the Promise with a clear
timeout Error so callers like enrichAzurePullRequestCi() / commitInfo() won't
block indefinitely; ensure the timeout handler and req 'error' listener won't
produce double-rejections (guard the Promise resolution/rejection so only one
path wins) and include the URL or context in the timeout error message.
- Around line 294-311: Replace the API endpoint assignment for senderHtmlUrl
with a call to the existing helper that builds a browser-facing ADO profile URL:
use adoSenderHtmlUrl(createdBy) (falling back to ci.senderHtmlUrl) instead of
createdBy.url; update the PR enrichment return where senderHtmlUrl is set
(referencing createdBy and senderHtmlUrl in that object) so it mirrors the Build
enrichment usage of adoSenderHtmlUrl().
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5f34763f-4544-4304-aa2f-f605f6834ff2
📒 Files selected for processing (7)
azure-pipelines.ymlscripts/verify-ado-pr-info.jssrc/index.jssrc/pull-request-ci-spec.jssrc/pull-request-ci.jssrc/utils-spec.jssrc/utils.js
✅ Files skipped from review due to trivial changes (1)
- azure-pipelines.yml
🚧 Files skipped from review as they are similar to previous changes (2)
- scripts/verify-ado-pr-info.js
- src/index.js
Branch
feat/detect-azure-ci— implementation summaryThis branch adds Azure DevOps / Azure Pipelines pull request detection and surfaces it alongside the existing GitHub Actions path.
commitInfo()can resolve PR metadata from either CI system (or force a provider).Core behavior
resolvePullRequestCi()(src/pull-request-ci.js) picks PR context by provider:auto: prefers GitHub Actions whenGITHUB_EVENT_PATH+GITHUB_ACTIONSyield a PR payload; otherwise tries Azure whenBUILD_REASON=PullRequestandSYSTEM_PULLREQUEST_PULLREQUESTIDis set.github-actionsorazure-pipelinesskips the other provider.commitInfo(folder, options)acceptspullRequestProvider(auto|github-actions|azure-pipelines, defaultauto).GitHub Actions: unchanged shape; exposed as
ghaEventData(same fields as before, without the internalproviderkey).Azure Pipelines:
adoEventDataincludes PR number, canonical PR URL (pullRequestIdandhtmlUrl), refs/SHAs when available, title, and sender avatar/profile URLs derived from env (and optionally REST).Azure-specific details
PR URL: Built from
SYSTEM_TEAMFOUNDATIONCOLLECTIONURI,SYSTEM_TEAMPROJECT,BUILD_REPOSITORY_NAME, and the numeric PR id — no numeric-only fallback forpullRequestId.Title: Uses
SYSTEM_PULLREQUEST_TITLEwhen set; otherwise parsesBUILD_SOURCEVERSIONMESSAGE(e.g.Merged PR {id}: {title}), avoiding Git-style merge messages that are not the UI title.Enrichment (
enrichAzurePullRequestCi): If a token (e.g.SYSTEM_ACCESSTOKEN) andBUILD_REPOSITORY_IDare present, calls the Git REST API for the PR to:baseSha(no documented env var for target commit) and backfillheadShawhen missing, fromlastMergeTargetCommit/lastMergeSourceCommit.createdBywhen available.HTTP helper uses a 30s timeout on JSON GETs; failures fall back to env-only data.
Tests and tooling
src/pull-request-ci-spec.js— unit coverage for resolution, URLs, titles, enrichment, and edge cases.src/utils-spec.js— extended for shared helpers.scripts/verify-ado-pr-info.js—npm run ado-pr-verify: on Azure PR builds only, asserts thatcommitInfo(..., { pullRequestProvider: 'azure-pipelines' })returns non-emptyadoEventDatawith expected fields; non-PR runs exit 0 with a skip message.azure-pipelines.yml— Azure Repos pipeline: Node 18,npm ci,npm test, thenado-pr-verify(optional token comment for richer title via REST).Refactors / compatibility
src/utils.js: GHA/Azure PR reads delegate topull-request-ci; docs notebaseShafor Azure env-only vs REST-enriched behavior.Object handling avoids patterns that break older Node where needed (e.g. compatibility-oriented destructuring).
package.json: adds theado-pr-verifyscript.Demo
Execution log:
Summary by CodeRabbit
New Features
CI / Chores
Tests