Skip to content

Commit 10f79f8

Browse files
authored
Merge pull request #2724 from FoothillSolutions/master
Add GitHub API to create a pull request.
2 parents 832e9f1 + b0b767e commit 10f79f8

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

build.fsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ open Fake.Core.TargetOperators
5959
open System.Net.Http
6060
open Microsoft.Deployment.DotNet.Releases
6161
open Fake.JavaScript
62+
open Octokit
63+
open Octokit.Internal
6264

6365
// ****************************************************************************************************
6466
// ------------------------------------------- Definitions -------------------------------------------
@@ -1011,12 +1013,6 @@ Target.create "GitHubRelease" (fun _ ->
10111013
Git.CommandHelper.directRunGitCommandAndFail gitDirectory "config user.email [email protected]"
10121014
Git.CommandHelper.directRunGitCommandAndFail gitDirectory "config user.name \"Matthias Dittrich\""
10131015

1014-
// Git.Staging.stageAll gitDirectory
1015-
// Git.Commit.exec gitDirectory (sprintf "Bump version to %s" simpleVersion)
1016-
// let branch = "bump-version-to-" + simpleVersion
1017-
// Git.Branches.checkoutNewBranch gitDirectory "origin" branch
1018-
// Git.Branches.pushBranch gitDirectory "origin" branch
1019-
10201016
Git.Branches.tag gitDirectory simpleVersion
10211017
Git.Branches.pushTag gitDirectory url simpleVersion
10221018

@@ -1033,7 +1029,24 @@ Target.create "GitHubRelease" (fun _ ->
10331029
|> GitHub.draftNewRelease githubReleaseUser gitName simpleVersion (release.SemVer.PreRelease <> None) release.Notes
10341030
|> GitHub.uploadFiles files
10351031
|> GitHub.publishDraft
1036-
|> Async.RunSynchronously)
1032+
|> Async.RunSynchronously
1033+
1034+
let bumpVersionMessage = (sprintf "Bump version to %s" simpleVersion)
1035+
let branch = "bump-version-to-" + simpleVersion
1036+
Git.Staging.stageAll ".config"
1037+
Git.Commit.exec gitDirectory bumpVersionMessage
1038+
Git.Branches.checkoutNewBranch gitDirectory "master" branch
1039+
Git.Branches.pushBranch gitDirectory "origin" branch
1040+
1041+
// when we release the GitHub module, this will be replaced with GitHub.createPullRequest API
1042+
let pullRequest = new NewPullRequest(bumpVersionMessage, branch, "master")
1043+
let pullRequestTask (client: GitHubClient) =
1044+
client.PullRequest.Create(githubReleaseUser, gitName, pullRequest) |> Async.AwaitTask |> Async.RunSynchronously
1045+
1046+
GitHub.createClientWithToken token
1047+
|> Async.RunSynchronously
1048+
|> pullRequestTask
1049+
|> ignore)
10371050

10381051
// ----------------------------------------------------------------------------------------------------
10391052
// Artifact targets; Preparing artifacts for release from existing artifacts

src/app/Fake.Api.GitHub/GitHub.fs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,3 +445,24 @@ module GitHub =
445445

446446
()
447447
}
448+
449+
/// <summary>
450+
/// Create a pull request on the specified repository.
451+
/// </summary>
452+
///
453+
/// <param name="owner">The owner of the repository - GitHub handle</param>
454+
/// <param name="repoName">The repository name</param>
455+
/// <param name="pullRequest">The pull request information, including source and destination branches</param>
456+
/// <param name="client">The GitHub client to use for communication</param>
457+
/// <example>
458+
/// <code lang="fsharp">
459+
/// let pullRequest = new PullRequest("Bump FAKE runner version", "version-branch", "master")
460+
///
461+
/// GitHub.createClientWithToken token
462+
/// |> GitHub.createPullRequest "fsprojects" "fake" pullRequest
463+
/// |> Async.RunSynchronously
464+
/// </code>
465+
/// </example>
466+
let createPullRequest owner repoName (pullRequest: NewPullRequest) (client: Async<GitHubClient>) =
467+
retryWithArg 5 client
468+
<| fun client' -> async { return Async.AwaitTask <| client'.PullRequest.Create(owner, repoName, pullRequest) }

0 commit comments

Comments
 (0)