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

Add GitHub API to create a pull request. #2724

Merged
merged 2 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
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
27 changes: 20 additions & 7 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ open Fake.Core.TargetOperators
open System.Net.Http
open Microsoft.Deployment.DotNet.Releases
open Fake.JavaScript
open Octokit
open Octokit.Internal

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

// Git.Staging.stageAll gitDirectory
// Git.Commit.exec gitDirectory (sprintf "Bump version to %s" simpleVersion)
// let branch = "bump-version-to-" + simpleVersion
// Git.Branches.checkoutNewBranch gitDirectory "origin" branch
// Git.Branches.pushBranch gitDirectory "origin" branch

Git.Branches.tag gitDirectory simpleVersion
Git.Branches.pushTag gitDirectory url simpleVersion

Expand All @@ -1033,7 +1029,24 @@ Target.create "GitHubRelease" (fun _ ->
|> GitHub.draftNewRelease githubReleaseUser gitName simpleVersion (release.SemVer.PreRelease <> None) release.Notes
|> GitHub.uploadFiles files
|> GitHub.publishDraft
|> Async.RunSynchronously)
|> Async.RunSynchronously

let bumpVersionMessage = (sprintf "Bump version to %s" simpleVersion)
let branch = "bump-version-to-" + simpleVersion
Git.Staging.stageAll ".config"
Git.Commit.exec gitDirectory bumpVersionMessage
Git.Branches.checkoutNewBranch gitDirectory "master" branch
Git.Branches.pushBranch gitDirectory "origin" branch

// when we release the GitHub module, this will be replaced with GitHub.createPullRequest API
let pullRequest = new NewPullRequest(bumpVersionMessage, branch, "master")
let pullRequestTask (client: GitHubClient) =
client.PullRequest.Create(githubReleaseUser, gitName, pullRequest) |> Async.AwaitTask |> Async.RunSynchronously

GitHub.createClientWithToken token
|> Async.RunSynchronously
|> pullRequestTask
|> ignore)

// ----------------------------------------------------------------------------------------------------
// Artifact targets; Preparing artifacts for release from existing artifacts
Expand Down
21 changes: 21 additions & 0 deletions src/app/Fake.Api.GitHub/GitHub.fs
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,24 @@ module GitHub =

()
}

/// <summary>
/// Create a pull request on the specified repository.
/// </summary>
///
/// <param name="owner">The owner of the repository - GitHub handle</param>
/// <param name="repoName">The repository name</param>
/// <param name="pullRequest">The pull request information, including source and destination branches</param>
/// <param name="client">The GitHub client to use for communication</param>
/// <example>
/// <code lang="fsharp">
/// let pullRequest = new PullRequest("Bump FAKE runner version", "version-branch", "master")
///
/// GitHub.createClientWithToken token
/// |> GitHub.createPullRequest "fsprojects" "fake" pullRequest
/// |> Async.RunSynchronously
/// </code>
/// </example>
let createPullRequest owner repoName (pullRequest: NewPullRequest) (client: Async<GitHubClient>) =
retryWithArg 5 client
<| fun client' -> async { return Async.AwaitTask <| client'.PullRequest.Create(owner, repoName, pullRequest) }