Skip to content

Commit

Permalink
add ability to create github draft pull requests
Browse files Browse the repository at this point in the history
  • Loading branch information
rgarcia authored and nathanleiby committed May 15, 2021
1 parent f9d9392 commit da8630b
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 13 deletions.
3 changes: 3 additions & 0 deletions cmd/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ mp plan -b microplaning -m 'microplane fun' -r app-service -- python /absolute/p
isSingleRepo = len(repos) == 1

parallelismLimit, err = cmd.Flags().GetInt64("parallelism")
if err != nil {
log.Fatal(err)
}
log.Printf("planning %d repos with parallelism limit [%d]", len(repos), parallelismLimit)
err = parallelizeLimited(repos, planOneRepo, parallelismLimit)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ var pushFlagAssignee string
var pushFlagThrottle string
var pushFlagBodyFile string
var pushFlagLabels []string
var pushFlagDraft bool

// rate limits the # of git pushes. used to prevent load on CI system
var pushThrottle *time.Ticker

var prAssignee string
var prBody string
var prLabels []string
var prDraft bool

var pushCmd = &cobra.Command{
Use: "push",
Expand Down Expand Up @@ -75,6 +77,12 @@ var pushCmd = &cobra.Command{
prLabels = labels
}

draft, err := cmd.Flags().GetBool("draft")
if err != nil {
log.Fatal(err)
}
prDraft = draft

repos, err := whichRepos(cmd)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -130,6 +138,7 @@ func pushOneRepo(r lib.Repo, ctx context.Context) error {
PRAssignee: prAssignee,
BranchName: planOutput.BranchName,
Labels: prLabels,
Draft: prDraft,
}
var output push.Output
var err error
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func init() {
pushCmd.Flags().StringVarP(&pushFlagAssignee, "assignee", "a", "", "Github user to assign the PR to")
pushCmd.Flags().StringVarP(&pushFlagBodyFile, "body-file", "b", "", "body of PR")
pushCmd.Flags().StringSliceVarP(&pushFlagLabels, "labels", "l", nil, "labels to attach to PR")
pushCmd.Flags().BoolVarP(&pushFlagDraft, "draft", "d", false, "push a draft pull request (only supported for github)")

rootCmd.AddCommand(statusCmd)
statusCmd.Flags().BoolP("sync", "s", false, "Sync workflow status with repo origin")
Expand Down
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ module github.com/Clever/microplane
go 1.15

require (
github.com/GeertJohan/fgt v0.0.0-20160120143236-262f7b11eec0 // indirect
github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c // indirect
github.com/facebookgo/errgroup v0.0.0-20160209021148-779c8d7ef069
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 // indirect
github.com/fatih/color v1.10.0
github.com/google/go-github v17.0.0+incompatible
github.com/juju/errors v0.0.0-20200330140219-3fe23663418f // indirect
github.com/google/go-github/v35 v35.0.0
github.com/juju/testing v0.0.0-20210324180055-18c50b0c2098 // indirect
github.com/nathanleiby/diffparser v0.0.0-20180103231304-936553ce5db1
github.com/spf13/cobra v1.1.3
github.com/stretchr/testify v1.7.0
github.com/waigani/diffparser v0.0.0-20190828052634-7391f219313d // indirect
github.com/xanzy/go-gitlab v0.44.0
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
)
90 changes: 86 additions & 4 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions initialize/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/Clever/microplane/lib"
"github.com/google/go-github/github"
"github.com/google/go-github/v35/github"
gitlab "github.com/xanzy/go-gitlab"
)

Expand Down Expand Up @@ -199,7 +199,7 @@ func githubRepoSearch(p *lib.Provider, query string) ([]lib.Repo, error) {

for _, repoResult := range result.Repositories {
numProcessedResults = numProcessedResults + 1
allRepos[*repoResult.Name] = &repoResult
allRepos[*repoResult.Name] = repoResult
}

incompleteResults := result.GetIncompleteResults()
Expand Down
2 changes: 1 addition & 1 deletion lib/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"os"

"github.com/google/go-github/github"
"github.com/google/go-github/v35/github"
"github.com/xanzy/go-gitlab"
"golang.org/x/oauth2"
)
Expand Down
2 changes: 1 addition & 1 deletion merge/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"github.com/Clever/microplane/lib"
"github.com/google/go-github/github"
"github.com/google/go-github/v35/github"
)

// Input to Push()
Expand Down
5 changes: 4 additions & 1 deletion push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/Clever/microplane/lib"
"github.com/google/go-github/github"
"github.com/google/go-github/v35/github"
)

// Command represents a command to run.
Expand Down Expand Up @@ -39,6 +39,8 @@ type Input struct {
BranchName string
// Labels
Labels []string
// Draft controls whether it should be a draft PR
Draft bool
}

// Output from Push()
Expand Down Expand Up @@ -122,6 +124,7 @@ func GithubPush(ctx context.Context, input Input, repoLimiter *time.Ticker, push
Body: &body,
Head: &head,
Base: &base,
Draft: &input.Draft,
}, repoLimiter, pushLimiter)
if err != nil {
return Output{Success: false}, err
Expand Down

0 comments on commit da8630b

Please sign in to comment.