Skip to content

Commit

Permalink
Initial support for full github projects - references #113
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Oct 13, 2014
1 parent 32fa053 commit f76bc5a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### 0.6.13 - 13.10.2014
* Initial support for full github projects - https://github.com/fsprojects/Paket/issues/113

#### 0.6.12 - 13.10.2014
* BUGFIX: Paket only deletes files which will are downloaded by init-auto-restore process - https://github.com/fsprojects/Paket/pull/254

Expand Down
1 change: 1 addition & 0 deletions src/Paket.Core/DependenciesFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ module DependenciesFileParser =
| _ -> failwithf "invalid github specification:%s %s" Environment.NewLine trimmed
match parts with
| [| _; projectSpec; fileSpec |] -> SourceFile(getParts projectSpec, fileSpec)
| [| _; projectSpec; |] -> SourceFile(getParts projectSpec, "FULLPROJECT")
| _ -> failwithf "invalid github specification:%s %s" Environment.NewLine trimmed
| _ -> Blank

Expand Down
42 changes: 41 additions & 1 deletion src/Paket.Core/GitHub.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
open Paket
open Newtonsoft.Json.Linq
open System.IO
open Ionic.Zip

// Gets the sha1 of a branch
let getSHA1OfBranch owner project branch =
Expand Down Expand Up @@ -31,5 +32,44 @@ let downloadDependenciesFile(rootPath,remoteFile:ModuleResolver.ResolvedSourceFi
return text
| None -> return "" }


let ExtractZip(fileName : string, targetFolder) =
let zip = ZipFile.Read(fileName)
Directory.CreateDirectory(targetFolder) |> ignore
for zipEntry in zip do
zipEntry.Extract(targetFolder, ExtractExistingFileAction.OverwriteSilently)

let rec DirectoryCopy(sourceDirName, destDirName, copySubDirs) =
let dir = new DirectoryInfo(sourceDirName)
let dirs = dir.GetDirectories()


if not <| Directory.Exists(destDirName) then
Directory.CreateDirectory(destDirName) |> ignore

for file in dir.GetFiles() do
file.CopyTo(Path.Combine(destDirName, file.Name), false) |> ignore

// If copying subdirectories, copy them and their contents to new location.
if copySubDirs then
for subdir in dirs do
DirectoryCopy(subdir.FullName, Path.Combine(destDirName, subdir.Name), copySubDirs)

/// Gets a single file from github.
let downloadSourceFile(remoteFile:ModuleResolver.ResolvedSourceFile) = downloadFromUrl(None,sprintf "https://github.com/%s/%s/raw/%s/%s" remoteFile.Owner remoteFile.Project remoteFile.Commit remoteFile.Name)
let downloadGithubFiles(remoteFile:ModuleResolver.ResolvedSourceFile,destitnation) = async {
match remoteFile.Name with
| "FULLPROJECT" ->
let fi = FileInfo(destitnation)
let projectPath = fi.Directory.FullName
let zipFile = Path.Combine(projectPath,sprintf "%s.zip" remoteFile.Commit)
do! downloadFromUrl(None,sprintf "https://github.com/%s/%s/archive/%s.zip" remoteFile.Owner remoteFile.Project remoteFile.Commit) zipFile

ExtractZip(zipFile,projectPath)

let source = Path.Combine(projectPath, sprintf "%s-%s" remoteFile.Project remoteFile.Commit)
DirectoryCopy(source,projectPath,true)

Directory.Delete(source,true)

| _ -> return! downloadFromUrl(None,sprintf "https://github.com/%s/%s/raw/%s/%s" remoteFile.Owner remoteFile.Project remoteFile.Commit remoteFile.Name) destitnation
}
5 changes: 2 additions & 3 deletions src/Paket.Core/RestoreProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ let DownloadSourceFile(rootPath, source:ResolvedSourceFile) =
let destination = Path.Combine(rootPath, source.FilePath)

let isInRightVersion =
if not <| File.Exists destination then false
else if not <| versionFile.Exists then false
if not <| versionFile.Exists then false
else source.Commit = File.ReadAllText(versionFile.FullName)

if isInRightVersion then
Expand All @@ -51,7 +50,7 @@ let DownloadSourceFile(rootPath, source:ResolvedSourceFile) =
tracefn "Downloading %s to %s" (source.ToString()) destination

Directory.CreateDirectory(destination |> Path.GetDirectoryName) |> ignore
do! GitHub.downloadSourceFile source destination
do! GitHub.downloadGithubFiles(source,destination)
File.WriteAllText(versionFile.FullName, source.Commit)
}

Expand Down

0 comments on commit f76bc5a

Please sign in to comment.