-
Notifications
You must be signed in to change notification settings - Fork 277
Add step in publish pipeline to create PR to azure-sdk-for-net #7426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
try { | ||
// Clone the repository | ||
console.log(`Cloning azure-sdk-for-net repository...`); | ||
execSync(`git clone https://github.com/Azure/azure-sdk-for-net.git ${tempDir}`, { |
Check warning
Code scanning / CodeQL
Shell command built from environment values Medium
absolute path
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 5 days ago
To fix the issue, we will replace the use of execSync
with execFileSync
and pass the arguments separately instead of interpolating them into the shell command. This approach avoids shell interpretation of the tempDir
value, mitigating the risk of command injection or unintended behavior.
Specifically:
- Replace the
execSync
call on line 49 withexecFileSync
. - Pass the
git
command and its arguments as separate parameters toexecFileSync
. - Ensure that the
tempDir
value is passed as an argument, not interpolated into the command string.
-
Copy modified line R2 -
Copy modified line R49
@@ -1,3 +1,3 @@ | ||
/* eslint-disable no-console */ | ||
import { execSync } from "child_process"; | ||
import { execFileSync, execSync } from "child_process"; | ||
import { mkdirSync, writeFileSync, readFileSync } from "fs"; | ||
@@ -48,3 +48,3 @@ | ||
console.log(`Cloning azure-sdk-for-net repository...`); | ||
execSync(`git clone https://github.com/Azure/azure-sdk-for-net.git ${tempDir}`, { | ||
execFileSync("git", ["clone", "https://github.com/Azure/azure-sdk-for-net.git", tempDir], { | ||
stdio: "inherit", |
|
||
// Create a new branch | ||
console.log(`Creating branch ${branchName}...`); | ||
execSync(`git checkout -b ${branchName}`, { |
Check warning
Code scanning / CodeQL
Unsafe shell command constructed from library input Medium
library input
shell command
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 5 days ago
To fix the issue, we should avoid directly interpolating the branchName
into the shell command string. Instead, we can use the execFileSync
method from the child_process
module, which allows us to pass arguments as an array. This approach avoids shell interpretation of special characters in the input, mitigating the risk of shell injection.
Specifically:
- Replace the
execSync
call on line 65 withexecFileSync
, passing thebranchName
as an argument in an array. - Ensure that the
branchName
is validated or sanitized before use to prevent any unintended behavior.
-
Copy modified line R2 -
Copy modified line R65
@@ -1,3 +1,3 @@ | ||
/* eslint-disable no-console */ | ||
import { execSync } from "child_process"; | ||
import { execSync, execFileSync } from "child_process"; | ||
import { mkdirSync, writeFileSync, readFileSync } from "fs"; | ||
@@ -64,3 +64,3 @@ | ||
console.log(`Creating branch ${branchName}...`); | ||
execSync(`git checkout -b ${branchName}`, { | ||
execFileSync("git", ["checkout", "-b", branchName], { | ||
stdio: "inherit", |
// Push the branch | ||
console.log(`Pushing branch to remote...`); | ||
// Using HTTPS with token for auth | ||
const remoteUrl = `https://${githubToken}@github.com/Azure/azure-sdk-for-net.git`; |
Check warning
Code scanning / CodeQL
Unsafe shell command constructed from library input Medium
library input
shell command
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 5 days ago
To fix the issue, we should avoid directly embedding the githubToken
into the shell command string. Instead, we can use a safer API like child_process.execFile
to pass the arguments as an array, which avoids interpretation by the shell. Since execFile
does not support inline authentication in the URL, we can use the git
command's -c
option to set the http.extraheader
configuration for authentication.
This approach ensures that the githubToken
is not interpreted by the shell, mitigating the risk of command injection.
-
Copy modified lines R98-R99
@@ -97,4 +97,4 @@ | ||
// Using HTTPS with token for auth | ||
const remoteUrl = `https://${githubToken}@github.com/Azure/azure-sdk-for-net.git`; | ||
execSync(`git push ${remoteUrl} ${branchName}`, { | ||
const remoteUrl = "https://github.com/Azure/azure-sdk-for-net.git"; | ||
execSync("git", ["-c", `http.extraheader=Authorization: Bearer ${githubToken}`, "push", remoteUrl, branchName], { | ||
stdio: "inherit", |
console.log(`Pushing branch to remote...`); | ||
// Using HTTPS with token for auth | ||
const remoteUrl = `https://${githubToken}@github.com/Azure/azure-sdk-for-net.git`; | ||
execSync(`git push ${remoteUrl} ${branchName}`, { |
Check warning
Code scanning / CodeQL
Unsafe shell command constructed from library input Medium
library input
shell command
This string concatenation which depends on
This PR adds automation to create a pull request in the Azure SDK for .NET repository that updates the dependency on http-client-csharp when a new version is published.
Implementation Details
Created a new script in
internal-build-utils
package:create-azure-sdk-for-net-pr.ts
to handle PR creationhttp-client.ts
for GitHub API requestsModified the
http-client-csharp
publish pipeline:Added documentation:
CONTRIBUTING.md
for http-client-csharpHow It Works
When a new version of http-client-csharp is published from the main branch:
This automation helps ensure that the Azure SDK for .NET always uses the latest version of the TypeSpec-generated client components, improving consistency across repositories.
Fixes #7110.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.