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

Minimize latest plan preview comment before comment error message #4683

Merged

Conversation

TakumaKurosawa
Copy link
Contributor

@TakumaKurosawa TakumaKurosawa commented Nov 22, 2023

What this PR does / why we need it:

  1. The status badge appear twice

Screenshot 2023-11-22 at 14 52 14

  1. Minimize previous comment when plan-preview result has error

screencapture-github-CyberAgentAI-aoc-daifuku-app-config-pull-1323-2023-11-22-14_56_14

Which issue(s) this PR fixes:

Fixes #

Does this PR introduce a user-facing change?:

  • How are users affected by this change:
  • Is this breaking change:
  • How to migrate (if breaking change):

@ffjlabo
Copy link
Member

ffjlabo commented Nov 22, 2023

@TakumaKurosawa
Thank you for the PR!
I would like to recheck the purpose!

You want to do below, right?

  • fix not to show the status badge twice
  • minimize the previous comment not only when the plan-preview succeed but also the plan-preview result has an error (because not minimized before)

@TakumaKurosawa
Copy link
Contributor Author

@ffjlabo
Thanks for checking my pull request.
Your thoughts are completely in line with mine.

Comment on lines 154 to 158
if comment == nil {
log.Println("plan-preview result has error")
os.Exit(1)
return
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there is no previous comment 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@khanhtc1202
I'm sorry for replying later.
Nothing to minimize any message if there is no previous comment.
I'm not sure what you want to know, sorry.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean in that case, this comment would be nil and I guess we can return normally, no need to exit with error here, isn't it? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@khanhtc1202
This comment is latest previous comment that must close.
But if result.HasError() {} is still true, so we have to exit with error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@khanhtc1202 cc @TakumaKurosawa
It should stop as exit 1 because the fix is in the error case in which plan-preview failed.

So if the previous comment doesn't exist, the code wants to finish as exit 1 with any errors when the plan-preview result has some errors.
This is like an early return.

Copy link
Member

@ffjlabo ffjlabo Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is confusing, so he created a function for minimizing a previous comment 👍
This function does not return errors if some errors occur in it because we should comment on the PR about the plan-preview result regardless of failing to minimize
74a9d8e

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got your points, thank both 🙏

@TakumaKurosawa TakumaKurosawa force-pushed the fix-plan-preview-error-comment branch from 2878653 to 0bff295 Compare November 28, 2023 01:45
Comment on lines 145 to 168
// Find comments we sent before
comment, err := findLatestPlanPreviewComment(ctx, ghGraphQLClient, event.Owner, event.Repo, event.PRNumber)
if err != nil {
log.Printf("Unable to find the previous comment to minimize (%v)\n", err)
}

body := makeCommentBody(event, result)
doComment(failureBadgeURL + "\n" + body)
doComment(body)

if comment == nil {
log.Println("plan-preview result has error")
os.Exit(1)
return
}

if bool(comment.IsMinimized) {
log.Printf("Previous plan-preview comment has already minimized. So don't minimize anything\n")
return
}

if err := minimizeComment(ctx, ghGraphQLClient, comment.ID, "OUTDATED"); err != nil {
log.Printf("warning: cannot minimize comment: %s\n", err.Error())
return
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[IMO]

minimize the previous comment not only when the plan-preview succeed but also the plan-preview result has an error (because not minimized before)

To realize this, It would be nice to gather these process into one method 👀

  • find latest comment
  • makeCommentBody
  • do comment
  • minimizeComment

Then we only call the method regardless of failure or success. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ffjlabo
Yes! Exactly!
I will gather these process.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ffjlabo
Applied!!
74a9d8e

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TakumaKurosawa Sorry for late reply 🙏 It looks good 👍

Copy link

codecov bot commented Dec 3, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (f7287c8) 30.82% compared to head (57b3af0) 30.83%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4683   +/-   ##
=======================================
  Coverage   30.82%   30.83%           
=======================================
  Files         221      221           
  Lines       25993    25993           
=======================================
+ Hits         8012     8014    +2     
+ Misses      17331    17329    -2     
  Partials      650      650           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TakumaKurosawa TakumaKurosawa force-pushed the fix-plan-preview-error-comment branch from 74a9d8e to 84dcc11 Compare December 6, 2023 01:27
@khanhtc1202
Copy link
Member

@ffjlabo please re-check 👀

Copy link
Member

@ffjlabo ffjlabo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TakumaKurosawa
Thank you! just one more nit point 🙏
If this fixed I will approve

doComment(failureBadgeURL + "\n" + body)
doComment(body)

log.Printf("Successfully minimized last plan-preview result on pull request\n")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log.Printf -> log.Println would be better 👀

Copy link
Contributor Author

@TakumaKurosawa TakumaKurosawa Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ffjlabo
Applied!
f286ae2

Comment on lines 348 to 349
log.Printf("Previous plan-preview comment has already minimized. So don't minimize anything\n")
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here 🙏

Copy link
Contributor Author

@TakumaKurosawa TakumaKurosawa Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return
}

log.Printf("Successfully minimized last plan-preview result on pull request\n")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here 🙏

Copy link
Contributor Author

@TakumaKurosawa TakumaKurosawa Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TakumaKurosawa TakumaKurosawa force-pushed the fix-plan-preview-error-comment branch from 1cb42fa to f286ae2 Compare December 7, 2023 07:07
Copy link
Member

@ffjlabo ffjlabo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! 🚀

@ffjlabo ffjlabo force-pushed the fix-plan-preview-error-comment branch from f286ae2 to 57b3af0 Compare December 7, 2023 07:32
Copy link
Member

@khanhtc1202 khanhtc1202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you go 🪨

@khanhtc1202 khanhtc1202 merged commit 2501848 into pipe-cd:master Dec 7, 2023
15 checks passed
@TakumaKurosawa TakumaKurosawa deleted the fix-plan-preview-error-comment branch December 7, 2023 08:15
@khanhtc1202
Copy link
Member

@TakumaKurosawa The new version of action-plan-preview had been released, thank you 🙏
https://github.com/pipe-cd/actions-plan-preview/releases/tag/v1.7.6

sZma5a pushed a commit to sZma5a/pipecd that referenced this pull request Dec 17, 2023
…pe-cd#4683)

* Minimize latest plan preview comment before comment error message

Signed-off-by: Takumaron <[email protected]>

* Create minimize previous comment function

Signed-off-by: TakumaKurosawa <[email protected]>

* Use log.Println instead of log.Printf

Signed-off-by: TakumaKurosawa <[email protected]>

---------

Signed-off-by: Takumaron <[email protected]>
Signed-off-by: TakumaKurosawa <[email protected]>
sZma5a pushed a commit to sZma5a/pipecd that referenced this pull request Dec 17, 2023
…pe-cd#4683)

* Minimize latest plan preview comment before comment error message

Signed-off-by: Takumaron <[email protected]>

* Create minimize previous comment function

Signed-off-by: TakumaKurosawa <[email protected]>

* Use log.Println instead of log.Printf

Signed-off-by: TakumaKurosawa <[email protected]>

---------

Signed-off-by: Takumaron <[email protected]>
Signed-off-by: TakumaKurosawa <[email protected]>
sZma5a pushed a commit to sZma5a/pipecd that referenced this pull request Dec 17, 2023
…pe-cd#4683)

* Minimize latest plan preview comment before comment error message

Signed-off-by: Takumaron <[email protected]>

* Create minimize previous comment function

Signed-off-by: TakumaKurosawa <[email protected]>

* Use log.Println instead of log.Printf

Signed-off-by: TakumaKurosawa <[email protected]>

---------

Signed-off-by: Takumaron <[email protected]>
Signed-off-by: TakumaKurosawa <[email protected]>
Signed-off-by: sZma5a <[email protected]>
@github-actions github-actions bot mentioned this pull request Feb 6, 2024
sZma5a pushed a commit to sZma5a/pipecd that referenced this pull request Feb 12, 2024
…pe-cd#4683)

* Minimize latest plan preview comment before comment error message

Signed-off-by: Takumaron <[email protected]>

* Create minimize previous comment function

Signed-off-by: TakumaKurosawa <[email protected]>

* Use log.Println instead of log.Printf

Signed-off-by: TakumaKurosawa <[email protected]>

---------

Signed-off-by: Takumaron <[email protected]>
Signed-off-by: TakumaKurosawa <[email protected]>
Signed-off-by: 鈴木 優耀 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants