Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only return Algorithm Week PRs #1463

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion algorithms/collector/actions/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ func GetPullRequests(p params) ([]*github.PullRequest, error) {
},
})

return pullRequests, err
filteredPullRequets := make([]*github.PullRequest, 0)
for _, pr := range pullRequests {
if isAlgorithmPR(*pr.Body) {
filteredPullRequets = append(filteredPullRequets, pr)
}
}

return filteredPullRequets, err
}

// CommentPR adds a comment in PR
Expand Down
12 changes: 12 additions & 0 deletions algorithms/collector/actions/utils.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
package actions

import "strings"

func ptrStr(s string) *string {
return &s
}

func isAlgorithmPR(body string) bool {
patterns := []string{"- [ ] Problem", "- [x] Problem"}
for _, pattern := range patterns {
if strings.Contains(body, pattern) {
return true
}
}
return false
}
20 changes: 20 additions & 0 deletions algorithms/collector/actions/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,23 @@ func Test_ptrStr(t *testing.T) {
t.Errorf("ptrStr() returns wrong ptr string (nil)")
}
}

func Test_isAlgorithmPR(t *testing.T) {
type Test struct {
input string
output bool
}

tests := []Test{
{input: "This is a non-algorithm PR\nIt has multiple lines", output: false},
{input: "This is a correct one\n- [ ] Problem 1\n- [ ] Problem 2", output: true},
{input: "This is also a correct one\n- [ ] Problem 1\n- [x] Problem 2", output: true},
}

for _, test := range tests {
actual := isAlgorithmPR(test.input)
if actual != test.output {
t.Errorf("isAlgorithmPR() returns wrong result for string: '%s'", test.input)
}
}
}