Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds createClientWithToken & createRelease to Octokit.fsx #913

Merged
merged 1 commit into from
Aug 18, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions modules/Octokit/Octokit.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ open Octokit
open System
open System.IO

type Draft =
type Draft =
{ Client : GitHubClient
Owner : string
Project : string
Expand All @@ -25,32 +25,42 @@ let rec private retry count asyncF =
with _ when count > 0 -> return! retry (count - 1) asyncF
}


let createClient user password =
async {
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 createClientWithToken token =
async {
let github = new GitHubClient(new ProductHeaderValue("FAKE"))
github.Credentials <- Credentials(token)
return github
}

let private makeRelease draft owner project version prerelease (notes:seq<string>) (client : Async<GitHubClient>) =
async {
let data = new NewRelease(version)
data.Name <- version
data.Body <- String.Join(Environment.NewLine, notes)
data.Draft <- true
data.Draft <- draft
data.Prerelease <- prerelease
let! client' = client
let! draft = Async.AwaitTask <| client'.Release.Create(owner, project, data)
printfn "Created draft release id %d" draft.Id
let draftWord = if data.Draft then " draft" else ""
printfn "Created%s release id %d" draftWord draft.Id
return { Client = client'
Owner = owner
Project = project
DraftRelease = draft }
} |> retry 5

let uploadFile fileName (draft : Async<Draft>) =
async {
let createDraft owner project version prerelease notes client = makeRelease true owner project version prerelease notes client
let createRelease owner project version prerelease notes client = makeRelease false owner project version prerelease notes client

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>())
Expand All @@ -60,8 +70,8 @@ let uploadFile fileName (draft : Async<Draft>) =
return draft'
} |> retry 5

let releaseDraft (draft : Async<Draft>) =
async {
let releaseDraft (draft : Async<Draft>) =
async {
let! draft' = draft
let update = draft'.DraftRelease.ToUpdate()
update.Draft <- Nullable<bool>(false)
Expand Down