Skip to content

Commit

Permalink
Fixed match methods for documents
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiao committed Jan 4, 2021
1 parent abbd163 commit f9632cd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
3 changes: 2 additions & 1 deletion cmd/contributions.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func main() {
documentsList := documentsCmd.Bool("list", false, "false")
documentQuery := documentsCmd.String("query", "", "")
documentFilter := documentsCmd.String("filter", "", "")
documentMatch := documentsCmd.String("match", "", "")

jenkinsCmd := flag.NewFlagSet("jenkins", flag.ExitOnError)
jenkinsBranch := jenkinsCmd.String("branch", "", "")
Expand Down Expand Up @@ -48,7 +49,7 @@ func main() {

case "docs":
documentsCmd.Parse(os.Args[2:])
ShowDocuments(&confFile, documentsList, documentQuery, documentFilter)
ShowDocuments(&confFile, documentsList, documentQuery, documentFilter, documentMatch)

case "jenkins":
jenkinsCmd.Parse(os.Args[2:])
Expand Down
43 changes: 36 additions & 7 deletions cmd/documents.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,19 @@ import (
"github.com/uber/gonduit/core"
)

// Manage the options for differential / arcanist requests
// Verify if a string match a specific criterias with filters such as str1|str2
func matchSequenceStr(strEntry *string, filter *string) bool {
for _, line := range strings.Split(*filter, "|") {
if strings.Contains(*strEntry, line) {
return true
}
}
return false

func ShowDocuments(confFile *config.ConfGoPath, documentList *bool, documentQuery *string, documentFilter *string) {
}

// Management options for documents
func ShowDocuments(confFile *config.ConfGoPath, documentList *bool, documentQuery *string, documentFilter *string, documentFilterBoolean *string) {
fmt.Println("\n⭐ Starting pha-go with documents command.")
fmt.Println("\t List: ", *documentList)

Expand All @@ -27,11 +37,30 @@ func ShowDocuments(confFile *config.ConfGoPath, documentList *bool, documentQuer

docs := documents.LookForDocument(client, documentQuery)
for _, v := range docs.Data {
fmt.Println("\t🐊 Phid: ", v.Phid)
for _, line := range strings.Split(strings.TrimSuffix(v.Attachments.Content.Content.Raw, "\n"), "\n") {
fmt.Println(line)
re := regexp.MustCompile(*documentFilter)
fmt.Println(re.FindStringSubmatch(line))

reTitle := regexp.MustCompile("^(.*?) Support$")
matchTitle := reTitle.FindStringSubmatch(v.Attachments.Content.Title)

if len(matchTitle) > 1 && matchSequenceStr(&matchTitle[1], documentFilterBoolean) {
fmt.Println("\t🐊 Customer: ", v.Attachments.Content.Title)
for _, line := range strings.Split(strings.TrimSuffix(v.Attachments.Content.Content.Raw, "\n"), "\n") {
fmt.Println(line)
re := regexp.MustCompile("^## (.*?)$")
re2 := regexp.MustCompile("^\\=\\=\\ (.*?) \\=\\=$")

match := re.FindStringSubmatch(line)

if len(match) > 1 && strings.Contains(match[1], *documentFilter) == false {
break

} else {
match2 := re2.FindStringSubmatch(line)
if len(match2) > 1 && strings.Contains(match2[1], *documentFilter) == false {
break
}
}

}
}
}
}

0 comments on commit f9632cd

Please sign in to comment.