You've already forked mpbot-github
mirror of
https://github.com/macports/mpbot-github.git
synced 2026-03-31 14:46:03 -07:00
Parse maintainer info
This commit is contained in:
40
pr/dbutil.go
40
pr/dbutil.go
@@ -3,15 +3,21 @@ package pr
|
||||
import (
|
||||
"database/sql"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
type Maintainer struct {
|
||||
primary string
|
||||
others []string
|
||||
openMaintainer bool
|
||||
noMaintainer bool
|
||||
GithubHandle string
|
||||
Email string
|
||||
}
|
||||
|
||||
type PortMaintainer struct {
|
||||
Primary *Maintainer
|
||||
Others []*Maintainer
|
||||
OpenMaintainer bool
|
||||
NoMaintainer bool
|
||||
}
|
||||
|
||||
var tracDB *sql.DB
|
||||
@@ -20,6 +26,7 @@ var wwwDB *sql.DB
|
||||
// Create connections to DBs
|
||||
func init() {
|
||||
var err error
|
||||
// TODO: use real dbname or read from env/flag
|
||||
tracDB, err = sql.Open("postgres", "host=/tmp dbname=l2dy")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -47,8 +54,7 @@ func GetGitHubHandle(email string) (string, error) {
|
||||
|
||||
// GetMaintainer returns the maintainers of a port,
|
||||
// the primary maintainer is always the first in the slice.
|
||||
// TODO: parse multi identity per maintainer and email
|
||||
func GetMaintainer(port string) (*Maintainer, error) {
|
||||
func GetMaintainer(port string) (*PortMaintainer, error) {
|
||||
rows, err := wwwDB.Query("SELECT maintainer, is_primary "+
|
||||
"FROM public.maintainers "+
|
||||
"WHERE portfile = $1", port)
|
||||
@@ -57,7 +63,7 @@ func GetMaintainer(port string) (*Maintainer, error) {
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
maintainer := new(Maintainer)
|
||||
maintainer := new(PortMaintainer)
|
||||
maintainerCursor := ""
|
||||
isPrimary := false
|
||||
|
||||
@@ -66,11 +72,27 @@ func GetMaintainer(port string) (*Maintainer, error) {
|
||||
return nil, err
|
||||
}
|
||||
if isPrimary {
|
||||
maintainer.primary = maintainerCursor
|
||||
maintainer.Primary = parseMaintainer(maintainerCursor)
|
||||
} else {
|
||||
maintainer.others = append(maintainer.others, maintainerCursor)
|
||||
maintainer.Others = append(maintainer.Others, parseMaintainer(maintainerCursor))
|
||||
}
|
||||
}
|
||||
|
||||
return maintainer, nil
|
||||
}
|
||||
|
||||
func parseMaintainer(maintainerFullString string) *Maintainer {
|
||||
maintainerStrings := strings.Split(maintainerFullString, " ")
|
||||
maintainer := new(Maintainer)
|
||||
for _, maintainerString := range maintainerStrings {
|
||||
if strings.HasPrefix(maintainerString, "@") {
|
||||
maintainer.GithubHandle = maintainerString[1:]
|
||||
} else if strings.Count(maintainerString, ":") == 1 {
|
||||
emailParts := strings.Split(maintainerString, ":")
|
||||
maintainer.Email = emailParts[1] + "@" + emailParts[0]
|
||||
} else {
|
||||
maintainer.Email = maintainerString + "@macports.org"
|
||||
}
|
||||
}
|
||||
return maintainer
|
||||
}
|
||||
|
||||
23
pr/githubapi/pull_request.go
Normal file
23
pr/githubapi/pull_request.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package githubapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/google/go-github/github"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
func ListChangedPorts(number int) []string {
|
||||
client := github.NewClient(nil)
|
||||
files, _, err := client.PullRequests.ListFiles(context.Background(), "macports-staging", "macports-ports", number, nil)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
ports := make([]string, 0, 1)
|
||||
portfileRegexp := regexp.MustCompile(`[^\._/][^/]*/([^/]+)/Portfile`)
|
||||
for _, file := range files {
|
||||
if match := portfileRegexp.FindStringSubmatch(*file.Filename); match != nil {
|
||||
ports = append(ports, match[1])
|
||||
}
|
||||
}
|
||||
return ports
|
||||
}
|
||||
@@ -2,9 +2,10 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"github.com/macports/mpbot-github/pr/webhook"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/macports/mpbot-github/pr/webhook"
|
||||
)
|
||||
|
||||
// Entry point of the PR bot
|
||||
|
||||
Reference in New Issue
Block a user