@elisra-devops/docgen-data-provider 0.4.6 → 0.4.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/sonar-project.properties +4 -4
- package/.github/workflows/ci.yml +21 -21
- package/.github/workflows/release.yml +45 -40
- package/LICENSE +21 -21
- package/README.md +39 -38
- package/bin/helpers/helper.d.ts +37 -0
- package/bin/helpers/helper.js +83 -0
- package/bin/helpers/helper.js.map +1 -0
- package/bin/helpers/tfs.d.ts +5 -0
- package/bin/helpers/tfs.js +100 -0
- package/bin/helpers/tfs.js.map +1 -0
- package/bin/index.d.ts +16 -0
- package/bin/index.js +53 -0
- package/bin/index.js.map +1 -0
- package/bin/models/tfs-data.d.ts +86 -0
- package/bin/models/tfs-data.js +63 -0
- package/bin/models/tfs-data.js.map +1 -0
- package/bin/modules/GitDataProvider.d.ts +26 -0
- package/bin/modules/GitDataProvider.js +301 -0
- package/bin/modules/GitDataProvider.js.map +1 -0
- package/bin/modules/MangementDataProvider.d.ts +9 -0
- package/bin/modules/MangementDataProvider.js +62 -0
- package/bin/modules/MangementDataProvider.js.map +1 -0
- package/bin/modules/PipelinesDataProvider.d.ts +13 -0
- package/bin/modules/PipelinesDataProvider.js +103 -0
- package/bin/modules/PipelinesDataProvider.js.map +1 -0
- package/bin/modules/TestDataProvider.d.ts +24 -0
- package/bin/modules/TestDataProvider.js +294 -0
- package/bin/modules/TestDataProvider.js.map +1 -0
- package/bin/modules/TicketsDataProvider.d.ts +26 -0
- package/bin/modules/TicketsDataProvider.js +385 -0
- package/bin/modules/TicketsDataProvider.js.map +1 -0
- package/bin/modules/test/gitDataProvider.test.d.ts +1 -0
- package/bin/modules/test/gitDataProvider.test.js +138 -0
- package/bin/modules/test/gitDataProvider.test.js.map +1 -0
- package/bin/modules/test/managmentDataProvider.test.d.ts +1 -0
- package/bin/modules/test/managmentDataProvider.test.js +40 -0
- package/bin/modules/test/managmentDataProvider.test.js.map +1 -0
- package/bin/modules/test/pipelineDataProvider.test.d.ts +1 -0
- package/bin/modules/test/pipelineDataProvider.test.js +62 -0
- package/bin/modules/test/pipelineDataProvider.test.js.map +1 -0
- package/bin/modules/test/testDataProvider.test.d.ts +1 -0
- package/bin/modules/test/testDataProvider.test.js +103 -0
- package/bin/modules/test/testDataProvider.test.js.map +1 -0
- package/bin/modules/test/ticketsDataProvider.test.d.ts +1 -0
- package/bin/modules/test/ticketsDataProvider.test.js +103 -0
- package/bin/modules/test/ticketsDataProvider.test.js.map +1 -0
- package/bin/utils/logger.d.ts +3 -0
- package/bin/utils/logger.js +33 -0
- package/bin/utils/logger.js.map +1 -0
- package/enviroment.d.ts +12 -12
- package/package.json +53 -53
- package/src/helpers/helper.ts +117 -117
- package/src/helpers/tfs.ts +92 -92
- package/src/index.ts +36 -36
- package/src/models/tfs-data.ts +136 -136
- package/src/modules/GitDataProvider.ts +446 -446
- package/src/modules/MangementDataProvider.ts +59 -59
- package/src/modules/PipelinesDataProvider.ts +142 -142
- package/src/modules/TestDataProvider.ts +423 -423
- package/src/modules/TicketsDataProvider.ts +435 -435
- package/src/modules/test/gitDataProvider.test.ts +207 -207
- package/src/modules/test/managmentDataProvider.test.ts +33 -33
- package/src/modules/test/pipelineDataProvider.test.ts +79 -79
- package/src/modules/test/testDataProvider.test.ts +139 -139
- package/src/modules/test/ticketsDataProvider.test.ts +138 -138
- package/src/utils/logger.ts +37 -37
- package/tsconfig.json +27 -27
|
@@ -1,446 +1,446 @@
|
|
|
1
|
-
import { TFSServices } from "../helpers/tfs";
|
|
2
|
-
import TicketsDataProvider from "./TicketsDataProvider";
|
|
3
|
-
import logger from "../utils/logger";
|
|
4
|
-
export default class GitDataProvider {
|
|
5
|
-
orgUrl: string = "";
|
|
6
|
-
token: string = "";
|
|
7
|
-
ticketsDataProvider: TicketsDataProvider;
|
|
8
|
-
|
|
9
|
-
constructor(orgUrl: string, token: string) {
|
|
10
|
-
this.orgUrl = orgUrl;
|
|
11
|
-
this.token = token;
|
|
12
|
-
this.ticketsDataProvider = new TicketsDataProvider(
|
|
13
|
-
this.orgUrl,
|
|
14
|
-
this.token,
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
async GetTeamProjectGitReposList(
|
|
18
|
-
teamProject: string
|
|
19
|
-
) {
|
|
20
|
-
logger.debug(`fetching repos list for team project - ${teamProject}`);
|
|
21
|
-
let url = `${this.orgUrl}/${teamProject}/_apis/git/repositories`;
|
|
22
|
-
return TFSServices.getItemContent(url, this.token, "get");
|
|
23
|
-
} //GetGitRepoFromPrId
|
|
24
|
-
|
|
25
|
-
async GetGitRepoFromRepoId(
|
|
26
|
-
repoId: string
|
|
27
|
-
) {
|
|
28
|
-
logger.debug(`fetching repo data by id - ${repoId}`);
|
|
29
|
-
let url = `${this.orgUrl}_apis/git/repositories/${repoId}`;
|
|
30
|
-
return TFSServices.getItemContent(url, this.token, "get");
|
|
31
|
-
} //GetGitRepoFromPrId
|
|
32
|
-
|
|
33
|
-
async GetJsonFileFromGitRepo(
|
|
34
|
-
projectName: string,
|
|
35
|
-
repoName: string,
|
|
36
|
-
filePath: string
|
|
37
|
-
) {
|
|
38
|
-
let url = `${this.orgUrl}${projectName}/_apis/git/repositories/${repoName}/items?path=${filePath}&includeContent=true`;
|
|
39
|
-
let res = await TFSServices.getItemContent(url, this.token, "get");
|
|
40
|
-
let jsonObject = JSON.parse(res.content);
|
|
41
|
-
return jsonObject;
|
|
42
|
-
} //GetJsonFileFromGitRepo
|
|
43
|
-
|
|
44
|
-
async GetGitRepoFromPrId(
|
|
45
|
-
pullRequestId: number
|
|
46
|
-
) {
|
|
47
|
-
let url = `${this.orgUrl}_apis/git/pullrequests/${pullRequestId}`;
|
|
48
|
-
let res = await TFSServices.getItemContent(url, this.token, "get");
|
|
49
|
-
return res;
|
|
50
|
-
} //GetGitRepoFromPrId
|
|
51
|
-
|
|
52
|
-
async GetPullRequestCommits(
|
|
53
|
-
repositoryId: string,
|
|
54
|
-
pullRequestId: number
|
|
55
|
-
) {
|
|
56
|
-
let url = `${this.orgUrl}_apis/git/repositories/${repositoryId}/pullRequests/${pullRequestId}/commits`;
|
|
57
|
-
let res = await TFSServices.getItemContent(url, this.token, "get");
|
|
58
|
-
return res;
|
|
59
|
-
} //GetGitRepoFromPrId
|
|
60
|
-
|
|
61
|
-
async GetPullRequestsLinkedItemsInCommitRange(
|
|
62
|
-
projectId: string,
|
|
63
|
-
repositoryId: string,
|
|
64
|
-
commitRangeArray: any
|
|
65
|
-
) {
|
|
66
|
-
let pullRequestsFilteredArray: any = [];
|
|
67
|
-
let ChangeSetsArray: any = [];
|
|
68
|
-
//get all pr's in git repo
|
|
69
|
-
let url = `${this.orgUrl}${projectId}/_apis/git/repositories/${repositoryId}/pullrequests?status=completed&includeLinks=true&$top=2000}`;
|
|
70
|
-
logger.debug(`request url: ${url}`);
|
|
71
|
-
let pullRequestsArray = await TFSServices.getItemContent(
|
|
72
|
-
url,
|
|
73
|
-
this.token,
|
|
74
|
-
"get"
|
|
75
|
-
);
|
|
76
|
-
logger.info(
|
|
77
|
-
`got ${pullRequestsArray.count} pullrequests for repo: ${repositoryId}`
|
|
78
|
-
);
|
|
79
|
-
//iterate commit list to filter relavant pullrequests
|
|
80
|
-
pullRequestsArray.value.forEach((pr: any) => {
|
|
81
|
-
commitRangeArray.value.forEach((commit: any) => {
|
|
82
|
-
if (pr.lastMergeCommit.commitId == commit.commitId) {
|
|
83
|
-
pullRequestsFilteredArray.push(pr);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
logger.info(
|
|
88
|
-
`filtered in commit range ${pullRequestsFilteredArray.length} pullrequests for repo: ${repositoryId}`
|
|
89
|
-
);
|
|
90
|
-
//extract linked items and append them to result
|
|
91
|
-
await Promise.all(
|
|
92
|
-
pullRequestsFilteredArray.map(async (pr: any) => {
|
|
93
|
-
let linkedItems: any = {};
|
|
94
|
-
try {
|
|
95
|
-
if (pr._links.workItems.href) {
|
|
96
|
-
//get workitems linked to pr
|
|
97
|
-
let url: string = pr._links.workItems.href;
|
|
98
|
-
linkedItems = await TFSServices.getItemContent(
|
|
99
|
-
url,
|
|
100
|
-
this.token,
|
|
101
|
-
"get"
|
|
102
|
-
);
|
|
103
|
-
logger.info(
|
|
104
|
-
`got ${linkedItems.count} items linked to pr ${pr.pullRequestId}`
|
|
105
|
-
);
|
|
106
|
-
await Promise.all(
|
|
107
|
-
linkedItems.value.map(async (item: any) => {
|
|
108
|
-
let populatedItem = await this.ticketsDataProvider.GetWorkItem(
|
|
109
|
-
projectId,
|
|
110
|
-
item.id
|
|
111
|
-
);
|
|
112
|
-
let changeSet: any = {
|
|
113
|
-
workItem: populatedItem,
|
|
114
|
-
pullrequest: pr,
|
|
115
|
-
};
|
|
116
|
-
ChangeSetsArray.push(changeSet);
|
|
117
|
-
})
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
} catch (error) {
|
|
121
|
-
logger.error(error);
|
|
122
|
-
}
|
|
123
|
-
})
|
|
124
|
-
);
|
|
125
|
-
return ChangeSetsArray;
|
|
126
|
-
} //GetPullRequestsInCommitRange
|
|
127
|
-
|
|
128
|
-
async GetItemsInCommitRange(
|
|
129
|
-
projectId: string,
|
|
130
|
-
repositoryId: string,
|
|
131
|
-
commitRange:any
|
|
132
|
-
) {
|
|
133
|
-
//get all items linked to commits
|
|
134
|
-
let res: any = [];
|
|
135
|
-
let commitChangesArray: any = [];
|
|
136
|
-
//extract linked items and append them to result
|
|
137
|
-
for (const commit of commitRange.value) {
|
|
138
|
-
if (commit.workItems) {
|
|
139
|
-
for (const wi of commit.workItems) {
|
|
140
|
-
let populatedItem = await this.ticketsDataProvider.GetWorkItem(
|
|
141
|
-
projectId,
|
|
142
|
-
wi.id
|
|
143
|
-
);
|
|
144
|
-
let changeSet: any = { workItem: populatedItem, commit: commit };
|
|
145
|
-
commitChangesArray.push(changeSet);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
//get all items and pr data from pr's in commit range - using the above function
|
|
150
|
-
let pullRequestsChangesArray =
|
|
151
|
-
await this.GetPullRequestsLinkedItemsInCommitRange(
|
|
152
|
-
projectId,
|
|
153
|
-
repositoryId,
|
|
154
|
-
commitRange
|
|
155
|
-
);
|
|
156
|
-
//merge commit links with pr links
|
|
157
|
-
logger.info(`got ${pullRequestsChangesArray.length} items from pr's and`);
|
|
158
|
-
res = [...commitChangesArray, ...pullRequestsChangesArray];
|
|
159
|
-
let workItemIds :any = []
|
|
160
|
-
for (let index = 0; index < res.length; index++) {
|
|
161
|
-
if (workItemIds.includes(res[index].workItem.id)){
|
|
162
|
-
res.splice(index, 1);
|
|
163
|
-
index--;
|
|
164
|
-
}
|
|
165
|
-
else{
|
|
166
|
-
workItemIds.push(res[index].workItem.id)
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return res;
|
|
170
|
-
} //GetItemsInCommitRange
|
|
171
|
-
|
|
172
|
-
async GetPullRequestsInCommitRangeWithoutLinkedItems(
|
|
173
|
-
projectId: string,
|
|
174
|
-
repositoryId: string,
|
|
175
|
-
commitRangeArray: any
|
|
176
|
-
) {
|
|
177
|
-
let pullRequestsFilteredArray: any[] = [];
|
|
178
|
-
|
|
179
|
-
// Extract the organization name from orgUrl
|
|
180
|
-
let orgName = this.orgUrl.split('/').filter(Boolean).pop();
|
|
181
|
-
|
|
182
|
-
// Get all PRs in the git repo
|
|
183
|
-
let url = `${this.orgUrl}${projectId}/_apis/git/repositories/${repositoryId}/pullrequests?status=completed&includeLinks=true&$top=2000}`;
|
|
184
|
-
logger.debug(`request url: ${url}`);
|
|
185
|
-
let pullRequestsArray = await TFSServices.getItemContent(
|
|
186
|
-
url,
|
|
187
|
-
this.token,
|
|
188
|
-
"get"
|
|
189
|
-
);
|
|
190
|
-
logger.info(
|
|
191
|
-
`got ${pullRequestsArray.count} pullrequests for repo: ${repositoryId}`
|
|
192
|
-
);
|
|
193
|
-
|
|
194
|
-
// Iterate commit list to filter relevant pull requests
|
|
195
|
-
pullRequestsArray.value.forEach((pr: any) => {
|
|
196
|
-
commitRangeArray.value.forEach((commit: any) => {
|
|
197
|
-
if (pr.lastMergeCommit.commitId == commit.commitId) {
|
|
198
|
-
// Construct the pull request URL
|
|
199
|
-
const prUrl = `https://dev.azure.com/${orgName}/${projectId}/_git/${repositoryId}/pullrequest/${pr.pullRequestId}`;
|
|
200
|
-
|
|
201
|
-
// Extract only the desired properties from the PR
|
|
202
|
-
const prFilteredData = {
|
|
203
|
-
pullRequestId: pr.pullRequestId,
|
|
204
|
-
createdBy: pr.createdBy.displayName,
|
|
205
|
-
creationDate: pr.creationDate,
|
|
206
|
-
closedDate: pr.closedDate,
|
|
207
|
-
title: pr.title,
|
|
208
|
-
description: pr.description,
|
|
209
|
-
url: prUrl // Use the constructed URL here
|
|
210
|
-
};
|
|
211
|
-
pullRequestsFilteredArray.push(prFilteredData);
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
logger.info(
|
|
216
|
-
`filtered in commit range ${pullRequestsFilteredArray.length} pullrequests for repo: ${repositoryId}`
|
|
217
|
-
);
|
|
218
|
-
|
|
219
|
-
return pullRequestsFilteredArray;
|
|
220
|
-
} // GetPullRequestsInCommitRangeWithoutLinkedItems
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
async GetCommitByCommitId(
|
|
224
|
-
projectId: string,
|
|
225
|
-
repositoryId: string,
|
|
226
|
-
commitSha: string
|
|
227
|
-
) {
|
|
228
|
-
let url = `${this.orgUrl}${projectId}/_apis/git/repositories/${repositoryId}/commits/${commitSha}`;
|
|
229
|
-
return TFSServices.getItemContent(url, this.token, "get");
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
async GetCommitForPipeline(
|
|
233
|
-
projectId: string,
|
|
234
|
-
buildId: number
|
|
235
|
-
) {
|
|
236
|
-
let url = `${this.orgUrl}${projectId}/_apis/build/builds/${buildId}`;
|
|
237
|
-
let res = await TFSServices.getItemContent(url, this.token, "get");
|
|
238
|
-
return res.sourceVersion;
|
|
239
|
-
} //GetCommitForPipeline
|
|
240
|
-
|
|
241
|
-
async GetItemsForPipelinesRange(
|
|
242
|
-
projectId: string,
|
|
243
|
-
fromBuildId: number,
|
|
244
|
-
toBuildId: number
|
|
245
|
-
) {
|
|
246
|
-
let linkedItemsArray: any = [];
|
|
247
|
-
let url = `${this.orgUrl}${projectId}/_apis/build/workitems?fromBuildId=${fromBuildId}&toBuildId=${toBuildId}&$top=2000`;
|
|
248
|
-
let res = await TFSServices.getItemContent(url, this.token, "get");
|
|
249
|
-
logger.info(
|
|
250
|
-
`recieved ${res.count} items in build range ${fromBuildId}-${toBuildId}`
|
|
251
|
-
);
|
|
252
|
-
await Promise.all(
|
|
253
|
-
res.value.map(async (wi: any) => {
|
|
254
|
-
let populatedItem = await this.ticketsDataProvider.GetWorkItem(
|
|
255
|
-
projectId,
|
|
256
|
-
wi.id
|
|
257
|
-
);
|
|
258
|
-
let changeSet: any = { workItem: populatedItem, build: toBuildId };
|
|
259
|
-
linkedItemsArray.push(changeSet);
|
|
260
|
-
})
|
|
261
|
-
);
|
|
262
|
-
return linkedItemsArray;
|
|
263
|
-
} //GetCommitForPipeline
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
async GetCommitsInDateRange(
|
|
267
|
-
projectId: string,
|
|
268
|
-
repositoryId: string,
|
|
269
|
-
fromDate: string,
|
|
270
|
-
toDate: string,
|
|
271
|
-
branchName?: string
|
|
272
|
-
) {
|
|
273
|
-
let url:string
|
|
274
|
-
if (typeof branchName !== 'undefined') {
|
|
275
|
-
url = `${this.orgUrl}${projectId}/_apis/git/repositories/${repositoryId}/commits?searchCriteria.fromDate=${fromDate}&searchCriteria.toDate=${toDate}&searchCriteria.includeWorkItems=true&searchCriteria.$top=2000&searchCriteria.itemVersion.version=${branchName}`;
|
|
276
|
-
}
|
|
277
|
-
else{
|
|
278
|
-
url = `${this.orgUrl}${projectId}/_apis/git/repositories/${repositoryId}/commits?searchCriteria.fromDate=${fromDate}&searchCriteria.toDate=${toDate}&searchCriteria.includeWorkItems=true&searchCriteria.$top=2000`;
|
|
279
|
-
}
|
|
280
|
-
return TFSServices.getItemContent(url, this.token, "get");
|
|
281
|
-
} //GetCommitsInDateRange
|
|
282
|
-
|
|
283
|
-
async GetCommitsInCommitRange(
|
|
284
|
-
projectId: string,
|
|
285
|
-
repositoryId: string,
|
|
286
|
-
fromSha: string,
|
|
287
|
-
toSha: string
|
|
288
|
-
) {
|
|
289
|
-
let url = `${this.orgUrl}${projectId}/_apis/git/repositories/${repositoryId}/commits?searchCriteria.fromCommitId=${fromSha}&searchCriteria.toCommitId=${toSha}&searchCriteria.includeWorkItems=true&searchCriteria.$top=2000`;
|
|
290
|
-
return TFSServices.getItemContent(url, this.token, "get");
|
|
291
|
-
} //GetCommitsInCommitRange doesen't work!!!
|
|
292
|
-
|
|
293
|
-
async CreatePullRequestComment(
|
|
294
|
-
projectName: string,
|
|
295
|
-
repoID: string,
|
|
296
|
-
pullRequestID: number,
|
|
297
|
-
threads: any
|
|
298
|
-
) {
|
|
299
|
-
let url: string = `${this.orgUrl}${projectName}/_apis/git/repositories/${repoID}/pullRequests/${pullRequestID}/threads?api-version=5.0`;
|
|
300
|
-
let res: any = await TFSServices.getItemContent(
|
|
301
|
-
url,
|
|
302
|
-
this.token,
|
|
303
|
-
"post",
|
|
304
|
-
threads,
|
|
305
|
-
null
|
|
306
|
-
);
|
|
307
|
-
return res;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
async GetPullRequestComments(
|
|
311
|
-
projectName: string,
|
|
312
|
-
repoID: string,
|
|
313
|
-
pullRequestID: number
|
|
314
|
-
) {
|
|
315
|
-
let url: string = `${this.orgUrl}${projectName}/_apis/git/repositories/${repoID}/pullRequests/${pullRequestID}/threads`;
|
|
316
|
-
return TFSServices.getItemContent(
|
|
317
|
-
url,
|
|
318
|
-
this.token,
|
|
319
|
-
"get",
|
|
320
|
-
null,
|
|
321
|
-
null
|
|
322
|
-
);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
async GetCommitsForRepo(
|
|
326
|
-
projectName: string,
|
|
327
|
-
repoID: string,
|
|
328
|
-
branchName?: string
|
|
329
|
-
){
|
|
330
|
-
let url: string
|
|
331
|
-
if (typeof branchName !== 'undefined') {
|
|
332
|
-
url = `${this.orgUrl}${projectName}/_apis/git/repositories/${repoID}/commits?searchCriteria.$top=2000&searchCriteria.itemVersion.version=${branchName}`
|
|
333
|
-
}
|
|
334
|
-
else{
|
|
335
|
-
url = `${this.orgUrl}${projectName}/_apis/git/repositories/${repoID}/commits?searchCriteria.$top=2000`
|
|
336
|
-
}
|
|
337
|
-
let res:any = await TFSServices.getItemContent(
|
|
338
|
-
url,
|
|
339
|
-
this.token,
|
|
340
|
-
"get",
|
|
341
|
-
null,
|
|
342
|
-
null
|
|
343
|
-
);
|
|
344
|
-
return res;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
async GetPullRequestsForRepo(
|
|
348
|
-
projectName: string,
|
|
349
|
-
repoID: string
|
|
350
|
-
){
|
|
351
|
-
let url: string =
|
|
352
|
-
`${this.orgUrl}${projectName}/_apis/git/repositories/${repoID}/pullrequests?status=completed&includeLinks=true&$top=2000}`;
|
|
353
|
-
|
|
354
|
-
let res:any = await TFSServices.getItemContent(
|
|
355
|
-
url,
|
|
356
|
-
this.token,
|
|
357
|
-
"get",
|
|
358
|
-
null,
|
|
359
|
-
null
|
|
360
|
-
);
|
|
361
|
-
return res;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
async GetItemsInPullRequestRange(
|
|
366
|
-
projectId: string,
|
|
367
|
-
repositoryId: string,
|
|
368
|
-
pullRequestIDs: any,
|
|
369
|
-
) {
|
|
370
|
-
let pullRequestsFilteredArray: any = [];
|
|
371
|
-
let ChangeSetsArray: any = [];
|
|
372
|
-
//get all pr's in git repo
|
|
373
|
-
let url = `${this.orgUrl}${projectId}/_apis/git/repositories/${repositoryId}/pullrequests?status=completed&includeLinks=true&$top=2000}`;
|
|
374
|
-
logger.debug(`request url: ${url}`);
|
|
375
|
-
let pullRequestsArray = await TFSServices.getItemContent(
|
|
376
|
-
url,
|
|
377
|
-
this.token,
|
|
378
|
-
"get"
|
|
379
|
-
);
|
|
380
|
-
logger.info(
|
|
381
|
-
`got ${pullRequestsArray.count} pullrequests for repo: ${repositoryId}`
|
|
382
|
-
);
|
|
383
|
-
//iterate commit list to filter relavant pullrequests
|
|
384
|
-
pullRequestsArray.value.forEach((pr: any) => {
|
|
385
|
-
pullRequestIDs.forEach((prId: any) => {
|
|
386
|
-
if (prId == pr.pullRequestId) {
|
|
387
|
-
pullRequestsFilteredArray.push(pr);
|
|
388
|
-
}
|
|
389
|
-
});
|
|
390
|
-
});
|
|
391
|
-
logger.info(
|
|
392
|
-
`filtered in prId range ${pullRequestsFilteredArray.length} pullrequests for repo: ${repositoryId}`
|
|
393
|
-
);
|
|
394
|
-
//extract linked items and append them to result
|
|
395
|
-
await Promise.all(
|
|
396
|
-
pullRequestsFilteredArray.map(async (pr: any) => {
|
|
397
|
-
let linkedItems: any = {};
|
|
398
|
-
try {
|
|
399
|
-
if (pr._links.workItems.href) {
|
|
400
|
-
//get workitems linked to pr
|
|
401
|
-
let url: string = pr._links.workItems.href;
|
|
402
|
-
linkedItems = await TFSServices.getItemContent(
|
|
403
|
-
url,
|
|
404
|
-
this.token,
|
|
405
|
-
"get"
|
|
406
|
-
);
|
|
407
|
-
logger.info(
|
|
408
|
-
`got ${linkedItems.count} items linked to pr ${pr.pullRequestId}`
|
|
409
|
-
);
|
|
410
|
-
await Promise.all(
|
|
411
|
-
linkedItems.value.map(async (item: any) => {
|
|
412
|
-
let populatedItem = await this.ticketsDataProvider.GetWorkItem(
|
|
413
|
-
projectId,
|
|
414
|
-
item.id
|
|
415
|
-
);
|
|
416
|
-
let changeSet: any = {
|
|
417
|
-
workItem: populatedItem,
|
|
418
|
-
pullrequest: pr,
|
|
419
|
-
};
|
|
420
|
-
ChangeSetsArray.push(changeSet);
|
|
421
|
-
})
|
|
422
|
-
);
|
|
423
|
-
}
|
|
424
|
-
} catch (error) {
|
|
425
|
-
logger.error(error);
|
|
426
|
-
}
|
|
427
|
-
})
|
|
428
|
-
);
|
|
429
|
-
return ChangeSetsArray;
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
async GetRepoBranches(
|
|
433
|
-
projectName: string,
|
|
434
|
-
repoID: string
|
|
435
|
-
){
|
|
436
|
-
let url: string = `${this.orgUrl}${projectName}/_apis/git/repositories/${repoID}/refs?searchCriteria.$top=1000&filter=heads`
|
|
437
|
-
let res:any = await TFSServices.getItemContent(
|
|
438
|
-
url,
|
|
439
|
-
this.token,
|
|
440
|
-
"get",
|
|
441
|
-
null,
|
|
442
|
-
null
|
|
443
|
-
);
|
|
444
|
-
return res;
|
|
445
|
-
}
|
|
446
|
-
}
|
|
1
|
+
import { TFSServices } from "../helpers/tfs";
|
|
2
|
+
import TicketsDataProvider from "./TicketsDataProvider";
|
|
3
|
+
import logger from "../utils/logger";
|
|
4
|
+
export default class GitDataProvider {
|
|
5
|
+
orgUrl: string = "";
|
|
6
|
+
token: string = "";
|
|
7
|
+
ticketsDataProvider: TicketsDataProvider;
|
|
8
|
+
|
|
9
|
+
constructor(orgUrl: string, token: string) {
|
|
10
|
+
this.orgUrl = orgUrl;
|
|
11
|
+
this.token = token;
|
|
12
|
+
this.ticketsDataProvider = new TicketsDataProvider(
|
|
13
|
+
this.orgUrl,
|
|
14
|
+
this.token,
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
async GetTeamProjectGitReposList(
|
|
18
|
+
teamProject: string
|
|
19
|
+
) {
|
|
20
|
+
logger.debug(`fetching repos list for team project - ${teamProject}`);
|
|
21
|
+
let url = `${this.orgUrl}/${teamProject}/_apis/git/repositories`;
|
|
22
|
+
return TFSServices.getItemContent(url, this.token, "get");
|
|
23
|
+
} //GetGitRepoFromPrId
|
|
24
|
+
|
|
25
|
+
async GetGitRepoFromRepoId(
|
|
26
|
+
repoId: string
|
|
27
|
+
) {
|
|
28
|
+
logger.debug(`fetching repo data by id - ${repoId}`);
|
|
29
|
+
let url = `${this.orgUrl}_apis/git/repositories/${repoId}`;
|
|
30
|
+
return TFSServices.getItemContent(url, this.token, "get");
|
|
31
|
+
} //GetGitRepoFromPrId
|
|
32
|
+
|
|
33
|
+
async GetJsonFileFromGitRepo(
|
|
34
|
+
projectName: string,
|
|
35
|
+
repoName: string,
|
|
36
|
+
filePath: string
|
|
37
|
+
) {
|
|
38
|
+
let url = `${this.orgUrl}${projectName}/_apis/git/repositories/${repoName}/items?path=${filePath}&includeContent=true`;
|
|
39
|
+
let res = await TFSServices.getItemContent(url, this.token, "get");
|
|
40
|
+
let jsonObject = JSON.parse(res.content);
|
|
41
|
+
return jsonObject;
|
|
42
|
+
} //GetJsonFileFromGitRepo
|
|
43
|
+
|
|
44
|
+
async GetGitRepoFromPrId(
|
|
45
|
+
pullRequestId: number
|
|
46
|
+
) {
|
|
47
|
+
let url = `${this.orgUrl}_apis/git/pullrequests/${pullRequestId}`;
|
|
48
|
+
let res = await TFSServices.getItemContent(url, this.token, "get");
|
|
49
|
+
return res;
|
|
50
|
+
} //GetGitRepoFromPrId
|
|
51
|
+
|
|
52
|
+
async GetPullRequestCommits(
|
|
53
|
+
repositoryId: string,
|
|
54
|
+
pullRequestId: number
|
|
55
|
+
) {
|
|
56
|
+
let url = `${this.orgUrl}_apis/git/repositories/${repositoryId}/pullRequests/${pullRequestId}/commits`;
|
|
57
|
+
let res = await TFSServices.getItemContent(url, this.token, "get");
|
|
58
|
+
return res;
|
|
59
|
+
} //GetGitRepoFromPrId
|
|
60
|
+
|
|
61
|
+
async GetPullRequestsLinkedItemsInCommitRange(
|
|
62
|
+
projectId: string,
|
|
63
|
+
repositoryId: string,
|
|
64
|
+
commitRangeArray: any
|
|
65
|
+
) {
|
|
66
|
+
let pullRequestsFilteredArray: any = [];
|
|
67
|
+
let ChangeSetsArray: any = [];
|
|
68
|
+
//get all pr's in git repo
|
|
69
|
+
let url = `${this.orgUrl}${projectId}/_apis/git/repositories/${repositoryId}/pullrequests?status=completed&includeLinks=true&$top=2000}`;
|
|
70
|
+
logger.debug(`request url: ${url}`);
|
|
71
|
+
let pullRequestsArray = await TFSServices.getItemContent(
|
|
72
|
+
url,
|
|
73
|
+
this.token,
|
|
74
|
+
"get"
|
|
75
|
+
);
|
|
76
|
+
logger.info(
|
|
77
|
+
`got ${pullRequestsArray.count} pullrequests for repo: ${repositoryId}`
|
|
78
|
+
);
|
|
79
|
+
//iterate commit list to filter relavant pullrequests
|
|
80
|
+
pullRequestsArray.value.forEach((pr: any) => {
|
|
81
|
+
commitRangeArray.value.forEach((commit: any) => {
|
|
82
|
+
if (pr.lastMergeCommit.commitId == commit.commitId) {
|
|
83
|
+
pullRequestsFilteredArray.push(pr);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
logger.info(
|
|
88
|
+
`filtered in commit range ${pullRequestsFilteredArray.length} pullrequests for repo: ${repositoryId}`
|
|
89
|
+
);
|
|
90
|
+
//extract linked items and append them to result
|
|
91
|
+
await Promise.all(
|
|
92
|
+
pullRequestsFilteredArray.map(async (pr: any) => {
|
|
93
|
+
let linkedItems: any = {};
|
|
94
|
+
try {
|
|
95
|
+
if (pr._links.workItems.href) {
|
|
96
|
+
//get workitems linked to pr
|
|
97
|
+
let url: string = pr._links.workItems.href;
|
|
98
|
+
linkedItems = await TFSServices.getItemContent(
|
|
99
|
+
url,
|
|
100
|
+
this.token,
|
|
101
|
+
"get"
|
|
102
|
+
);
|
|
103
|
+
logger.info(
|
|
104
|
+
`got ${linkedItems.count} items linked to pr ${pr.pullRequestId}`
|
|
105
|
+
);
|
|
106
|
+
await Promise.all(
|
|
107
|
+
linkedItems.value.map(async (item: any) => {
|
|
108
|
+
let populatedItem = await this.ticketsDataProvider.GetWorkItem(
|
|
109
|
+
projectId,
|
|
110
|
+
item.id
|
|
111
|
+
);
|
|
112
|
+
let changeSet: any = {
|
|
113
|
+
workItem: populatedItem,
|
|
114
|
+
pullrequest: pr,
|
|
115
|
+
};
|
|
116
|
+
ChangeSetsArray.push(changeSet);
|
|
117
|
+
})
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
} catch (error) {
|
|
121
|
+
logger.error(error);
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
);
|
|
125
|
+
return ChangeSetsArray;
|
|
126
|
+
} //GetPullRequestsInCommitRange
|
|
127
|
+
|
|
128
|
+
async GetItemsInCommitRange(
|
|
129
|
+
projectId: string,
|
|
130
|
+
repositoryId: string,
|
|
131
|
+
commitRange:any
|
|
132
|
+
) {
|
|
133
|
+
//get all items linked to commits
|
|
134
|
+
let res: any = [];
|
|
135
|
+
let commitChangesArray: any = [];
|
|
136
|
+
//extract linked items and append them to result
|
|
137
|
+
for (const commit of commitRange.value) {
|
|
138
|
+
if (commit.workItems) {
|
|
139
|
+
for (const wi of commit.workItems) {
|
|
140
|
+
let populatedItem = await this.ticketsDataProvider.GetWorkItem(
|
|
141
|
+
projectId,
|
|
142
|
+
wi.id
|
|
143
|
+
);
|
|
144
|
+
let changeSet: any = { workItem: populatedItem, commit: commit };
|
|
145
|
+
commitChangesArray.push(changeSet);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
//get all items and pr data from pr's in commit range - using the above function
|
|
150
|
+
let pullRequestsChangesArray =
|
|
151
|
+
await this.GetPullRequestsLinkedItemsInCommitRange(
|
|
152
|
+
projectId,
|
|
153
|
+
repositoryId,
|
|
154
|
+
commitRange
|
|
155
|
+
);
|
|
156
|
+
//merge commit links with pr links
|
|
157
|
+
logger.info(`got ${pullRequestsChangesArray.length} items from pr's and`);
|
|
158
|
+
res = [...commitChangesArray, ...pullRequestsChangesArray];
|
|
159
|
+
let workItemIds :any = []
|
|
160
|
+
for (let index = 0; index < res.length; index++) {
|
|
161
|
+
if (workItemIds.includes(res[index].workItem.id)){
|
|
162
|
+
res.splice(index, 1);
|
|
163
|
+
index--;
|
|
164
|
+
}
|
|
165
|
+
else{
|
|
166
|
+
workItemIds.push(res[index].workItem.id)
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return res;
|
|
170
|
+
} //GetItemsInCommitRange
|
|
171
|
+
|
|
172
|
+
async GetPullRequestsInCommitRangeWithoutLinkedItems(
|
|
173
|
+
projectId: string,
|
|
174
|
+
repositoryId: string,
|
|
175
|
+
commitRangeArray: any
|
|
176
|
+
) {
|
|
177
|
+
let pullRequestsFilteredArray: any[] = [];
|
|
178
|
+
|
|
179
|
+
// Extract the organization name from orgUrl
|
|
180
|
+
let orgName = this.orgUrl.split('/').filter(Boolean).pop();
|
|
181
|
+
|
|
182
|
+
// Get all PRs in the git repo
|
|
183
|
+
let url = `${this.orgUrl}${projectId}/_apis/git/repositories/${repositoryId}/pullrequests?status=completed&includeLinks=true&$top=2000}`;
|
|
184
|
+
logger.debug(`request url: ${url}`);
|
|
185
|
+
let pullRequestsArray = await TFSServices.getItemContent(
|
|
186
|
+
url,
|
|
187
|
+
this.token,
|
|
188
|
+
"get"
|
|
189
|
+
);
|
|
190
|
+
logger.info(
|
|
191
|
+
`got ${pullRequestsArray.count} pullrequests for repo: ${repositoryId}`
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
// Iterate commit list to filter relevant pull requests
|
|
195
|
+
pullRequestsArray.value.forEach((pr: any) => {
|
|
196
|
+
commitRangeArray.value.forEach((commit: any) => {
|
|
197
|
+
if (pr.lastMergeCommit.commitId == commit.commitId) {
|
|
198
|
+
// Construct the pull request URL
|
|
199
|
+
const prUrl = `https://dev.azure.com/${orgName}/${projectId}/_git/${repositoryId}/pullrequest/${pr.pullRequestId}`;
|
|
200
|
+
|
|
201
|
+
// Extract only the desired properties from the PR
|
|
202
|
+
const prFilteredData = {
|
|
203
|
+
pullRequestId: pr.pullRequestId,
|
|
204
|
+
createdBy: pr.createdBy.displayName,
|
|
205
|
+
creationDate: pr.creationDate,
|
|
206
|
+
closedDate: pr.closedDate,
|
|
207
|
+
title: pr.title,
|
|
208
|
+
description: pr.description,
|
|
209
|
+
url: prUrl // Use the constructed URL here
|
|
210
|
+
};
|
|
211
|
+
pullRequestsFilteredArray.push(prFilteredData);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
logger.info(
|
|
216
|
+
`filtered in commit range ${pullRequestsFilteredArray.length} pullrequests for repo: ${repositoryId}`
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
return pullRequestsFilteredArray;
|
|
220
|
+
} // GetPullRequestsInCommitRangeWithoutLinkedItems
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
async GetCommitByCommitId(
|
|
224
|
+
projectId: string,
|
|
225
|
+
repositoryId: string,
|
|
226
|
+
commitSha: string
|
|
227
|
+
) {
|
|
228
|
+
let url = `${this.orgUrl}${projectId}/_apis/git/repositories/${repositoryId}/commits/${commitSha}`;
|
|
229
|
+
return TFSServices.getItemContent(url, this.token, "get");
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async GetCommitForPipeline(
|
|
233
|
+
projectId: string,
|
|
234
|
+
buildId: number
|
|
235
|
+
) {
|
|
236
|
+
let url = `${this.orgUrl}${projectId}/_apis/build/builds/${buildId}`;
|
|
237
|
+
let res = await TFSServices.getItemContent(url, this.token, "get");
|
|
238
|
+
return res.sourceVersion;
|
|
239
|
+
} //GetCommitForPipeline
|
|
240
|
+
|
|
241
|
+
async GetItemsForPipelinesRange(
|
|
242
|
+
projectId: string,
|
|
243
|
+
fromBuildId: number,
|
|
244
|
+
toBuildId: number
|
|
245
|
+
) {
|
|
246
|
+
let linkedItemsArray: any = [];
|
|
247
|
+
let url = `${this.orgUrl}${projectId}/_apis/build/workitems?fromBuildId=${fromBuildId}&toBuildId=${toBuildId}&$top=2000`;
|
|
248
|
+
let res = await TFSServices.getItemContent(url, this.token, "get");
|
|
249
|
+
logger.info(
|
|
250
|
+
`recieved ${res.count} items in build range ${fromBuildId}-${toBuildId}`
|
|
251
|
+
);
|
|
252
|
+
await Promise.all(
|
|
253
|
+
res.value.map(async (wi: any) => {
|
|
254
|
+
let populatedItem = await this.ticketsDataProvider.GetWorkItem(
|
|
255
|
+
projectId,
|
|
256
|
+
wi.id
|
|
257
|
+
);
|
|
258
|
+
let changeSet: any = { workItem: populatedItem, build: toBuildId };
|
|
259
|
+
linkedItemsArray.push(changeSet);
|
|
260
|
+
})
|
|
261
|
+
);
|
|
262
|
+
return linkedItemsArray;
|
|
263
|
+
} //GetCommitForPipeline
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
async GetCommitsInDateRange(
|
|
267
|
+
projectId: string,
|
|
268
|
+
repositoryId: string,
|
|
269
|
+
fromDate: string,
|
|
270
|
+
toDate: string,
|
|
271
|
+
branchName?: string
|
|
272
|
+
) {
|
|
273
|
+
let url:string
|
|
274
|
+
if (typeof branchName !== 'undefined') {
|
|
275
|
+
url = `${this.orgUrl}${projectId}/_apis/git/repositories/${repositoryId}/commits?searchCriteria.fromDate=${fromDate}&searchCriteria.toDate=${toDate}&searchCriteria.includeWorkItems=true&searchCriteria.$top=2000&searchCriteria.itemVersion.version=${branchName}`;
|
|
276
|
+
}
|
|
277
|
+
else{
|
|
278
|
+
url = `${this.orgUrl}${projectId}/_apis/git/repositories/${repositoryId}/commits?searchCriteria.fromDate=${fromDate}&searchCriteria.toDate=${toDate}&searchCriteria.includeWorkItems=true&searchCriteria.$top=2000`;
|
|
279
|
+
}
|
|
280
|
+
return TFSServices.getItemContent(url, this.token, "get");
|
|
281
|
+
} //GetCommitsInDateRange
|
|
282
|
+
|
|
283
|
+
async GetCommitsInCommitRange(
|
|
284
|
+
projectId: string,
|
|
285
|
+
repositoryId: string,
|
|
286
|
+
fromSha: string,
|
|
287
|
+
toSha: string
|
|
288
|
+
) {
|
|
289
|
+
let url = `${this.orgUrl}${projectId}/_apis/git/repositories/${repositoryId}/commits?searchCriteria.fromCommitId=${fromSha}&searchCriteria.toCommitId=${toSha}&searchCriteria.includeWorkItems=true&searchCriteria.$top=2000`;
|
|
290
|
+
return TFSServices.getItemContent(url, this.token, "get");
|
|
291
|
+
} //GetCommitsInCommitRange doesen't work!!!
|
|
292
|
+
|
|
293
|
+
async CreatePullRequestComment(
|
|
294
|
+
projectName: string,
|
|
295
|
+
repoID: string,
|
|
296
|
+
pullRequestID: number,
|
|
297
|
+
threads: any
|
|
298
|
+
) {
|
|
299
|
+
let url: string = `${this.orgUrl}${projectName}/_apis/git/repositories/${repoID}/pullRequests/${pullRequestID}/threads?api-version=5.0`;
|
|
300
|
+
let res: any = await TFSServices.getItemContent(
|
|
301
|
+
url,
|
|
302
|
+
this.token,
|
|
303
|
+
"post",
|
|
304
|
+
threads,
|
|
305
|
+
null
|
|
306
|
+
);
|
|
307
|
+
return res;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
async GetPullRequestComments(
|
|
311
|
+
projectName: string,
|
|
312
|
+
repoID: string,
|
|
313
|
+
pullRequestID: number
|
|
314
|
+
) {
|
|
315
|
+
let url: string = `${this.orgUrl}${projectName}/_apis/git/repositories/${repoID}/pullRequests/${pullRequestID}/threads`;
|
|
316
|
+
return TFSServices.getItemContent(
|
|
317
|
+
url,
|
|
318
|
+
this.token,
|
|
319
|
+
"get",
|
|
320
|
+
null,
|
|
321
|
+
null
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
async GetCommitsForRepo(
|
|
326
|
+
projectName: string,
|
|
327
|
+
repoID: string,
|
|
328
|
+
branchName?: string
|
|
329
|
+
){
|
|
330
|
+
let url: string
|
|
331
|
+
if (typeof branchName !== 'undefined') {
|
|
332
|
+
url = `${this.orgUrl}${projectName}/_apis/git/repositories/${repoID}/commits?searchCriteria.$top=2000&searchCriteria.itemVersion.version=${branchName}`
|
|
333
|
+
}
|
|
334
|
+
else{
|
|
335
|
+
url = `${this.orgUrl}${projectName}/_apis/git/repositories/${repoID}/commits?searchCriteria.$top=2000`
|
|
336
|
+
}
|
|
337
|
+
let res:any = await TFSServices.getItemContent(
|
|
338
|
+
url,
|
|
339
|
+
this.token,
|
|
340
|
+
"get",
|
|
341
|
+
null,
|
|
342
|
+
null
|
|
343
|
+
);
|
|
344
|
+
return res;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
async GetPullRequestsForRepo(
|
|
348
|
+
projectName: string,
|
|
349
|
+
repoID: string
|
|
350
|
+
){
|
|
351
|
+
let url: string =
|
|
352
|
+
`${this.orgUrl}${projectName}/_apis/git/repositories/${repoID}/pullrequests?status=completed&includeLinks=true&$top=2000}`;
|
|
353
|
+
|
|
354
|
+
let res:any = await TFSServices.getItemContent(
|
|
355
|
+
url,
|
|
356
|
+
this.token,
|
|
357
|
+
"get",
|
|
358
|
+
null,
|
|
359
|
+
null
|
|
360
|
+
);
|
|
361
|
+
return res;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
async GetItemsInPullRequestRange(
|
|
366
|
+
projectId: string,
|
|
367
|
+
repositoryId: string,
|
|
368
|
+
pullRequestIDs: any,
|
|
369
|
+
) {
|
|
370
|
+
let pullRequestsFilteredArray: any = [];
|
|
371
|
+
let ChangeSetsArray: any = [];
|
|
372
|
+
//get all pr's in git repo
|
|
373
|
+
let url = `${this.orgUrl}${projectId}/_apis/git/repositories/${repositoryId}/pullrequests?status=completed&includeLinks=true&$top=2000}`;
|
|
374
|
+
logger.debug(`request url: ${url}`);
|
|
375
|
+
let pullRequestsArray = await TFSServices.getItemContent(
|
|
376
|
+
url,
|
|
377
|
+
this.token,
|
|
378
|
+
"get"
|
|
379
|
+
);
|
|
380
|
+
logger.info(
|
|
381
|
+
`got ${pullRequestsArray.count} pullrequests for repo: ${repositoryId}`
|
|
382
|
+
);
|
|
383
|
+
//iterate commit list to filter relavant pullrequests
|
|
384
|
+
pullRequestsArray.value.forEach((pr: any) => {
|
|
385
|
+
pullRequestIDs.forEach((prId: any) => {
|
|
386
|
+
if (prId == pr.pullRequestId) {
|
|
387
|
+
pullRequestsFilteredArray.push(pr);
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
logger.info(
|
|
392
|
+
`filtered in prId range ${pullRequestsFilteredArray.length} pullrequests for repo: ${repositoryId}`
|
|
393
|
+
);
|
|
394
|
+
//extract linked items and append them to result
|
|
395
|
+
await Promise.all(
|
|
396
|
+
pullRequestsFilteredArray.map(async (pr: any) => {
|
|
397
|
+
let linkedItems: any = {};
|
|
398
|
+
try {
|
|
399
|
+
if (pr._links.workItems.href) {
|
|
400
|
+
//get workitems linked to pr
|
|
401
|
+
let url: string = pr._links.workItems.href;
|
|
402
|
+
linkedItems = await TFSServices.getItemContent(
|
|
403
|
+
url,
|
|
404
|
+
this.token,
|
|
405
|
+
"get"
|
|
406
|
+
);
|
|
407
|
+
logger.info(
|
|
408
|
+
`got ${linkedItems.count} items linked to pr ${pr.pullRequestId}`
|
|
409
|
+
);
|
|
410
|
+
await Promise.all(
|
|
411
|
+
linkedItems.value.map(async (item: any) => {
|
|
412
|
+
let populatedItem = await this.ticketsDataProvider.GetWorkItem(
|
|
413
|
+
projectId,
|
|
414
|
+
item.id
|
|
415
|
+
);
|
|
416
|
+
let changeSet: any = {
|
|
417
|
+
workItem: populatedItem,
|
|
418
|
+
pullrequest: pr,
|
|
419
|
+
};
|
|
420
|
+
ChangeSetsArray.push(changeSet);
|
|
421
|
+
})
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
} catch (error) {
|
|
425
|
+
logger.error(error);
|
|
426
|
+
}
|
|
427
|
+
})
|
|
428
|
+
);
|
|
429
|
+
return ChangeSetsArray;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
async GetRepoBranches(
|
|
433
|
+
projectName: string,
|
|
434
|
+
repoID: string
|
|
435
|
+
){
|
|
436
|
+
let url: string = `${this.orgUrl}${projectName}/_apis/git/repositories/${repoID}/refs?searchCriteria.$top=1000&filter=heads`
|
|
437
|
+
let res:any = await TFSServices.getItemContent(
|
|
438
|
+
url,
|
|
439
|
+
this.token,
|
|
440
|
+
"get",
|
|
441
|
+
null,
|
|
442
|
+
null
|
|
443
|
+
);
|
|
444
|
+
return res;
|
|
445
|
+
}
|
|
446
|
+
}
|