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

Fixing the issue when status check per rule matches multiple actions #29631

Merged

Conversation

charles7668
Copy link
Contributor

@charles7668 charles7668 commented Mar 6, 2024

Close #29628
rule

Test / Build*
Test / Build *
Test / Build 2*
Test / Build 1*

image
rule2

Test / Build*
Test / Build 1*

image

rule3

Test / Build*
Test / Build 1*
NotExist*

image

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 6, 2024
@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Mar 6, 2024
@wxiaoguang wxiaoguang changed the title Fixing the issue when status check per rule matches multiple actions (#29628) Fixing the issue when status check per rule matches multiple actions Mar 6, 2024
@wxiaoguang wxiaoguang added the backport/v1.21 This PR should be backported to Gitea 1.21 label Mar 6, 2024
@wxiaoguang
Copy link
Contributor

Related to:

I guess the if matchedCount != len(requiredContexts) was written intentionally? @MarkusAmshove would you like to take a look? 🙏

@wxiaoguang

This comment was marked as off-topic.

@charles7668
Copy link
Contributor Author

Related to:

* [Disallow merge when required checked are missing #29143](https://github.com/go-gitea/gitea/pull/29143)

I guess the if matchedCount != len(requiredContexts) was written intentionally? @MarkusAmshove would you like to take a look? 🙏

not sure , but I think this fix hasn't broken the expected behavior of #29143
image

Based on intuition, a rule can match many actions, unlike writing one rule to match one action (in which case, we only need to write the full action name).

Perhaps this checking behavior can be refactored.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Mar 6, 2024

I proposed some examples in #29631 (comment).

I think the correct logic should be:

  1. All "required" are satisfied
  2. All "rules" are used

Sorry I think I misunderstood something. Ignore my comments ....

ps: It would be helpful to add some tests to clarify the behavior.

@MarkusAmshove
Copy link
Contributor

Related to:

I guess the if matchedCount != len(requiredContexts) was written intentionally? @MarkusAmshove would you like to take a look? 🙏

The problem I fixed with that condition was that the function was returning success even if a required check hasn't run at all (e.g. no status check was submitted that matches a required pattern).
I guess I didn't think of a * pattern that catches multiple checks (so required 1, but matched 5).
The condition should still be correct, but it should test if matched is less than required, not unequal.
That should catch both cases

@charles7668
Copy link
Contributor Author

charles7668 commented Mar 6, 2024

Related to:

I guess the if matchedCount != len(requiredContexts) was written intentionally? @MarkusAmshove would you like to take a look? 🙏

The problem I fixed with that condition was that the function was returning success even if a required check hasn't run at all (e.g. no status check was submitted that matches a required pattern). I guess I didn't think of a * pattern that catches multiple checks (so required 1, but matched 5). The condition should still be correct, but it should test if matched is less than required, not unequal. That should catch both cases

I'm not sure, but the expected behavior is that every rule needs to match at least one action?

If using <, then the following case may be incorrect.

actions

Build 1
Build 2
Build 2t

rules

*Build*
*Build *
*Build 1*
*Build 2*

@MarkusAmshove
Copy link
Contributor

MarkusAmshove commented Mar 6, 2024

Yeah I think I didn't communicate that well.

The deleted if in this PR is an early exit, so I was talking about the pending condition.

To put it the other way around:
If there is a required context that matches no available status that is successful, then the function should return pending.

Currently it is also returning pending if a context matches multiple checks and that is obviously a bug.

The test case for the bug I fixed would look like this:

actions (all successful)

Build 1
Build 2

rules

Build 1
Build 2
Build 3

For that the function returned overall successful without my change

@charles7668
Copy link
Contributor Author

charles7668 commented Mar 6, 2024

Hmm... I think perhaps one rule matching at least one action is correct.

In GitHub, it seems like one rule matches just one action.

But if Gitea allows wildcard characters, then it seems to allow one rule to match multiple actions.

In this case, we can't simply compare the rule count and the matched action count.

case

this is result for this case when using <
image

@charles7668 charles7668 force-pushed the FixStatusCheckWhenRuleMatchMultiple branch from 0c0ea5d to c2c9cd8 Compare March 6, 2024 15:17
@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 6, 2024
@MarkusAmshove
Copy link
Contributor

I've taken the time to write some tests, which I should have done beforehand, and also changed the != to < to see if my assumption was correct.

Have a look at this commit (feel free to grab the tests into this PR): MarkusAmshove@adc885b
the only test failing is TestMergeRequiredContextsCommitStatus_MissingContextWithPattern
But I also can't guarantee that I'm not missing some cases :)

@charles7668 charles7668 force-pushed the FixStatusCheckWhenRuleMatchMultiple branch from c2c9cd8 to 8ab9e5b Compare March 6, 2024 15:32
@charles7668
Copy link
Contributor Author

I've taken the time to write some tests, which I should have done beforehand, and also changed the != to < to see if my assumption was correct.

Have a look at this commit (feel free to grab the tests into this PR): MarkusAmshove@adc885b the only test failing is TestMergeRequiredContextsCommitStatus_MissingContextWithPattern But I also can't guarantee that I'm not missing some cases :)

I'm just curious about this case. I think it should pass because when allowing wildcard characters, sometimes intersections are possible.

image

@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 6, 2024
@charles7668 charles7668 changed the title Fixing the issue when status check per rule matches multiple actions WIP : Fixing the issue when status check per rule matches multiple actions Mar 6, 2024
@charles7668 charles7668 force-pushed the FixStatusCheckWhenRuleMatchMultiple branch from 6d4cf88 to 583bea2 Compare March 6, 2024 16:07
@MarkusAmshove
Copy link
Contributor

None of the contexts have a wildcard character, did you mean to add a * somewhere?

@charles7668
Copy link
Contributor Author

None of the contexts have a wildcard character, did you mean to add a * somewhere?

Like this, just simulating when multiple rules match the same action.

	givenStatuses := createStatuses(
		createSuccess("Build 1"),
		createSuccess("Build 2"),
		createSuccess("Build 2t"),
	)

	requiredContexts := createRequiredContexts(
		"Build 1*",
		"Build 2*",
		"Build*",
		"Build *",
	)

@charles7668 charles7668 force-pushed the FixStatusCheckWhenRuleMatchMultiple branch from 583bea2 to 16dce07 Compare March 6, 2024 16:21
@charles7668 charles7668 changed the title WIP : Fixing the issue when status check per rule matches multiple actions Fixing the issue when status check per rule matches multiple actions Mar 6, 2024
@MarkusAmshove
Copy link
Contributor

Yes, that should result in success :-)

Maybe it's easier to change the logic to check each required context if it matches a check and if one doesn't, return pending. That way we don't have to count how many match

@charles7668 charles7668 marked this pull request as draft March 7, 2024 03:20
@charles7668 charles7668 force-pushed the FixStatusCheckWhenRuleMatchMultiple branch from 1f4b607 to 90658f3 Compare March 7, 2024 17:34
@pull-request-size pull-request-size bot removed the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 7, 2024
@charles7668 charles7668 force-pushed the FixStatusCheckWhenRuleMatchMultiple branch from 90658f3 to 1b0a814 Compare March 7, 2024 18:03
@charles7668 charles7668 marked this pull request as ready for review March 7, 2024 18:38
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 8, 2024
@lunny lunny requested a review from Zettat123 March 8, 2024 03:09
services/pull/commit_status.go Outdated Show resolved Hide resolved
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 8, 2024
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 8, 2024
@lunny lunny enabled auto-merge (squash) March 8, 2024 04:33
@lunny lunny merged commit 7cf7a49 into go-gitea:main Mar 8, 2024
26 checks passed
@GiteaBot GiteaBot added this to the 1.23.0 milestone Mar 8, 2024
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 8, 2024
GiteaBot pushed a commit to GiteaBot/gitea that referenced this pull request Mar 8, 2024
…o-gitea#29631)

Close go-gitea#29628
rule
```
Test / Build*
Test / Build *
Test / Build 2*
Test / Build 1*
```

![image](https://github.com/go-gitea/gitea/assets/30816317/19bef0a9-fa97-43c5-887b-dece76064aa8)
rule2
```
Test / Build*
Test / Build 1*
```

![image](https://github.com/go-gitea/gitea/assets/30816317/19bef0a9-fa97-43c5-887b-dece76064aa8)

rule3
```
Test / Build*
Test / Build 1*
NotExist*
```

![image](https://github.com/go-gitea/gitea/assets/30816317/f6a5e832-2e1b-4049-915b-45bec5ef070c)

---------

Co-authored-by: Zettat123 <zettat123@gmail.com>
@GiteaBot GiteaBot added the backport/done All backports for this PR have been created label Mar 8, 2024
lunny pushed a commit that referenced this pull request Mar 8, 2024
…29631) (#29655)

Backport #29631 by @charles7668

Close #29628
rule
```
Test / Build*
Test / Build *
Test / Build 2*
Test / Build 1*
```

![image](https://github.com/go-gitea/gitea/assets/30816317/19bef0a9-fa97-43c5-887b-dece76064aa8)
rule2
```
Test / Build*
Test / Build 1*
```

![image](https://github.com/go-gitea/gitea/assets/30816317/19bef0a9-fa97-43c5-887b-dece76064aa8)

rule3
```
Test / Build*
Test / Build 1*
NotExist*
```

![image](https://github.com/go-gitea/gitea/assets/30816317/f6a5e832-2e1b-4049-915b-45bec5ef070c)

Co-authored-by: charles <30816317+charles7668@users.noreply.github.com>
Co-authored-by: Zettat123 <zettat123@gmail.com>
zjjhot added a commit to zjjhot/gitea that referenced this pull request Mar 8, 2024
* giteaofficial/main:
  Filter for default-branch selection (go-gitea#29388)
  Fixing the issue when status check per rule matches multiple actions (go-gitea#29631)
  Fix 500 when deleting account with incorrect password or unsupported login type (go-gitea#29579)
  Partially enable MSSQL case-sensitive collation support (go-gitea#29238)
@lunny lunny modified the milestones: 1.23.0, 1.22.0 Mar 8, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
@charles7668 charles7668 deleted the FixStatusCheckWhenRuleMatchMultiple branch April 10, 2024 01:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created backport/v1.21 This PR should be backported to Gitea 1.21 lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gitea fails to complete all checks with more than 1 pattern in "Enable status check"
7 participants