From 61c263e7feec97193ce6c21f5a8e410c70da3fa6 Mon Sep 17 00:00:00 2001 From: Zero King Date: Tue, 8 Jan 2019 11:30:15 +0000 Subject: [PATCH] Recognize changes in files directory --- ci/portlist.go | 18 +++++++++++++++--- pr/githubapi/pull_request.go | 17 +++++++++++++---- pr/webhook/pull_request.go | 4 ++-- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/ci/portlist.go b/ci/portlist.go index 58e7026..47da43b 100644 --- a/ci/portlist.go +++ b/ci/portlist.go @@ -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]) } } diff --git a/pr/githubapi/pull_request.go b/pr/githubapi/pull_request.go index dae0b0f..03aad94 100644 --- a/pr/githubapi/pull_request.go +++ b/pr/githubapi/pull_request.go @@ -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 diff --git a/pr/webhook/pull_request.go b/pr/webhook/pull_request.go index cc4e7b1..c3e5cc9 100644 --- a/pr/webhook/pull_request.go +++ b/pr/webhook/pull_request.go @@ -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 }