-
Notifications
You must be signed in to change notification settings - Fork 156
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
Minimize latest plan preview comment before comment error message #4683
Conversation
@TakumaKurosawa You want to do below, right?
|
@ffjlabo |
tool/actions-plan-preview/main.go
Outdated
if comment == nil { | ||
log.Println("plan-preview result has error") | ||
os.Exit(1) | ||
return | ||
} |
There was a problem hiding this comment.
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 🤔
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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? 🤔
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 🙏
2878653
to
0bff295
Compare
tool/actions-plan-preview/main.go
Outdated
// 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 | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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 👍
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
74a9d8e
to
84dcc11
Compare
@ffjlabo please re-check 👀 |
There was a problem hiding this 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
tool/actions-plan-preview/main.go
Outdated
doComment(failureBadgeURL + "\n" + body) | ||
doComment(body) | ||
|
||
log.Printf("Successfully minimized last plan-preview result on pull request\n") |
There was a problem hiding this comment.
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 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.Printf("Previous plan-preview comment has already minimized. So don't minimize anything\n") | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here 🙏
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1cb42fa
to
f286ae2
Compare
There was a problem hiding this 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! 🚀
Signed-off-by: Takumaron <[email protected]>
Signed-off-by: TakumaKurosawa <[email protected]>
Signed-off-by: TakumaKurosawa <[email protected]>
f286ae2
to
57b3af0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you go 🪨
@TakumaKurosawa The new version of action-plan-preview had been released, thank you 🙏 |
…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]>
…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]>
…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]>
…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]>
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Does this PR introduce a user-facing change?: