-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ffc5a8
commit 0ef5f0f
Showing
3 changed files
with
74 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// This file is a copy of the one included in FAKE, with | ||
// use of retry removed, as this causes a NullPointerException | ||
// on Mono. | ||
|
||
#I __SOURCE_DIRECTORY__ | ||
#r @"../packages/Octokit/lib/net45/Octokit.dll" | ||
|
||
open Octokit | ||
open System | ||
open System.IO | ||
|
||
type Draft = | ||
{ Client : GitHubClient | ||
Owner : string | ||
Project : string | ||
DraftRelease : Release } | ||
|
||
let rec private retry count asyncF = | ||
async { | ||
try | ||
return! asyncF | ||
with _ when count > 0 -> return! retry (count - 1) asyncF | ||
} | ||
|
||
|
||
let createClient user password = | ||
async { | ||
let github = new GitHubClient(new ProductHeaderValue("FAKE")) | ||
github.Credentials <- Credentials(user, password) | ||
return github | ||
} | ||
|
||
let createDraft owner project version prerelease (notes: string seq) (client : Async<GitHubClient>) = | ||
async { | ||
let data = new NewRelease(version) | ||
data.Name <- version | ||
data.Body <- String.Join(Environment.NewLine, notes) | ||
data.Draft <- true | ||
data.Prerelease <- prerelease | ||
let! client' = client | ||
let! draft = Async.AwaitTask <| client'.Release.Create(owner, project, data) | ||
printfn "Created draft release id %d" draft.Id | ||
return { Client = client' | ||
Owner = owner | ||
Project = project | ||
DraftRelease = draft } | ||
} | ||
|
||
let uploadFile fileName (draft : Async<Draft>) = | ||
async { | ||
let fi = FileInfo(fileName) | ||
let archiveContents = File.OpenRead(fi.FullName) | ||
let assetUpload = new ReleaseAssetUpload(fi.Name,"application/octet-stream",archiveContents,Nullable<TimeSpan>()) | ||
let! draft' = draft | ||
let! asset = Async.AwaitTask <| draft'.Client.Release.UploadAsset(draft'.DraftRelease, assetUpload) | ||
printfn "Uploaded %s" asset.Name | ||
return draft' | ||
} | ||
|
||
let releaseDraft (draft : Async<Draft>) = | ||
async { | ||
let! draft' = draft | ||
let update = draft'.DraftRelease.ToUpdate() | ||
update.Draft <- Nullable<bool>(false) | ||
let! released = Async.AwaitTask <| draft'.Client.Release.Edit(draft'.Owner, draft'.Project, draft'.DraftRelease.Id, update) | ||
printfn "Released %d on github" released.Id | ||
} |