aboutsummaryrefslogtreecommitdiffstats
path: root/aports-ghpr.go
blob: 67d6f947c0651391b694dcd654e921420f8ffffd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
	}
}