@@ -337,7 +337,34 @@ func buildIssueQueries(
337337 return existingIssueQuery , relatedIssuesQuery
338338}
339339
340- func (p * poster ) post (origCtx context.Context , formatter IssueFormatter , req PostRequest ) error {
340+ type TestFailureType string
341+
342+ const (
343+ TestFailureNewIssue = TestFailureType ("new_issue" )
344+ TestFailureIssueComment = TestFailureType ("comment" )
345+ )
346+
347+ // TestFailureIssue encapsulates data about an issue created or
348+ // changed in order to report a test failure.
349+ type TestFailureIssue struct {
350+ Type TestFailureType
351+ ID int
352+ }
353+
354+ func (tfi TestFailureIssue ) String () string {
355+ switch tfi .Type {
356+ case TestFailureNewIssue :
357+ return fmt .Sprintf ("created new GitHub issue #%d" , tfi .ID )
358+ case TestFailureIssueComment :
359+ return fmt .Sprintf ("commented on existing GitHub issue #%d" , tfi .ID )
360+ default :
361+ return fmt .Sprintf ("[unrecognized test failure type %q, ID=%d]" , tfi .Type , tfi .ID )
362+ }
363+ }
364+
365+ func (p * poster ) post (
366+ origCtx context.Context , formatter IssueFormatter , req PostRequest ,
367+ ) (* TestFailureIssue , error ) {
341368 ctx := & postCtx {Context : origCtx }
342369 data := p .templateData (
343370 ctx ,
@@ -402,6 +429,7 @@ func (p *poster) post(origCtx context.Context, formatter IssueFormatter, req Pos
402429 createLabels := []string {RobotLabel }
403430 createLabels = append (createLabels , req .labels ()... )
404431 createLabels = append (createLabels , releaseLabel (p .Branch ))
432+ var result TestFailureIssue
405433 if foundIssue == nil {
406434 issueRequest := github.IssueRequest {
407435 Title : & title ,
@@ -411,11 +439,13 @@ func (p *poster) post(origCtx context.Context, formatter IssueFormatter, req Pos
411439 }
412440 issue , _ , err := p .createIssue (ctx , p .Org , p .Repo , & issueRequest )
413441 if err != nil {
414- return errors .Wrapf (err , "failed to create GitHub issue %s" ,
442+ return nil , errors .Wrapf (err , "failed to create GitHub issue %s" ,
415443 github .Stringify (issueRequest ))
416444 }
417445
418- p .l .Printf ("created GitHub issue #%d" , * issue .Number )
446+ result .Type = TestFailureNewIssue
447+ result .ID = * issue .Number
448+ p .l .Printf ("%s" , result )
419449 if req .ProjectColumnID != 0 {
420450 _ , _ , err := p .createProjectCard (ctx , int64 (req .ProjectColumnID ), & github.ProjectCardOptions {
421451 ContentID : * issue .ID ,
@@ -433,14 +463,16 @@ func (p *poster) post(origCtx context.Context, formatter IssueFormatter, req Pos
433463 comment := github.IssueComment {Body : github .String (body )}
434464 if _ , _ , err := p .createComment (
435465 ctx , p .Org , p .Repo , * foundIssue , & comment ); err != nil {
436- return errors .Wrapf (err , "failed to update issue #%d with %s" ,
466+ return nil , errors .Wrapf (err , "failed to update issue #%d with %s" ,
437467 * foundIssue , github .Stringify (comment ))
438468 } else {
439- p .l .Printf ("created comment on existing GitHub issue (#%d)" , * foundIssue )
469+ result .Type = TestFailureIssueComment
470+ result .ID = * foundIssue
471+ p .l .Printf ("%s" , result )
440472 }
441473 }
442474
443- return nil
475+ return & result , nil
444476}
445477
446478func (p * poster ) teamcityURL (tab , fragment string ) * url.URL {
@@ -559,9 +591,9 @@ type Logger interface {
559591// will be returned.
560592func Post (
561593 ctx context.Context , l Logger , formatter IssueFormatter , req PostRequest , opts * Options ,
562- ) error {
594+ ) ( * TestFailureIssue , error ) {
563595 if ! opts .CanPost () {
564- return errors .Newf ("GITHUB_API_TOKEN env variable is not set; cannot post issue" )
596+ return nil , errors .Newf ("GITHUB_API_TOKEN env variable is not set; cannot post issue" )
565597 }
566598
567599 client := github .NewClient (oauth2 .NewClient (ctx , oauth2 .StaticTokenSource (
0 commit comments