korekt-cli 0.9.0 → 0.9.2
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/package.json +1 -1
- package/scripts/azure.sh +29 -43
- package/src/index.test.js +5 -5
- package/src/utils.js +2 -2
package/package.json
CHANGED
package/scripts/azure.sh
CHANGED
|
@@ -72,40 +72,20 @@ wrap_code_block() {
|
|
|
72
72
|
printf "%s\n" "$content" | fold -s -w "$max_width"
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
# Function to fetch
|
|
76
|
-
|
|
75
|
+
# Function to fetch threads (single request, no pagination)
|
|
76
|
+
fetch_threads() {
|
|
77
77
|
local url="$1"
|
|
78
|
-
local
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
while [ "$has_more" = true ]; do
|
|
84
|
-
local response
|
|
85
|
-
response=$(curl -s -X GET "${url}?\$top=${top}&\$skip=${skip}&api-version=6.0" \
|
|
86
|
-
-H "Authorization: Bearer $SYSTEM_ACCESSTOKEN" \
|
|
87
|
-
-H "Content-Type: application/json")
|
|
88
|
-
|
|
89
|
-
if ! echo "$response" | jq -e '.value' > /dev/null 2>&1; then
|
|
90
|
-
echo "[]"
|
|
91
|
-
return
|
|
92
|
-
fi
|
|
93
|
-
|
|
94
|
-
local page_threads
|
|
95
|
-
page_threads=$(echo "$response" | jq '.value')
|
|
96
|
-
|
|
97
|
-
local count
|
|
98
|
-
count=$(echo "$page_threads" | jq 'length')
|
|
78
|
+
local response
|
|
79
|
+
response=$(curl -s --max-time 30 -X GET "${url}?api-version=7.1" \
|
|
80
|
+
-H "Authorization: Bearer $SYSTEM_ACCESSTOKEN" \
|
|
81
|
+
-H "Content-Type: application/json")
|
|
99
82
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
skip=$((skip + top))
|
|
105
|
-
fi
|
|
106
|
-
done
|
|
83
|
+
if ! echo "$response" | jq -e '.value' > /dev/null 2>&1; then
|
|
84
|
+
echo "[]"
|
|
85
|
+
return
|
|
86
|
+
fi
|
|
107
87
|
|
|
108
|
-
echo "$
|
|
88
|
+
echo "$response" | jq '.value'
|
|
109
89
|
}
|
|
110
90
|
|
|
111
91
|
# Function to delete old bot summary comments
|
|
@@ -114,7 +94,7 @@ delete_old_summary_comments() {
|
|
|
114
94
|
local threads_url="${BASE_API_URL}/threads"
|
|
115
95
|
local existing_threads
|
|
116
96
|
|
|
117
|
-
existing_threads=$(
|
|
97
|
+
existing_threads=$(fetch_threads "$threads_url")
|
|
118
98
|
|
|
119
99
|
if ! echo "$existing_threads" | jq -e . > /dev/null 2>&1; then
|
|
120
100
|
echo "Warning: Could not fetch existing threads to delete old summaries."
|
|
@@ -122,27 +102,31 @@ delete_old_summary_comments() {
|
|
|
122
102
|
fi
|
|
123
103
|
|
|
124
104
|
# Find threads that contain the bot marker and have no threadContext (summary comments)
|
|
125
|
-
echo "$existing_threads" | jq -r '.[] | select(.comments[0].content | contains("🤖 **Automated Code Review Results**")) | select(.threadContext == null) | .id' | while IFS= read -r
|
|
126
|
-
|
|
105
|
+
echo "$existing_threads" | jq -r '.[] | select((.comments[0].content? // "") | contains("🤖 **Automated Code Review Results**")) | select(.threadContext == null) | {id: .id, comment_id: .comments[0].id} | @json' | while IFS= read -r thread_json; do
|
|
106
|
+
local thread_id
|
|
107
|
+
local comment_id
|
|
108
|
+
thread_id=$(echo "$thread_json" | jq -r '.id')
|
|
109
|
+
comment_id=$(echo "$thread_json" | jq -r '.comment_id')
|
|
110
|
+
|
|
111
|
+
if [ -z "$thread_id" ] || [ "$thread_id" = "null" ] || [ -z "$comment_id" ] || [ "$comment_id" = "null" ]; then
|
|
127
112
|
continue
|
|
128
113
|
fi
|
|
129
114
|
|
|
130
|
-
echo "Deleting old summary thread
|
|
115
|
+
echo "Deleting old summary comment (thread ID: $thread_id, comment ID: $comment_id)..."
|
|
131
116
|
|
|
132
117
|
local delete_response
|
|
133
|
-
delete_response=$(curl -s -X
|
|
118
|
+
delete_response=$(curl -s -X DELETE "${BASE_API_URL}/threads/${thread_id}/comments/${comment_id}?api-version=7.1" \
|
|
134
119
|
-H "Authorization: Bearer $SYSTEM_ACCESSTOKEN" \
|
|
135
120
|
-H "Content-Type: application/json" \
|
|
136
|
-
--data '{"status": "closed"}' \
|
|
137
121
|
-w "\n%{http_code}")
|
|
138
122
|
|
|
139
123
|
local http_status
|
|
140
124
|
http_status=$(echo "$delete_response" | tail -n1)
|
|
141
125
|
|
|
142
126
|
if [ "$http_status" -ge 200 ] && [ "$http_status" -lt 300 ]; then
|
|
143
|
-
echo "Successfully
|
|
127
|
+
echo "Successfully deleted comment in thread $thread_id"
|
|
144
128
|
else
|
|
145
|
-
echo "Warning: Could not
|
|
129
|
+
echo "Warning: Could not delete comment in thread $thread_id (HTTP $http_status)"
|
|
146
130
|
fi
|
|
147
131
|
done
|
|
148
132
|
}
|
|
@@ -153,7 +137,7 @@ populate_existing_comments_map() {
|
|
|
153
137
|
local threads_url="${BASE_API_URL}/threads"
|
|
154
138
|
local existing_threads
|
|
155
139
|
|
|
156
|
-
existing_threads=$(
|
|
140
|
+
existing_threads=$(fetch_threads "$threads_url")
|
|
157
141
|
|
|
158
142
|
if ! echo "$existing_threads" | jq -e . > /dev/null 2>&1; then
|
|
159
143
|
echo "Warning: Could not fetch existing threads. Duplicate checking will be skipped."
|
|
@@ -209,6 +193,7 @@ post_review_thread() {
|
|
|
209
193
|
'{
|
|
210
194
|
comments: [
|
|
211
195
|
{
|
|
196
|
+
parentCommentId: 0,
|
|
212
197
|
content: $content,
|
|
213
198
|
commentType: 1
|
|
214
199
|
}
|
|
@@ -228,7 +213,7 @@ post_review_thread() {
|
|
|
228
213
|
}')
|
|
229
214
|
|
|
230
215
|
local post_response
|
|
231
|
-
post_response=$(curl -s -X POST "${BASE_API_URL}/threads?api-version=
|
|
216
|
+
post_response=$(curl -s -X POST "${BASE_API_URL}/threads?api-version=7.1" \
|
|
232
217
|
-H "Authorization: Bearer $SYSTEM_ACCESSTOKEN" \
|
|
233
218
|
-H "Content-Type: application/json" \
|
|
234
219
|
--data "$thread_payload" -w "\n%{http_code}")
|
|
@@ -458,6 +443,7 @@ SUMMARY_PAYLOAD=$(jq -n \
|
|
|
458
443
|
'{
|
|
459
444
|
comments: [
|
|
460
445
|
{
|
|
446
|
+
parentCommentId: 0,
|
|
461
447
|
content: $content,
|
|
462
448
|
commentType: 1
|
|
463
449
|
}
|
|
@@ -465,7 +451,7 @@ SUMMARY_PAYLOAD=$(jq -n \
|
|
|
465
451
|
status: 1
|
|
466
452
|
}')
|
|
467
453
|
|
|
468
|
-
POST_RESPONSE=$(curl -s -X POST "${BASE_API_URL}/threads?api-version=
|
|
454
|
+
POST_RESPONSE=$(curl -s -X POST "${BASE_API_URL}/threads?api-version=7.1" \
|
|
469
455
|
-H "Authorization: Bearer $SYSTEM_ACCESSTOKEN" \
|
|
470
456
|
-H "Content-Type: application/json" \
|
|
471
457
|
--data "$SUMMARY_PAYLOAD" -w "\n%{http_code}")
|
|
@@ -503,7 +489,7 @@ STATUS_PAYLOAD=$(jq -n \
|
|
|
503
489
|
}
|
|
504
490
|
}')
|
|
505
491
|
|
|
506
|
-
STATUS_RESPONSE=$(curl -s -X POST "${BASE_API_URL}/statuses?api-version=
|
|
492
|
+
STATUS_RESPONSE=$(curl -s -X POST "${BASE_API_URL}/statuses?api-version=7.1" \
|
|
507
493
|
-H "Authorization: Bearer $SYSTEM_ACCESSTOKEN" \
|
|
508
494
|
-H "Content-Type: application/json" \
|
|
509
495
|
--data "$STATUS_PAYLOAD" -w "\n%{http_code}")
|
package/src/index.test.js
CHANGED
|
@@ -451,7 +451,7 @@ describe('getPrUrl', () => {
|
|
|
451
451
|
delete process.env.BITBUCKET_WORKSPACE;
|
|
452
452
|
delete process.env.BITBUCKET_REPO_SLUG;
|
|
453
453
|
delete process.env.BITBUCKET_PR_ID;
|
|
454
|
-
delete process.env.
|
|
454
|
+
delete process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI;
|
|
455
455
|
delete process.env.SYSTEM_TEAMPROJECT;
|
|
456
456
|
delete process.env.BUILD_REPOSITORY_NAME;
|
|
457
457
|
delete process.env.SYSTEM_PULLREQUEST_PULLREQUESTID;
|
|
@@ -477,7 +477,7 @@ describe('getPrUrl', () => {
|
|
|
477
477
|
});
|
|
478
478
|
|
|
479
479
|
it('should return Azure DevOps PR URL when Azure env vars are set', () => {
|
|
480
|
-
process.env.
|
|
480
|
+
process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI = 'https://dev.azure.com/myorg/';
|
|
481
481
|
process.env.SYSTEM_TEAMPROJECT = 'myproject';
|
|
482
482
|
process.env.BUILD_REPOSITORY_NAME = 'myrepo';
|
|
483
483
|
process.env.SYSTEM_PULLREQUEST_PULLREQUESTID = '789';
|
|
@@ -486,7 +486,7 @@ describe('getPrUrl', () => {
|
|
|
486
486
|
});
|
|
487
487
|
|
|
488
488
|
it('should strip trailing slash from Azure DevOps collection URI', () => {
|
|
489
|
-
process.env.
|
|
489
|
+
process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI = 'https://dev.azure.com/myorg/';
|
|
490
490
|
process.env.SYSTEM_TEAMPROJECT = 'myproject';
|
|
491
491
|
process.env.BUILD_REPOSITORY_NAME = 'myrepo';
|
|
492
492
|
process.env.SYSTEM_PULLREQUEST_PULLREQUESTID = '789';
|
|
@@ -497,7 +497,7 @@ describe('getPrUrl', () => {
|
|
|
497
497
|
});
|
|
498
498
|
|
|
499
499
|
it('should URL-encode spaces in Azure DevOps project and repo names', () => {
|
|
500
|
-
process.env.
|
|
500
|
+
process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI = 'https://dev.azure.com/myorg/';
|
|
501
501
|
process.env.SYSTEM_TEAMPROJECT = 'My Project';
|
|
502
502
|
process.env.BUILD_REPOSITORY_NAME = 'My Repo';
|
|
503
503
|
process.env.SYSTEM_PULLREQUEST_PULLREQUESTID = '789';
|
|
@@ -527,7 +527,7 @@ describe('getPrUrl', () => {
|
|
|
527
527
|
});
|
|
528
528
|
|
|
529
529
|
it('should return null when only partial Azure env vars are set', () => {
|
|
530
|
-
process.env.
|
|
530
|
+
process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI = 'https://dev.azure.com/myorg/';
|
|
531
531
|
process.env.SYSTEM_TEAMPROJECT = 'myproject';
|
|
532
532
|
// BUILD_REPOSITORY_NAME and SYSTEM_PULLREQUEST_PULLREQUESTID not set
|
|
533
533
|
|
package/src/utils.js
CHANGED
|
@@ -34,12 +34,12 @@ export function getPrUrl() {
|
|
|
34
34
|
}
|
|
35
35
|
// Azure DevOps Pipelines
|
|
36
36
|
if (
|
|
37
|
-
process.env.
|
|
37
|
+
process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI &&
|
|
38
38
|
process.env.SYSTEM_TEAMPROJECT &&
|
|
39
39
|
process.env.BUILD_REPOSITORY_NAME &&
|
|
40
40
|
process.env.SYSTEM_PULLREQUEST_PULLREQUESTID
|
|
41
41
|
) {
|
|
42
|
-
const collectionUri = process.env.
|
|
42
|
+
const collectionUri = process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI.replace(/\/$/, '');
|
|
43
43
|
return `${collectionUri}/${encodeURIComponent(process.env.SYSTEM_TEAMPROJECT)}/_git/${encodeURIComponent(process.env.BUILD_REPOSITORY_NAME)}/pullrequest/${process.env.SYSTEM_PULLREQUEST_PULLREQUESTID}`;
|
|
44
44
|
}
|
|
45
45
|
return null;
|