-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSyncADOtoGitHub.ps
61 lines (59 loc) · 2.09 KB
/
SyncADOtoGitHub.ps
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
param(
[Parameter()]
[string]$GitHubDestinationPAT,
[Parameter()]
[string]$ADOSourcePAT
)
# Write your PowerShell commands here.
Write-Host ' - - - - - - - - - - - - - - - - - - - - - - - - -'
Write-Host ' reflect Azure Devops repo changes to GitHub repo'
Write-Host ' - - - - - - - - - - - - - - - - - - - - - - - - - '
$AzureRepoName = "nestjs-project"
$ADOCloneURL = "dev.azure.com/BrainvireInfo/IT-Project/_git/nestjs-project"
$GitHubCloneURL = "github.com/vinodkumar704/nestjs-project.git"
$stageDir = pwd | Split-Path
Write-Host "stage Dir is : $stageDir"
$githubDir = $stageDir +"\"+"gitHub"
Write-Host "github Dir : $githubDir"
$destination = $githubDir+"\"+ $AzureRepoName+".git"
Write-Host "destination: $destination"
#Please make sure, you remove https from azure-repo-clone-url
$sourceURL = "https://$($ADOSourcePAT)"+"@"+"$($ADOCloneURL)"
write-host "source URL : $sourceURL"
#Please make sure, you remove https from github-repo-clone-url
write-host "tocken : $GitHubDestinationPAT"
write-host "clone URL : $GitHubCloneURL"
$destURL = "https://" + $($GitHubDestinationPAT) +"@"+"$($GitHubCloneURL)"
write-host "dest URL : $destURL"
#Check if the parent directory exists and delete
if((Test-Path -path $githubDir))
{
Remove-Item -Path $githubDir -Recurse -force
}
if(!(Test-Path -path $githubDir))
{
New-Item -ItemType directory -Path $githubDir
Set-Location $githubDir
git clone --mirror $sourceURL
}
else
{
Write-Host "The given folder path $githubDir already exists";
}
Set-Location $destination
Write-Output '*****Git removing remote secondary****'
git remote rm secondary
Write-Output '*****Git remote add****'
git remote add --mirror=fetch secondary $destURL
Write-Output '*****Git fetch origin****'
git fetch $sourceURL
Write-Output '*****Git push secondary****'
#git remote set-url origin $destURLSetURL
git push secondary --all -f
Write-Output '**Azure Devops repo synced with Github repo**'
Set-Location $stageDir
if((Test-Path -path $githubDir))
{
Remove-Item -Path $githubDir -Recurse -force
}
write-host "Job completed"