package main import ( "context" "flag" "fmt" "github.com/google/go-github/github" "log" "os" "path" ) var ( owner = flag.String("o", "alpinelinux", "GitHub username of the repository owner") repo = flag.String("r", "aports", "Name of the GitHub repository") ) func usage() { fmt.Fprintf(flag.CommandLine.Output(), "USAGE: %s [FLAGS] [APORT]\n\n"+ "The following flags are supported:\n\n", os.Args[0]) flag.PrintDefaults() } func main() { flag.Usage = usage flag.Parse() var aport string if flag.NArg() >= 1 { aport = flag.Arg(0) } // if APKBUILD exists in current directory, then we limit the search if _, err := os.Stat("APKBUILD"); err == nil { dir, err := os.Getwd() if err != nil { log.Fatal(err) } aport = path.Base(dir) fmt.Println("searching for: ", aport) } if aport == "" { usage() os.Exit(1) } // TODO: allow set authentication client := github.NewClient(nil) ctx := context.Background() opt := &github.PullRequestListOptions{ ListOptions: github.ListOptions{PerPage: 200}, } for { query := fmt.Sprintf("%s type:pr in:title is:open repo:%s/%s", aport, *owner, *repo) res, resp, err := client.Search.Issues(ctx, query, nil) if err != nil { log.Fatal(err) } for _, issue := range res.Issues { fmt.Println(*issue.Number, *issue.User.Login, *issue.HTMLURL, *issue.Title) } if resp.NextPage == 0 { break } opt.Page = resp.NextPage } }