by Developer Wiki Admin Account
Changes to 3 files · Browse files at 3e61a62ffd2c Showing diff from parent bb959c445c8a 57dcd44b2fb2 Diff from another changeset...
@@ -6,7 +6,8 @@ #
# The script should be run on a machine which has sufficient disk space to clone copies of ALL of the
# repositories from the old kiln server. This means it also requires that Mercurial be installed in order to run.
-
+#
+# Beware: Branches will not migrate properly if the parent repo has been changed since the original point of the branch!
@@ -143,6 +144,12 @@ # If we don't find an existing repo, then create a new repo with the information we grabbed from the old server
if (not dest_repo):
if (src_repo['ixParent']):
+ # By setting the ixParent field, when Repo/Create is called, it will create a new branch from the ixParent Repo.
+ # This means, that the point at which the src repo branched off from the parent can and most likely will be different from the
+ # point at which the dest repo gets branched. (One option I know of to fix this, after the fact, is to strip changesets in
+ # the dest repo back to the point where the branch was created in the src repo. Then push the src repo to the dest repo and
+ # the src and dest branches should be back in sync.
+ debug_print(" !!! Warning: Branches may not migrate properly !!!")
data = urllib.urlencode({'token': destinationToken,
'sName': src_repo['sName'],
'sDescription': src_repo['sDescription'],
|
|
|
@@ -0,0 +1,117 @@ + <#
+.SYNOPSIS
+ Repairs all repositories on a Kiln server
+
+.DESCRIPTION
+ Uses the Kiln API to gather information about all repositories hosted on the Kiln server and then
+ issues API commands to repair each of the repositories.
+
+.EXAMPLE
+ .\repair_all_repos.ps1 -kilnUrl "http://my.fogbugz/kiln" -token "gfd4567f2g7d8f2g4d6f8sdsdg88"
+
+.PARAMETER kilnUrl
+ Where Kiln is hosted, this URL must be reachable from the local machine
+
+.PARAMETER token
+ A valid API token for the Kiln server
+
+.NOTES
+ Author: Quentin Schroeder
+ Version: 1.0
+ Date: Jan 22, 2013
+#>
+
+
+param([string]$kilnUrl = "http://localhost/kiln",
+ [string]$token = ""
+ )
+
+
+function main() {
+ if ($token -eq "") {write-host "Must provide a token to authorize access to Kiln."; exit;}
+
+ $url = "{0}/Api/1.0/Project?token={1}" -f ($kilnUrl, $token)
+ write-host ("Getting repo information from {0}" -f $url)
+ $response = (New-Object System.Net.WebClient).DownloadString($url)
+ if (!($?)) {write-host "Failed to get repo information. Confirm the kilnUrl parameter is correct."; exit;}
+
+ $responseXml = Convert-JsonToXml($response)
+ $projects = $responseXml.root.childnodes
+
+ foreach ($project in $projects) {
+ foreach ($group in $project.repoGroups.childnodes) {
+ foreach ($repo in $group.repos.childnodes) {
+ $ixRepo = $repo.ixRepo."#text"
+ $repoName = $repo.sName."#text"
+ $URI = "{0}/api/1.0/repo/{1}/repair?token={2}" -f ($kilnUrl, $ixRepo, $token)
+ write-host ("Attempting to repair repo '{0}' (ixRepo: {1})" -f ($repoName, $ixRepo) )
+ Execute-HTTPPostCommand $URI "a=1"
+ if (!($?)) {write-host "Failed!!"}
+ }
+ }
+ }
+}
+
+
+
+# This is provided as an alternative to ConvertFrom-JSON, which requires Powershell V3
+# which is not on most servers by default and requires a reboot to install.
+# Source: (https://www.cogmotive.com/blog/powershell/parsing-json-in-powershell-xml-the-member-item-is-already-present)
+Add-Type -Assembly System.ServiceModel.Web,System.Runtime.Serialization
+function Convert-JsonToXml([string]$json)
+{
+ $bytes = [byte[]][char[]]$json
+ $quotas = [System.Xml.XmlDictionaryReaderQuotas]::Max
+ $jsonReader = [System.Runtime.Serialization.Json.JsonReaderWriterFactory]::CreateJsonReader($bytes,$quotas)
+ try
+ {
+ $xml = new-object System.Xml.XmlDocument
+ $xml.Load($jsonReader)
+ $xml
+ }
+ finally
+ {
+ $jsonReader.Close()
+ }
+}
+
+
+
+# Source: (http://stackoverflow.com/questions/5246836/user-powershell-script-to-post-to-url)
+function Execute-HTTPPostCommand() {
+ param(
+ [string] $target = $null,
+ [string] $post = $null
+ )
+
+ $webRequest = [System.Net.WebRequest]::Create($target)
+ $webRequest.ContentType = "text/html"
+ $PostStr = [System.Text.Encoding]::UTF8.GetBytes($post)
+ $webrequest.ContentLength = $PostStr.Length
+ $webRequest.ServicePoint.Expect100Continue = $false
+ $webRequest.Method = "POST"
+
+ $requestStream = $webRequest.GetRequestStream()
+ $requestStream.Write($PostStr, 0,$PostStr.length)
+ $requestStream.Close()
+
+ try
+ {
+ [System.Net.WebResponse] $resp = $webRequest.GetResponse()
+ }
+ catch [Net.WebException]
+ {
+ write-host $_.Exception.ToString()
+ }
+
+ $rs = $resp.GetResponseStream()
+ [System.IO.StreamReader] $sr = New-Object System.IO.StreamReader -argumentList $rs
+ [string] $results = $sr.ReadToEnd()
+
+ return $results
+}
+
+
+
+main
+
|
Loading...