fix: replace azure-devops-node-api with direct REST calls#192
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
fetchinstead of the SDK and added an assertion for JSON Patch content type. - Removed
azure-devops-node-apifrom dependencies and bumped the package version to4.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 pointinternalRepoIdhas 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!'). SinceinternalRepoIdwas 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
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
8886db6 to
3a24d07
Compare
📦 Draft Release CreatedA draft release v4.1.5 has been created for this PR. Next Steps
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Removes the
azure-devops-node-apidependency and replaces all SDK usage with directfetchcalls to the Azure DevOps REST API.Problem
The
azure-devops-node-apiSDK and itstyped-rest-clientdependency use the deprecatedurl.parse()API, causingDEP0169warnings 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.emitWarningto suppress the warning, this PR removes the root cause by replacing the SDK with direct REST API calls using Node's built-infetch. The action already usedfetch+ Basic auth for the data provider query, so this makes the codebase consistent.Changes
src/link-work-item.js: Replace SDK calls withazureDevOpsRequest()helper usingfetchsrc/main.js: Same migration (legacy file, kept consistent)__tests__/link-work-item.test.js: Replace SDK mocks withfetchmocks, add content-type assertion for PATCHpackage.json: Removeazure-devops-node-apidependency, bump to 4.1.4Benefits
typed-rest-client,tunnel, etc.)Closes #191