Skip to content

Instantly share code, notes, and snippets.

@Vany
Last active August 12, 2019 16:56
Show Gist options
  • Save Vany/6f85bc2a76d87b3718bf3335a4803dc5 to your computer and use it in GitHub Desktop.
Save Vany/6f85bc2a76d87b3718bf3335a4803dc5 to your computer and use it in GitHub Desktop.
automaticly merge insolar's puulrequest
// GPL
// go run merger.go "tokentokentoken" insolar/insolar/<prnum>
package main
import (
"context"
"fmt"
"github.com/google/go-github/github"
"golang.org/x/oauth2"
"os"
"strconv"
"strings"
"time"
)
func main() {
ctx := context.Background()
token := os.Args[1]
spl := strings.Split(os.Args[2], "/")
proj := spl[0]
repo := spl[1]
prnum, err := strconv.Atoi(spl[2])
asserterr(err)
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
tc := oauth2.NewClient(ctx, ts)
client := github.NewClient(tc)
for {
pr, _, err := client.PullRequests.Get(ctx, proj, repo, prnum)
asserterr(err)
fmt.Printf("%d : %s\n", *pr.Number, *pr.MergeableState)
ms := *pr.MergeableState
if ms == "blocked" || ms == "unknown" {
time.Sleep(10 * time.Second)
continue
}
prmr, _, err := client.PullRequests.Merge(ctx, "insolar", "insolar", prnum, "automerge", nil)
asserterr(err)
fmt.Printf("%#v\n", prmr)
}
}
func asserterr(e error) {
if e == nil {
return
}
panic(e)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment