Recognize changes in files directory

This commit is contained in:
Zero King
2019-01-08 11:30:15 +00:00
parent b697d64841
commit 61c263e7fe
3 changed files with 30 additions and 9 deletions
+15 -3
View File
@@ -6,7 +6,7 @@ import (
"regexp"
)
// List second part of path of Portfiles that was changed in the PR.
// List second part of path of Portfiles (or port files) that was changed in the PR.
func GetChangedPortList() ([]string, error) {
gitCmd := exec.Command("git", "diff", "--name-status", "macports/master...HEAD", "--")
stdout, err := gitCmd.StdoutPipe()
@@ -17,11 +17,23 @@ func GetChangedPortList() ([]string, error) {
return nil, err
}
ports := make([]string, 0, 1)
gitRegexp := regexp.MustCompile(`[AM]\t[^\._/][^/]*/([^/]+)/Portfile`) // Ignore hidden and _* top directories
portsFound := make(map[string]bool)
// Ignore hidden and _* top directories
portGrep := regexp.MustCompile(
`[AM]\t[^\._/][^/]*/([^/]+)/(Portfile|files/)`)
renameGrep := regexp.MustCompile(
`R[0-9]*\t[^\t]*\t[^\._/][^/]*/([^/]+)/(Portfile|files/)`)
stdoutScanner := bufio.NewScanner(stdout)
for stdoutScanner.Scan() {
line := stdoutScanner.Text()
if match := gitRegexp.FindStringSubmatch(line); match != nil {
var match []string
if match = portGrep.FindStringSubmatch(line); match == nil {
continue
} else if match = renameGrep.FindStringSubmatch(line); match == nil {
continue
}
if _, ok := portsFound[match[1]]; !ok {
portsFound[match[1]] = true
ports = append(ports, match[1])
}
}
+13 -4
View File
@@ -33,16 +33,25 @@ func (client *githubClient) ListChangedPortsAndFiles(owner, repo string, number
opt.Page = resp.NextPage
}
portfileRegexp := regexp.MustCompile(`[^\._/][^/]*/([^/]+)/Portfile`) // Ignore hidden and _* top directories
portGrep := regexp.MustCompile(`[^\._/][^/]*/([^/]+)/(Portfile|files/)`) // Ignore hidden and _* top directories
portsFound := make(map[string]int)
for _, file := range allFiles {
fileName := *file.Filename
if *file.Status == "renamed" {
fileName = *file.PreviousFilename
}
match := portfileRegexp.FindStringSubmatch(fileName)
match := portGrep.FindStringSubmatch(fileName)
if match != nil {
ports = append(ports, match[1])
commitFiles = append(commitFiles, file)
if idx, ok := portsFound[match[1]]; !ok {
ports = append(ports, match[1])
commitFiles = append(commitFiles, file)
portsFound[match[1]] = len(ports) - 1
} else {
if match[2] == "Portfile" {
commitFiles[idx] = file
}
}
}
}
return
+2 -2
View File
@@ -61,8 +61,8 @@ func (receiver *Receiver) processPullRequest(event *github.PullRequestEvent) {
for i, port := range ports {
portMaintainer, err := receiver.dbHelper.GetPortMaintainer(port)
if err != nil {
// TODO: handle submission of duplicate ports
if err.Error() == "port not found" && *files[i].Status == "added" {
// TODO: warn about submission of duplicate ports in different category
if err.Error() == "port not found" && !strings.Contains(*files[i].Filename, "/files/") && *files[i].Status == "added" {
isSubmission = true
continue
}