Skip to content

Commit 92b1ccd

Browse files
committed
🐛 Add system token to Azure git commands and fix action tests (#526)
* 🐛 QD-12128 add system token to git * 🐛 Add Go SDK to tests * 🐛 Changes after review * 🐛 Fix git errors
1 parent b86aab0 commit 92b1ccd

File tree

4 files changed

+72
-36
lines changed

4 files changed

+72
-36
lines changed

.github/workflows/node.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,14 @@ jobs:
366366
git commit -m "Add new feature"
367367
working-directory: '${{ matrix.directory }}'
368368
shell: bash
369+
- uses: actions/setup-go@v6
370+
if: ${{ matrix.arguments == '--ide,QDGO'}}
371+
with:
372+
go-version: '>=1.25.1'
373+
- name: Export GOROOT for subsequent steps
374+
if: ${{ matrix.arguments == '--ide,QDGO'}}
375+
shell: bash
376+
run: echo "GOROOT=$(go env GOROOT)" >> $GITHUB_ENV
369377
- name: Qodana
370378
uses: ./
371379
with:

vsts/QodanaScan/index.js

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79613,8 +79613,8 @@ var require_utils4 = __commonJS({
7961379613
const { sourceBranch, targetBranch } = getSourceAndTargetBranches();
7961479614
if (sourceBranch && targetBranch) {
7961579615
try {
79616-
yield git(["fetch", "origin"]);
79617-
const output = yield gitOutput(["merge-base", "origin/" + sourceBranch, "origin/" + targetBranch], {
79616+
yield git(["fetch", "origin"], true);
79617+
const output = yield gitOutput(["merge-base", "origin/" + sourceBranch, "origin/" + targetBranch], false, {
7961879618
ignoreReturnCode: true
7961979619
});
7962079620
if (output.exitCode === 0) {
@@ -79635,13 +79635,13 @@ To enable prMode, consider adding "fetchDepth: 0".`;
7963579635
return "";
7963679636
});
7963779637
}
79638-
function git(args_1) {
79639-
return __awaiter2(this, arguments, void 0, function* (args, options = {}) {
79640-
return (yield gitOutput(args, options)).exitCode;
79638+
function git(args_1, withCredentials_1) {
79639+
return __awaiter2(this, arguments, void 0, function* (args, withCredentials, options = {}) {
79640+
return (yield gitOutput(args, withCredentials, options)).exitCode;
7964179641
});
7964279642
}
79643-
function gitOutput(args_1) {
79644-
return __awaiter2(this, arguments, void 0, function* (args, options = {}) {
79643+
function gitOutput(args_1, withCredentials_1) {
79644+
return __awaiter2(this, arguments, void 0, function* (args, withCredentials, options = {}) {
7964579645
const result2 = {
7964679646
exitCode: 0,
7964779647
stdout: "",
@@ -79661,8 +79661,16 @@ To enable prMode, consider adding "fetchDepth: 0".`;
7966179661
});
7966279662
options.outStream = outStream;
7966379663
options.errStream = errStream;
79664+
if (withCredentials && process.env.SYSTEM_ACCESSTOKEN !== void 0) {
79665+
args = [
79666+
"-c",
79667+
`http.extraheader="AUTHORIZATION: bearer $SYSTEM_ACCESSTOKEN"`,
79668+
...args
79669+
];
79670+
}
7966479671
result2.exitCode = yield tl2.execAsync("git", args, options).catch((error) => {
79665-
tl2.warning(`Failed to run git command with arguments: ${args.join(" ")}`);
79672+
tl2.warning(`Failed to run git command with arguments: ${args.join(" ")}.
79673+
Error: ${error.message}`);
7966679674
throw error;
7966779675
});
7966879676
if (result2.stdout.startsWith("[command]")) {
@@ -79765,29 +79773,29 @@ ${comment_tag_pattern}`;
7976579773
}
7976679774
currentBranch = currentBranch.replace("refs/heads/", "");
7976779775
currentBranch = (0, qodana_12.validateBranchName)(currentBranch);
79768-
const currentCommit = (yield gitOutput(["rev-parse", "HEAD"])).stdout.trim();
79769-
yield git(["config", "user.name", output_12.COMMIT_USER]);
79770-
yield git(["config", "user.email", output_12.COMMIT_EMAIL]);
79771-
yield git(["add", "."]);
79772-
let exitCode = yield git(["commit", "-m", commitMessage], {
79776+
const currentCommit = (yield gitOutput(["rev-parse", "HEAD"], false)).stdout.trim();
79777+
yield git(["config", "user.name", output_12.COMMIT_USER], false);
79778+
yield git(["config", "user.email", output_12.COMMIT_EMAIL], false);
79779+
yield git(["add", "."], false);
79780+
let exitCode = yield git(["commit", "-m", commitMessage], false, {
7977379781
ignoreReturnCode: true
7977479782
});
7977579783
if (exitCode !== 0) {
7977679784
return;
7977779785
}
79778-
exitCode = yield git(["pull", "--rebase", "origin", currentBranch]);
79786+
exitCode = yield git(["pull", "--rebase", "origin", currentBranch], true);
7977979787
if (exitCode !== 0) {
7978079788
return;
7978179789
}
7978279790
if (mode === qodana_12.BRANCH) {
79783-
const commitToCherryPick = (yield gitOutput(["rev-parse", "HEAD"])).stdout.trim();
79784-
yield git(["checkout", currentBranch]);
79785-
yield git(["cherry-pick", commitToCherryPick]);
79791+
const commitToCherryPick = (yield gitOutput(["rev-parse", "HEAD"], false)).stdout.trim();
79792+
yield git(["checkout", currentBranch], false);
79793+
yield git(["cherry-pick", commitToCherryPick], false);
7978679794
yield gitPush(currentBranch);
7978779795
console.log(`Pushed quick-fixes to branch ${currentBranch}`);
7978879796
} else if (mode === qodana_12.PULL_REQUEST) {
7978979797
const newBranch = `qodana/quick-fixes-${currentCommit.slice(0, 7)}`;
79790-
yield git(["checkout", "-b", newBranch]);
79798+
yield git(["checkout", "-b", newBranch], false);
7979179799
yield gitPush(newBranch);
7979279800
yield createPr(commitMessage, currentBranch, newBranch);
7979379801
console.log(`Pushed quick-fixes to branch ${newBranch} and created pull request`);
@@ -79799,11 +79807,13 @@ ${comment_tag_pattern}`;
7979979807
}
7980079808
function gitPush(branch) {
7980179809
return __awaiter2(this, void 0, void 0, function* () {
79802-
const output = yield gitOutput(["push", "origin", branch], {
79810+
const output = yield gitOutput(["push", "origin", branch], true, {
7980379811
ignoreReturnCode: true
7980479812
});
7980579813
if (output.exitCode !== 0) {
79806-
tl2.warning(`Failed to push branch ${branch}: ${output.stderr}`);
79814+
tl2.warning(`Failed to push branch ${branch}.
79815+
Stdout: ${output.stdout}
79816+
Stderr: ${output.stderr}`);
7980779817
}
7980879818
});
7980979819
}

vsts/src/utils.ts

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,10 @@ async function getPrSha(): Promise<string> {
215215

216216
if (sourceBranch && targetBranch) {
217217
try {
218-
await git(['fetch', 'origin'])
218+
await git(['fetch', 'origin'], true)
219219
const output = await gitOutput(
220220
['merge-base', 'origin/' + sourceBranch, 'origin/' + targetBranch],
221+
false,
221222
{
222223
ignoreReturnCode: true
223224
}
@@ -243,19 +244,22 @@ To enable prMode, consider adding "fetchDepth: 0".`
243244

244245
async function git(
245246
args: string[],
247+
withCredentials: boolean,
246248
options: IExecOptions = {}
247249
): Promise<number> {
248-
return (await gitOutput(args, options)).exitCode
250+
return (await gitOutput(args, withCredentials, options)).exitCode
249251
}
250252

251253
/**
252254
* Returns trimmed output of git command omitting the command itself
253255
* i.e., if gitOutput(['status']) is called the "/usr/bin/git status" will be omitted
256+
* @param withCredentials pass oauth token as extra header. Could be needed for fetch, push commands
254257
* @param args git arguments
255258
* @param options options for azure-pipelines-task-lib/task exec
256259
*/
257260
async function gitOutput(
258261
args: string[],
262+
withCredentials: boolean,
259263
options: IExecOptions = {}
260264
): Promise<{exitCode: number; stderr: string; stdout: string}> {
261265
const result = {
@@ -282,8 +286,18 @@ async function gitOutput(
282286
options.outStream = outStream
283287
options.errStream = errStream
284288

289+
if (withCredentials && process.env.SYSTEM_ACCESSTOKEN !== undefined) {
290+
args = [
291+
'-c',
292+
`http.extraheader="AUTHORIZATION: bearer $SYSTEM_ACCESSTOKEN"`,
293+
...args
294+
]
295+
}
296+
285297
result.exitCode = await tl.execAsync('git', args, options).catch(error => {
286-
tl.warning(`Failed to run git command with arguments: ${args.join(' ')}`)
298+
tl.warning(
299+
`Failed to run git command with arguments: ${args.join(' ')}.\nError: ${(error as Error).message}`
300+
)
287301
throw error
288302
})
289303
if (result.stdout.startsWith('[command]')) {
@@ -443,31 +457,33 @@ export async function pushQuickFixes(
443457
currentBranch = currentBranch.replace('refs/heads/', '')
444458
currentBranch = validateBranchName(currentBranch)
445459

446-
const currentCommit = (await gitOutput(['rev-parse', 'HEAD'])).stdout.trim()
447-
await git(['config', 'user.name', COMMIT_USER])
448-
await git(['config', 'user.email', COMMIT_EMAIL])
449-
await git(['add', '.'])
450-
let exitCode = await git(['commit', '-m', commitMessage], {
460+
const currentCommit = (
461+
await gitOutput(['rev-parse', 'HEAD'], false)
462+
).stdout.trim()
463+
await git(['config', 'user.name', COMMIT_USER], false)
464+
await git(['config', 'user.email', COMMIT_EMAIL], false)
465+
await git(['add', '.'], false)
466+
let exitCode = await git(['commit', '-m', commitMessage], false, {
451467
ignoreReturnCode: true
452468
})
453469
if (exitCode !== 0) {
454470
return
455471
}
456-
exitCode = await git(['pull', '--rebase', 'origin', currentBranch])
472+
exitCode = await git(['pull', '--rebase', 'origin', currentBranch], true)
457473
if (exitCode !== 0) {
458474
return
459475
}
460476
if (mode === BRANCH) {
461477
const commitToCherryPick = (
462-
await gitOutput(['rev-parse', 'HEAD'])
478+
await gitOutput(['rev-parse', 'HEAD'], false)
463479
).stdout.trim()
464-
await git(['checkout', currentBranch])
465-
await git(['cherry-pick', commitToCherryPick])
480+
await git(['checkout', currentBranch], false)
481+
await git(['cherry-pick', commitToCherryPick], false)
466482
await gitPush(currentBranch)
467483
console.log(`Pushed quick-fixes to branch ${currentBranch}`)
468484
} else if (mode === PULL_REQUEST) {
469485
const newBranch = `qodana/quick-fixes-${currentCommit.slice(0, 7)}`
470-
await git(['checkout', '-b', newBranch])
486+
await git(['checkout', '-b', newBranch], false)
471487
await gitPush(newBranch)
472488
await createPr(commitMessage, currentBranch, newBranch)
473489
console.log(
@@ -480,11 +496,13 @@ export async function pushQuickFixes(
480496
}
481497

482498
async function gitPush(branch: string): Promise<void> {
483-
const output = await gitOutput(['push', 'origin', branch], {
499+
const output = await gitOutput(['push', 'origin', branch], true, {
484500
ignoreReturnCode: true
485501
})
486502
if (output.exitCode !== 0) {
487-
tl.warning(`Failed to push branch ${branch}: ${output.stderr}`)
503+
tl.warning(
504+
`Failed to push branch ${branch}.\nStdout: ${output.stdout}\nStderr: ${output.stderr}`
505+
)
488506
}
489507
}
490508

vsts/vss-extension.dev.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifestVersion": 1,
33
"id": "qodana-dev",
44
"name": "Qodana (Dev)",
5-
"version": "2025.1.216",
5+
"version": "2025.2.227",
66
"publisher": "JetBrains",
77
"targets": [
88
{

0 commit comments

Comments
 (0)