Skip to content

[CSR-4184] feat: added azure devops pr info#8

Open
miguelangaranocurrents wants to merge 11 commits intomasterfrom
feat/detect-azure-ci
Open

[CSR-4184] feat: added azure devops pr info#8
miguelangaranocurrents wants to merge 11 commits intomasterfrom
feat/detect-azure-ci

Conversation

@miguelangaranocurrents
Copy link
Copy Markdown

@miguelangaranocurrents miguelangaranocurrents commented Apr 27, 2026

Branch feat/detect-azure-ci — implementation summary

This 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 when GITHUB_EVENT_PATH + GITHUB_ACTIONS yield a PR payload; otherwise tries Azure when BUILD_REASON=PullRequest and SYSTEM_PULLREQUEST_PULLREQUESTID is set.
    • Explicit github-actions or azure-pipelines skips the other provider.
  • commitInfo(folder, options) accepts pullRequestProvider (auto | github-actions | azure-pipelines, default auto).

  • GitHub Actions: unchanged shape; exposed as ghaEventData (same fields as before, without the internal provider key).

  • Azure Pipelines: adoEventData includes PR number, canonical PR URL (pullRequestId and htmlUrl), 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 for pullRequestId.

  • Title: Uses SYSTEM_PULLREQUEST_TITLE when set; otherwise parses BUILD_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) and BUILD_REPOSITORY_ID are present, calls the Git REST API for the PR to:

    • Prefer the real PR title from the API.
    • Fill baseSha (no documented env var for target commit) and backfill headSha when missing, from lastMergeTargetCommit / lastMergeSourceCommit.
    • Improve sender avatar/HTML URLs from createdBy when 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.jsnpm run ado-pr-verify: on Azure PR builds only, asserts that commitInfo(..., { pullRequestProvider: 'azure-pipelines' }) returns non-empty adoEventData with expected fields; non-PR runs exit 0 with a skip message.

  • azure-pipelines.yml — Azure Repos pipeline: Node 18, npm ci, npm test, then ado-pr-verify (optional token comment for richer title via REST).

Refactors / compatibility

  • src/utils.js: GHA/Azure PR reads delegate to pull-request-ci; docs note baseSha for 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 the ado-pr-verify script.


Demo

Execution log:

2026-04-28T03:41:58.3265403Z ##[section]Starting: Verify Azure PR → commit-info adoEventData
2026-04-28T03:41:58.3271444Z ==============================================================================
2026-04-28T03:41:58.3271556Z Task         : Command line
2026-04-28T03:41:58.3271619Z Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
2026-04-28T03:41:58.3271717Z Version      : 2.268.0
2026-04-28T03:41:58.3271774Z Author       : Microsoft Corporation
2026-04-28T03:41:58.3271836Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
2026-04-28T03:41:58.3271926Z ==============================================================================
2026-04-28T03:41:58.4278134Z Generating script.
2026-04-28T03:41:58.4290608Z Script contents:
2026-04-28T03:41:58.4305056Z npm run ado-pr-verify
2026-04-28T03:41:58.4305602Z ========================== Starting Command Output ===========================
2026-04-28T03:41:58.4328329Z [command]/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/8c44b6ca-08e4-4755-80f6-ff36aa7f4d3a.sh
2026-04-28T03:41:58.6011224Z 
2026-04-28T03:41:58.6014198Z > @currents/commit-info@1.0.1-beta.0 ado-pr-verify
2026-04-28T03:41:58.6014756Z > node scripts/verify-ado-pr-info.js
2026-04-28T03:41:58.6015073Z 
2026-04-28T03:41:58.8013880Z ado-pr-verify: adoEventData = {
2026-04-28T03:41:58.8020314Z   "pullRequestId": "https://igneusideas.visualstudio.com/MyFirstProject/_git/commit-info/pullrequest/1",
2026-04-28T03:41:58.8020903Z   "pullRequestNumber": "1",
2026-04-28T03:41:58.8021315Z   "buildSourceBranch": "refs/pull/1/merge",
2026-04-28T03:41:58.8021718Z   "headRef": "refs/heads/feat/detect-azure-ci",
2026-04-28T03:41:58.8022129Z   "headSha": "6b01117f48b167e4b1185725f37f2137e77d5038",
2026-04-28T03:41:58.8022601Z   "baseRef": "refs/heads/master",
2026-04-28T03:41:58.8023004Z   "baseSha": null,
2026-04-28T03:41:58.8023363Z   "issueUrl": null,
2026-04-28T03:41:58.8023862Z   "htmlUrl": "https://igneusideas.visualstudio.com/MyFirstProject/_git/commit-info/pullrequest/1",
2026-04-28T03:41:58.8024419Z   "prTitle": "Merge pull request 1 from feat/detect-azure-ci into master",
2026-04-28T03:41:58.8025029Z   "senderAvatarUrl": "https://igneusideas.visualstudio.com/_apis/GraphProfile/MemberAvatars/b9c6e39f-61c8-6679-bcfb-9dd104fe98dd?size=2&api-version=5.1-preview.1",
2026-04-28T03:41:58.8025662Z   "senderHtmlUrl": "https://igneusideas.visualstudio.com/_usersSettings/about?userId=b9c6e39f-61c8-6679-bcfb-9dd104fe98dd"
2026-04-28T03:41:58.8026182Z }
2026-04-28T03:41:58.8159702Z 
2026-04-28T03:41:58.8234292Z ##[section]Finishing: Verify Azure PR → commit-info adoEventData
image

Summary by CodeRabbit

  • New Features

    • Added Azure Pipelines pull-request metadata support alongside GitHub Actions.
    • Provider auto-detection with optional explicit provider selection; exposes provider identifiers.
  • CI / Chores

    • New Azure Pipelines configuration and a verification step to validate PR metadata during PR builds.
    • New script to verify Azure PR info in pipeline runs.
  • Tests

    • Added comprehensive tests and updated snapshots covering multi-provider detection, enrichment, parsing, and edge cases.

@notion-workspace
Copy link
Copy Markdown

Azure DevOps PR data

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 27, 2026

📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
Provider core & utils
src/pull-request-ci.js, src/utils.js, src/index.js
New pull-request-ci module with provider constants, GH/ADO readers, resolver (resolvePullRequestCi), Azure enrichment (enrichAzurePullRequestCi), and withoutProvider. commitInfo accepts options and surfaces pullRequestCi; getAdoPrEventData added. Exports extended to include resolver and provider constants.
Tests & snapshots
src/pull-request-ci-spec.js, src/utils-spec.js, __snapshots__/commit-info-spec.js
Adds unit tests for provider selection, Azure enrichment, title/sender parsing, GH/ADO read behaviors, and updates snapshots to include new exported API entries.
Azure CI & verification
azure-pipelines.yml, scripts/verify-ado-pr-info.js, package.json
Adds Azure Pipelines YAML, verification script scripts/verify-ado-pr-info.js (runs only on PR builds, invokes commitInfo with pullRequestProvider: 'azure-pipelines' and asserts ADO fields), and npm script ado-pr-verify.

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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The PR title accurately describes the main change: adding Azure DevOps pull request information detection and processing capabilities to the codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/detect-azure-ci

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. Importing PROVIDER_AZURE_PIPELINES keeps 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

📥 Commits

Reviewing files that changed from the base of the PR and between 80ffa78 and 2b56e6f.

📒 Files selected for processing (9)
  • __snapshots__/commit-info-spec.js
  • azure-pipelines.yml
  • package.json
  • scripts/verify-ado-pr-info.js
  • src/index.js
  • src/pull-request-ci-spec.js
  • src/pull-request-ci.js
  • src/utils-spec.js
  • src/utils.js

Comment thread src/pull-request-ci.js
Comment thread src/pull-request-ci.js Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2b56e6f and a441899.

📒 Files selected for processing (7)
  • azure-pipelines.yml
  • scripts/verify-ado-pr-info.js
  • src/index.js
  • src/pull-request-ci-spec.js
  • src/pull-request-ci.js
  • src/utils-spec.js
  • src/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

Comment thread src/pull-request-ci.js Outdated
Comment thread src/pull-request-ci.js
Comment thread src/pull-request-ci.js Outdated
@agoldis agoldis changed the title [CSR-4184] feat: addded azure devops pr info [CSR-4184] feat: added azure devops pr info Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants