github.com/shashidharatd/test-infra@v0.0.0-20171006011030-71304e1ca560/mungegithub/mungers/comment-deleter-jenkins.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package mungers 18 19 import ( 20 "regexp" 21 22 "k8s.io/test-infra/mungegithub/github" 23 24 "github.com/golang/glog" 25 githubapi "github.com/google/go-github/github" 26 ) 27 28 const ( 29 commentDeleterJenkinsName = "comment-deleter-jenkins" 30 commentRegexpStr = `GCE e2e( test)? build/test \*\*(passed|failed)\*\* for commit [[:xdigit:]]+\. 31 \* \[Build Log\]\([^)]+\) 32 \* \[Test Artifacts\]\([^)]+\) 33 \* \[Internal Jenkins Results\]\([^)]+\)` 34 commentRegexpStrUpdated = `GCE e2e( test)? build/test \*\*(passed|failed)\*\* for commit [[:xdigit:]]+\. 35 \* \[Test Results\]\([^)]+\) 36 \* \[Build Log\]\([^)]+\) 37 \* \[Test Artifacts\]\([^)]+\) 38 \* \[Internal Jenkins Results\]\([^)]+\)` 39 ) 40 41 var ( 42 _ = glog.Infof 43 //Changed so that this variable is true if it compiles old or updated 44 commentRegexp = regexp.MustCompile(commentRegexpStr) 45 updatedCommentRegexp = regexp.MustCompile(commentRegexpStrUpdated) 46 ) 47 48 // CommentDeleterJenkins looks for jenkins comments which are no longer useful 49 // and deletes them 50 type CommentDeleterJenkins struct{} 51 52 func init() { 53 c := CommentDeleterJenkins{} 54 RegisterStaleIssueComments(c) 55 } 56 57 func isJenkinsTestComment(body string) bool { 58 return updatedCommentRegexp.MatchString(body) || commentRegexp.MatchString(body) 59 } 60 61 // StaleIssueComments returns a slice of stale issue comments. 62 func (CommentDeleterJenkins) StaleIssueComments(obj *github.MungeObject, comments []*githubapi.IssueComment) []*githubapi.IssueComment { 63 out := []*githubapi.IssueComment{} 64 var last *githubapi.IssueComment 65 66 for i := range comments { 67 comment := comments[i] 68 if !jenkinsBotComment(comment) { 69 continue 70 } 71 72 if !isJenkinsTestComment(*comment.Body) { 73 continue 74 } 75 if last != nil { 76 out = append(out, last) 77 } 78 last = comment 79 } 80 return out 81 }