Skip to content

Commit

Permalink
Merge pull request #196 from suzuki-shunsuke/fix/post-comment-even-if…
Browse files Browse the repository at this point in the history
…-failed-to-hide-comments

fix: post a comment even if it failed to list hidden comments
  • Loading branch information
suzuki-shunsuke authored Jan 15, 2021
2 parents 7c93e69 + 826e325 commit b6754a5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
17 changes: 10 additions & 7 deletions pkg/api/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (ctrl ExecController) post(
"pr_number": cmt.PRNumber,
"sha": cmt.SHA1,
}).Debug("comment meta data")

skipHideComment := false
nodeIDs, err := ctrl.listHiddenComments(ctx, cmt, map[string]interface{}{
"Command": map[string]interface{}{
"ExitCode": cmtParams.ExitCode,
Expand All @@ -271,16 +271,19 @@ func (ctrl ExecController) post(
},
})
if err != nil {
return err
skipHideComment = true
logrus.WithError(err).Error("list hidden comments")
}

if err := ctrl.Commenter.Create(ctx, cmt); err != nil {
return fmt.Errorf("failed to create an issue comment: %w", err)
}
logrus.WithFields(logrus.Fields{
"count": len(nodeIDs),
"node_ids": nodeIDs,
}).Debug("comments which would be hidden")
ctrl.hideComments(ctx, nodeIDs)
if !skipHideComment {
logrus.WithFields(logrus.Fields{
"count": len(nodeIDs),
"node_ids": nodeIDs,
}).Debug("comments which would be hidden")
ctrl.hideComments(ctx, nodeIDs)
}
return nil
}
16 changes: 10 additions & 6 deletions pkg/api/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,22 @@ func (ctrl PostController) Post(ctx context.Context, opts option.PostOptions) er
"pr_number": cmt.PRNumber,
"sha": cmt.SHA1,
}).Debug("comment meta data")
skipHideComment := false
nodeIDs, err := ctrl.listHiddenComments(ctx, cmt)
if err != nil {
return err
skipHideComment = true
logrus.WithError(err).Error("list hidden comments")
}
if err := ctrl.Commenter.Create(ctx, cmt); err != nil {
return fmt.Errorf("failed to create an issue comment: %w", err)
}
logrus.WithFields(logrus.Fields{
"count": len(nodeIDs),
"node_ids": nodeIDs,
}).Debug("comments which would be hidden")
ctrl.hideComments(ctx, nodeIDs)
if !skipHideComment {
logrus.WithFields(logrus.Fields{
"count": len(nodeIDs),
"node_ids": nodeIDs,
}).Debug("comments which would be hidden")
ctrl.hideComments(ctx, nodeIDs)
}
return nil
}

Expand Down

0 comments on commit b6754a5

Please sign in to comment.