@@ -4,8 +4,6 @@ package test
44
55import (
66 "context"
7- "crypto/sha256"
8- "encoding/hex"
97 "fmt"
108 "os"
119 "regexp"
@@ -30,27 +28,10 @@ import (
3028 "github.com/tektoncd/pipeline/pkg/names"
3129 "gotest.tools/v3/assert"
3230 "gotest.tools/v3/assert/cmp"
33- "gotest.tools/v3/golden"
3431 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3532 "knative.dev/pkg/apis"
3633)
3734
38- func compactCommentTimestamp (ts github.Timestamp ) string {
39- if ts .IsZero () {
40- return "unknown"
41- }
42- return ts .UTC ().Format (time .RFC3339 )
43- }
44-
45- func commentBodyHash (body string ) string {
46- sum := sha256 .Sum256 ([]byte (body ))
47- digest := hex .EncodeToString (sum [:])
48- if len (digest ) > 12 {
49- return digest [:12 ]
50- }
51- return digest
52- }
53-
5435func TestGithubGHEPullRequestBasic (t * testing.T ) {
5536 ctx := context .Background ()
5637 g := & tgithub.PRTest {
@@ -188,78 +169,6 @@ func TestGithubPullRequestWebhook(t *testing.T) {
188169 defer g .TearDown (ctx , t )
189170}
190171
191- func TestGithubGHEPullRequestBadYaml (t * testing.T ) {
192- ctx := context .Background ()
193- g := & tgithub.PRTest {
194- Label : "Github PullRequest Bad Yaml" ,
195- YamlFiles : []string {"testdata/failures/bad-yaml.yaml" },
196- GHE : true ,
197- NoStatusCheck : true ,
198- }
199- g .RunPullRequest (ctx , t )
200- defer g .TearDown (ctx , t )
201-
202- maxLoop := 10
203- for i := 0 ; i < maxLoop ; i ++ {
204- comments , _ , err := g .Provider .Client ().Issues .ListComments (
205- ctx , g .Options .Organization , g .Options .Repo , g .PRNumber ,
206- & github.IssueListCommentsOptions {})
207- assert .NilError (t , err )
208-
209- if len (comments ) > 0 {
210- if len (comments ) > 1 {
211- for _ , comment := range comments {
212- g .Cnx .Clients .Log .Infof ("duplicate comment diagnostic: comment_id=%d created_at=%s updated_at=%s author_login=%s body_hash=%s body_len=%d" ,
213- comment .GetID (),
214- compactCommentTimestamp (comment .GetCreatedAt ()),
215- compactCommentTimestamp (comment .GetUpdatedAt ()),
216- comment .GetUser ().GetLogin (),
217- commentBodyHash (comment .GetBody ()),
218- len (comment .GetBody ()))
219- }
220-
221- const recheckAttempts = 5
222- for attempt := 1 ; attempt <= recheckAttempts && len (comments ) > 1 ; attempt ++ {
223- g .Cnx .Clients .Log .Infof ("recheck duplicate comments attempt=%d/%d current_count=%d" , attempt , recheckAttempts , len (comments ))
224- time .Sleep (2 * time .Second )
225- comments , _ , err = g .Provider .Client ().Issues .ListComments (
226- ctx , g .Options .Organization , g .Options .Repo , g .PRNumber ,
227- & github.IssueListCommentsOptions {})
228- assert .NilError (t , err )
229- }
230-
231- if len (comments ) > 1 {
232- commentSummaries := make ([]string , 0 , len (comments ))
233- for _ , comment := range comments {
234- commentSummaries = append (commentSummaries ,
235- fmt .Sprintf ("%d(created=%s updated=%s)" ,
236- comment .GetID (),
237- compactCommentTimestamp (comment .GetCreatedAt ()),
238- compactCommentTimestamp (comment .GetUpdatedAt ())))
239- }
240- assert .Assert (t , len (comments ) == 1 ,
241- "Should have only one comment created after rechecks, count=%d comments=%s" ,
242- len (comments ), strings .Join (commentSummaries , ", " ))
243- }
244- }
245-
246- if len (comments ) == 0 {
247- g .Cnx .Clients .Log .Infof ("No comments after duplicate recheck, continuing wait loop %d/%d" , i , maxLoop )
248- time .Sleep (6 * time .Second )
249- continue
250- }
251-
252- golden .Assert (t , comments [0 ].GetBody (), strings .ReplaceAll (fmt .Sprintf ("%s.golden" , t .Name ()), "/" , "-" ))
253- return
254- }
255-
256- g .Cnx .Clients .Log .Infof ("Looping %d/%d waiting for a comment to appear" , i , maxLoop )
257- time .Sleep (6 * time .Second )
258- }
259-
260- t .Fatal ("No comments with the pipelinerun error found on the pull request" )
261- }
262-
263172func TestGithubGHEInvalidCELExpressionReportingOnPR (t * testing.T ) {
264173 ctx := context .Background ()
265174 g := & tgithub.PRTest {
0 commit comments