github
2 TopicsIssue running Powershell script to clone GitHub repositories
I'm running into a problem where my script is unable to clone private GitHub repositories into a destination folder using a GitHub API key. When I run the script, I receive the following error: Invoke-RestMethod : {"message":"Not Found","documentation_url":"https://docs.github.com/rest"} At C:\Users\florekd\Desktop\script.ps1:5 char:17 + $repoInfo = Invoke-RestMethod -Uri $url -Headers $headers + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand Original script: # Function to clone a repository using GitHub API function CloneGitHubRepo($repoName, $accessToken, $repoBranch, $cloneDirectory) { $headers = @{ "Authorization" = "Bearer $accessToken" } $url = "https://api.github.com/<org_name>/$repoName" $repoInfo = Invoke-RestMethod -Uri $url -Headers $headers if ($repoInfo) { $cloneUrl = $repoInfo.clone_url git clone $cloneUrl -b $repoBranch $cloneDirectory --progress -v } else { Write-Host "Failed to retrieve repository information for $url" } } Function Get-Filename($initialDirectory){ [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null $OpenFileDialog=New-Object System.Windows.Forms.OpenFileDialog $OpenFileDialog.InitialDirectory=$initialDirectory $OpenFileDialog.ShowDialog() | Out-Null $OpenFileDialog.FileName } #Prompt user for a home directory to make $save_directory = Read-Host -Prompt "Enter the root directory name to save all project files: " #Prompt user for file containing list of GitHub repository URLs #$git_list = Read-Host -Prompt "Provide the list of GitHub URLs to pull: " $git_list = Get-Filename "$env:USERPROFILE\Desktop\" #Prompt user for GitHub Release Branch to target $git_branch = Read-Host -Prompt "Provide Git release branch to target: " #Prompt user for GitHub API Token $git_token = Read-Host -Prompt "Provide the GitHub token to use: " #Create Save Directory If(!(test-path -PathType container $save_directory)) { New-Item -Path $save_directory -ItemType Directory } # Loop through each repository and clone it foreach ($git_uri in Get-Content -Path $git_list) { CloneGitHubRepo $git_uri $git_token $git_branch "$save_directory\$git_uri" } Would it be easier to just use curl to pull the repos?Solved4.1KViews0likes2Commentspowershell to run git commit using PAT in Azure github pipelines
I created a Personal Access Token for my repository and named it as 'PAT', created a variable called 'PATSecret' in my pipeline for the secret of PAT. Passing PATSecret as an input variable for $Cred. But when trying to use this secret to run commit command, authentication is failing. param( [string]$Cred ) git--version gitadd. Write-Host"setupauthorinfo" gitconfiguser.emailyou@you.com gitconfiguser.name"yourname" Write-Host"gitcommitwithmessage" gitcommit-m"TestCommitfromAzureDevOps" gitpush-uhttps://PAT:$($cred)@dev.azure.com/project/_git/myrepo HEAD Error message: fatal: Authentication failed for 'https://dev.azure.com/project/_git/myrepo/' ##[error]PowerShell exited with code '1'.Solved7.3KViews1like4Comments