Skip to content

fix: replace azure-devops-node-api with direct REST calls#192

Merged
joshjohanning merged 1 commit into
mainfrom
fix/remove-azure-devops-node-api
May 5, 2026
Merged

fix: replace azure-devops-node-api with direct REST calls#192
joshjohanning merged 1 commit into
mainfrom
fix/remove-azure-devops-node-api

Conversation

@joshjohanning
Copy link
Copy Markdown
Owner

Summary

Removes the azure-devops-node-api dependency and replaces all SDK usage with direct fetch calls to the Azure DevOps REST API.

Problem

The azure-devops-node-api SDK and its typed-rest-client dependency use the deprecated url.parse() API, causing DEP0169 warnings on Node 22+ (microsoft/azure-devops-node-api#664). Even the latest versions of both packages have not fixed this, and the upstream issue is still in triage.

Solution

Rather than monkey-patching process.emitWarning to suppress the warning, this PR removes the root cause by replacing the SDK with direct REST API calls using Node's built-in fetch. The action already used fetch + Basic auth for the data provider query, so this makes the codebase consistent.

Changes

  • src/link-work-item.js: Replace SDK calls with azureDevOpsRequest() helper using fetch
  • src/main.js: Same migration (legacy file, kept consistent)
  • __tests__/link-work-item.test.js: Replace SDK mocks with fetch mocks, add content-type assertion for PATCH
  • package.json: Remove azure-devops-node-api dependency, bump to 4.1.4

Benefits

  • ✅ Fixes DEP0169 warning at its root
  • 70% bundle size reduction (4,254kB → 1,264kB)
  • ✅ Removes heavy transitive dependency tree (typed-rest-client, tunnel, etc.)
  • ✅ Zero behavior change — same API surface and error handling

Closes #191

Copilot AI review requested due to automatic review settings May 5, 2026 16:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR removes the azure-devops-node-api SDK dependency and migrates the Azure DevOps integration to direct REST API calls via Node’s built-in fetch, addressing the DEP0169 warnings on Node 22+ and reducing bundle size.

Changes:

  • Replaced Azure DevOps SDK usage with a small fetch-based REST helper in the work-item linking logic.
  • Updated Jest tests to mock fetch instead of the SDK and added an assertion for JSON Patch content type.
  • Removed azure-devops-node-api from dependencies and bumped the package version to 4.1.4 (with lockfile + coverage badge updates).
Show a summary per file
File Description
src/link-work-item.js Migrates work item linking/lookup to fetch via a new REST helper.
src/main.js Applies the same REST-based approach for consistency with the legacy module.
tests/link-work-item.test.js Reworks mocks to use fetch and validates PATCH content type.
package.json Removes azure-devops-node-api dependency and bumps version to 4.1.4.
package-lock.json Updates lockfile to reflect dependency removal and version bump.
badges/coverage.svg Updates the generated coverage badge.

Copilot's findings

Comments suppressed due to low confidence (2)

src/link-work-item.js:145

  • If the PATCH request to link the PR fails for reasons other than "already exists", the error is rethrown and then handled by the outer catch which calls core.setFailed('Failed to retrieve internalRepoId!'). At that point internalRepoId has already been retrieved successfully, so this failure message is misleading. Consider handling PATCH failures separately (e.g., setFailed with a "Failed to link PR to work item" message, or throw a new error that preserves context) so users get an accurate error.
        await azureDevOpsRequest(
          `https://dev.azure.com/${devOpsOrg}/_apis/wit/workitems/${workItemId}?$expand=relations&api-version=7.1`,
          azToken,
          {
            method: 'PATCH',
            headers: { 'Content-Type': 'application/json-patch+json' },
            body: JSON.stringify(patchDoc)
          }
        );
        core.info('... success!');
      } catch (exception) {
        const errorMessage = exception.toString();
        if (-1 !== errorMessage.indexOf('already exists')) {
          core.info('... (already exists) ...');
        } else {
          throw exception;
        }
      }

src/main.js:145

  • If the PATCH request to link the PR fails for reasons other than "already exists", the error is rethrown and then handled by the outer catch which calls core.setFailed('Failed to retrieve internalRepoId!'). Since internalRepoId was already resolved, this message is misleading. Consider handling PATCH failures separately (or rethrowing a contextualized error) so the reported failure matches the real cause.
        await azureDevOpsRequest(
          `https://dev.azure.com/${devOpsOrg}/_apis/wit/workitems/${workItemId}?$expand=relations&api-version=7.1`,
          azToken,
          {
            method: 'PATCH',
            headers: { 'Content-Type': 'application/json-patch+json' },
            body: JSON.stringify(patchDoc)
          }
        );
        core.info('... success!');
      } catch (exception) {
        const errorMessage = exception.toString();
        if (-1 !== errorMessage.indexOf('already exists')) {
          core.info('... (already exists) ...');
        } else {
          throw exception;
        }
      }
  • Files reviewed: 4/6 changed files
  • Comments generated: 2

Comment thread src/main.js Outdated
Comment thread src/link-work-item.js Outdated
Remove the azure-devops-node-api dependency and replace all SDK usage
with direct fetch calls to the Azure DevOps REST API. This eliminates
the DEP0169 url.parse() deprecation warning caused by the SDK and its
typed-rest-client dependency (microsoft/azure-devops-node-api#664).

Shared helpers (azureDevOpsHeaders, azureDevOpsRequest) are extracted
into src/azure-devops-rest.js and imported by both entrypoints.

Benefits:
- Fixes DEP0169 warning at its root (no monkey-patching needed)
- Reduces bundle size by ~70% (4,254kB -> 1,264kB)
- Uses the same fetch + Basic auth pattern already in the codebase
- Removes heavy transitive dependency tree (typed-rest-client, tunnel)

The action API surface and behavior are unchanged.

Closes #191
@joshjohanning joshjohanning force-pushed the fix/remove-azure-devops-node-api branch from 8886db6 to 3a24d07 Compare May 5, 2026 17:10
@joshjohanning joshjohanning merged commit 50ff1db into main May 5, 2026
3 checks passed
@joshjohanning joshjohanning deleted the fix/remove-azure-devops-node-api branch May 5, 2026 17:11
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

📦 Draft Release Created

A draft release v4.1.5 has been created for this PR.

🔗 View Draft Release

Next Steps

  • Review the release notes
  • Publish the release to make it permanent

This is an automated reminder from the publish-github-action workflow.

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.

Minor : Fix the DEP0169 warning

2 participants