-
Notifications
You must be signed in to change notification settings - Fork 10
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
Skip Checks API neutral state #278
base: master
Are you sure you want to change the base?
Changes from 2 commits
c1901c2
c6d909a
417f9ef
9e5baff
1769fde
b4c8892
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ type StateChangeInfo struct { | |
ID int64 | ||
SHA string | ||
IsRelatedToAutoBranchBody func(string) bool | ||
IsInProgress func() bool | ||
} | ||
|
||
func CheckAutoBranchWithStatusEvent(ctx context.Context, client *github.Client, autoMergeRepo *queue.AutoMergeQRepo, ev *github.StatusEvent) { | ||
|
@@ -32,6 +33,7 @@ func CheckAutoBranchWithStatusEvent(ctx context.Context, client *github.Client, | |
ID: *ev.ID, | ||
SHA: *ev.SHA, | ||
IsRelatedToAutoBranchBody: isRelatedToAutoBranchBodyWithStatusEvent(ev), | ||
IsInProgress: inProgressWithStatusEvent(ev), | ||
} | ||
checkAutoBranch(ctx, client, autoMergeRepo, info) | ||
} | ||
|
@@ -46,6 +48,7 @@ func CheckAutoBranchWithCheckSuiteEvent(ctx context.Context, client *github.Clie | |
ID: *ev.CheckSuite.ID, | ||
SHA: *ev.CheckSuite.HeadSHA, | ||
IsRelatedToAutoBranchBody: isRelatedToAutoBranchBodyWithCheckSuiteEvent(ev), | ||
IsInProgress: inProgressWithCheckSuiteEvent(ev), | ||
} | ||
checkAutoBranch(ctx, client, autoMergeRepo, info) | ||
} | ||
|
@@ -130,6 +133,18 @@ func isRelatedToAutoBranchBodyWithCheckSuiteEvent(ev *github.CheckSuiteEvent) fu | |
} | ||
} | ||
|
||
func inProgressWithStatusEvent(ev *github.StatusEvent) func() bool { | ||
return func() bool { | ||
return *ev.State == "pending" | ||
} | ||
} | ||
|
||
func inProgressWithCheckSuiteEvent(ev *github.CheckSuiteEvent) func() bool { | ||
return func() bool { | ||
return *ev.CheckSuite.Status != "completed" || *ev.CheckSuite.Conclusion == "neutral" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As your comment, I feel But this code will check whether I concern that this function will return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, it enforces the order of use, which doesn't seem to be a good function... |
||
} | ||
} | ||
|
||
func isRelatedToAutoBranch(active *queue.AutoMergeQueueItem, info StateChangeInfo, autoBranch string) bool { | ||
if !info.IsRelatedToAutoBranchBody(autoBranch) { | ||
log.Printf("warn: this event (%v) is not the auto branch\n", info.ID) | ||
|
@@ -183,6 +198,11 @@ func mergeSucceedItem( | |
return true | ||
} | ||
|
||
if info.IsInProgress() { | ||
log.Printf("info: Check is in progres\n") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
return true | ||
} | ||
|
||
if info.Status != "success" { | ||
log.Println("info: could not merge pull request") | ||
|
||
|
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.
@yamachu I imagined the following code instead of passing a function to
.IsInProgress
field.What do you think about this? Are there any problem to implement?
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.
@tetsuharuohzeki In the code you were suggesting, did you imagine to set the Conclusion field to
ev.State
when received a StatusAPI event?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.
Yes.
Ah, but
github.StatusEvent
does not haveConclusion
field. I think we can use*string
forStateChangeInfo.Conclusion
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.
@yamachu
I wrote that but I also seem your proposed code would also be nice approach which uses func.
You can choose the final implementation. How do you think?
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.
It's a different types, but I think I can express it in a function like TypeScript's Union type, so I'll add a
Conclusion *string
parameter.In the following comments, would such an implementation be appropriate?
https://github.com/voyagegroup/popuko/pull/278/files#r754050176
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.
@yamachu
Umm, I agree that we would need to define a status by something.
However, from your proposed psuedo code, I think the current design is wrong to handle these status.
Your proposed one mixes handling Status API and Checks API in the same code path. This makes a thing more complex.
I think we would require these refactoring to introduce this PR change cleanly:
StateChangeInfo
, and separate a code path into for Status API and Checks API.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.
私は英語ネイティブではないため、コメントに対してコストがかかってしまっています。
そのためコメントを日本語で記載いたします。
異なる概念であるStatus APIのEventとChecks APIのEventを同一の構造体で表現していることで複雑になっていることは同意いたします。
例えば
info.Status
で表現されている内容が、ChecksAPIの場合はConclusionの値であるといった例です。そのためコードパスを分離することは確かに良いように思われます。
Event依存の構造体に非依存の構造体を入れ込み、Event依存のコードパスを分離することでまずは表現可能だと考え、以下のコミットで表現してみました。
1769fde
非依存の構造体に例えば
IsRelatedToAutoBranchBody
のように、関数を返す形にすることでの様にエントリポイントである
checkAutoBranch
は共通化出来そうではありますが、この構造体に持たせるのは違和感がありました。そのため横に別名で生やすことで、コードの分離を実現しています。