Skip to content

Commit 493b934

Browse files
committed
fix: Update task key and enhance PR and WorkItem utilities for better URL handling
1 parent 6d4ccf9 commit 493b934

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
13a03f76-52e6-47c1-a079-458ed4dae056
1+
cb9148cc-bbbc-4b0a-bf7d-d3a121c2dd8b

CommitRangeReleaseNotesTask/task/dist/utils/PRUtils.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ exports.getPRInfo = void 0;
1313
const tl = require("azure-pipelines-task-lib/task");
1414
const WorkItemUtils_1 = require("./WorkItemUtils");
1515
function getPRInfo(pullRequestId, apiUrl, project, repositoryId, accessToken) {
16-
var _a, _b, _c, _d;
16+
var _a, _b, _c, _d, _e;
1717
return __awaiter(this, void 0, void 0, function* () {
1818
try {
1919
const prUrl = `${apiUrl}/${project}/_apis/git/repositories/${repositoryId}/pullRequests/${pullRequestId}?includeWorkItemRefs=true&api-version=7.1`;
@@ -36,11 +36,14 @@ function getPRInfo(pullRequestId, apiUrl, project, repositoryId, accessToken) {
3636
console.warn(`PR ${pullRequestId} missing required title field`);
3737
return null;
3838
}
39+
const webUrl = ((_a = prJson.repository) === null || _a === void 0 ? void 0 : _a.webUrl)
40+
? `${prJson.repository.webUrl}/pullrequest/${pullRequestId}`
41+
: (((_c = (_b = prJson._links) === null || _b === void 0 ? void 0 : _b.web) === null || _c === void 0 ? void 0 : _c.href) || `${apiUrl}/${project}/_git/pullrequest/${pullRequestId}`);
3942
const prResult = {
4043
id: pullRequestId,
4144
title: prJson.title,
42-
url: ((_b = (_a = prJson._links) === null || _a === void 0 ? void 0 : _a.web) === null || _b === void 0 ? void 0 : _b.href) || `${apiUrl}/${project}/_git/pullrequest/${pullRequestId}`,
43-
author: ((_c = prJson.createdBy) === null || _c === void 0 ? void 0 : _c.displayName) || ((_d = prJson.createdBy) === null || _d === void 0 ? void 0 : _d.uniqueName) || 'Unknown',
45+
url: webUrl,
46+
author: ((_d = prJson.createdBy) === null || _d === void 0 ? void 0 : _d.displayName) || ((_e = prJson.createdBy) === null || _e === void 0 ? void 0 : _e.uniqueName) || 'Unknown',
4447
workItems: []
4548
};
4649
// Fetch work items if they exist

CommitRangeReleaseNotesTask/task/dist/utils/WorkItemUtils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
1111
Object.defineProperty(exports, "__esModule", { value: true });
1212
exports.getWorkItem = void 0;
1313
function getWorkItem(workItemId, apiUrl, project, accessToken) {
14-
var _a, _b;
14+
var _a, _b, _c, _d;
1515
return __awaiter(this, void 0, void 0, function* () {
1616
const fields = [
1717
"System.Title",
@@ -43,7 +43,7 @@ function getWorkItem(workItemId, apiUrl, project, accessToken) {
4343
id: data.id,
4444
title: data.fields["System.Title"],
4545
workItemType: data.fields["System.WorkItemType"],
46-
url: data.url,
46+
url: ((_d = (_c = data._links) === null || _c === void 0 ? void 0 : _c.html) === null || _d === void 0 ? void 0 : _d.href) || data.url,
4747
assignedTo: data.fields["System.AssignedTo"] ? {
4848
displayName: data.fields["System.AssignedTo"].displayName || 'Unassigned',
4949
uniqueName: data.fields["System.AssignedTo"].uniqueName || '',

CommitRangeReleaseNotesTask/task/utils/PRUtils.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import tl = require("azure-pipelines-task-lib/task");
2-
import { getWorkItem, type WorkItem } from './WorkItemUtils';
2+
import { getWorkItem, type WorkItem } from './WorkItemUtils';
33

44
export interface PullRequest {
55
id: number;
@@ -43,10 +43,15 @@ export async function getPRInfo(
4343
return null;
4444
}
4545

46+
const webUrl =
47+
prJson.repository?.webUrl
48+
? `${prJson.repository.webUrl}/pullrequest/${pullRequestId}`
49+
: (prJson._links?.web?.href || `${apiUrl}/${project}/_git/pullrequest/${pullRequestId}`);
50+
4651
const prResult: PullRequest = {
4752
id: pullRequestId,
4853
title: prJson.title,
49-
url: prJson._links?.web?.href || `${apiUrl}/${project}/_git/pullrequest/${pullRequestId}`,
54+
url: webUrl,
5055
author: prJson.createdBy?.displayName || prJson.createdBy?.uniqueName || 'Unknown',
5156
workItems: []
5257
};

CommitRangeReleaseNotesTask/task/utils/WorkItemUtils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export interface WorkItemApiResponse {
2020
"System.WorkItemType": string;
2121
"System.AssignedTo"?: WorkItemAssignedTo;
2222
};
23+
_links?: {
24+
html?: { href: string };
25+
};
2326
}
2427

2528
export async function getWorkItem(
@@ -55,6 +58,7 @@ export async function getWorkItem(
5558

5659
const data: WorkItemApiResponse = await response.json();
5760

61+
5862
// Validate required fields
5963
if (!data.fields?.["System.Title"] || !data.fields?.["System.WorkItemType"]) {
6064
console.warn(`Work item ${workItemId} missing required fields`);
@@ -65,7 +69,7 @@ export async function getWorkItem(
6569
id: data.id,
6670
title: data.fields["System.Title"],
6771
workItemType: data.fields["System.WorkItemType"],
68-
url: data.url,
72+
url: data._links?.html?.href || data.url,
6973
assignedTo: data.fields["System.AssignedTo"] ? {
7074
displayName: data.fields["System.AssignedTo"].displayName || 'Unassigned',
7175
uniqueName: data.fields["System.AssignedTo"].uniqueName || '',

0 commit comments

Comments
 (0)