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

Made logs.badge.branch capable of accepting a regular expression #1538

Conversation

Ocramius
Copy link
Sponsor Contributor

@Ocramius Ocramius commented Jul 14, 2021

By configuring logs.badge.branch with a /-delimited regular expression, we can collect
reports about a number of branches.

{
    "source": {
        "directories": ["src/"]
    },
    "logs": {
        "badge": {
            "branch": "/^release-.*$/"
        }
    }
}

Note that logs.badge.matchBranchRegex, initially proposed as an alternative, has also been removed.

We can safely assume that a branch value starting and ending with / is a regular expression, because
git branches starting or ending with / are not valid anyway.

Fixes #1536
Fixes #814

Related: #1137
Related: #1149

This PR:

@Ocramius Ocramius changed the title New logs.badge.matchBranchRegex config to match multiple branches i… New logs.badge.matchBranchRegex config to match multiple branches in reporting Jul 14, 2021
@@ -65,7 +63,8 @@ private function assertLogsStateIs(
$this->assertNull($badge);
} else {
$this->assertNotNull($badge);
$this->assertBadgeStateIs($badge, $expectedBadge->getBranch());
Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

Removed this: it made the tests much more confusing than they were, and a simpler solution was to do object-to-object equality.

Copy link
Member

Choose a reason for hiding this comment

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

object-to-object equality is always tricky due to the loose comparison, but if anyone is interested there is https://github.com/webmozarts/strict-phpunit which solves that issue and allows to remove a lot of boilertemplate

src/Logger/BadgeLogger.php Outdated Show resolved Hide resolved
src/Configuration/Entry/Badge.php Outdated Show resolved Hide resolved
Copy link
Member

@maks-rafalko maks-rafalko left a comment

Choose a reason for hiding this comment

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

I'm ok with the current state of PR.

One idea to discuss though: what if we make existing (in master) config key branch more clever to understand regexes?

{
    "logs": {
        "badge": {
            "branch": "master"
        }
    }
}

^ BC support, pushes the report for the exact branch - master in this case.

{
    "logs": {
        "badge": {
            "branch": "/^foo$/"
        }
    }
}

^ new feature. Infection understands this is a regex and matches with preg_match().

In this case we will keep BC and extend the functionality of branch config key.

src/Configuration/Entry/Badge.php Outdated Show resolved Hide resolved
@maks-rafalko maks-rafalko added this to the 0.24.0 milestone Jul 14, 2021
@Ocramius
Copy link
Sponsor Contributor Author

In this case we will keep BC and extend the functionality of branch config key.

Didn't want to mess with the existing branch value, as I don't know what values users have used within it so far.

What I can certainly try to do is say that if the branch value starts with / and ends with /, and is at least 3 characters long, then I treat it as a regex: a bit weak, but could work?

@maks-rafalko
Copy link
Member

What I can certainly try to do is say that if the branch value starts with / and ends with /, and is at least 3 characters long, then I treat it as a regex: a bit weak, but could work?

IMO, sounds ok :) I believe the majority of the users use it like branch: master

Also, why I like the idea of having just one branch config key - it will be similar to PHPUnit's --filter, which accepts raw values as well as regular expressions, which makes it quite flexible.

@Ocramius
Copy link
Sponsor Contributor Author

Ok, will go back at this and simplify the patch: possibly rewrite, since that would be simpler :D

@Ocramius
Copy link
Sponsor Contributor Author

Ocramius commented Jul 14, 2021

Thinking further about this, git branches cannot start with / nor end with /, so we're potentially good here 👍

@Ocramius Ocramius changed the title New logs.badge.matchBranchRegex config to match multiple branches in reporting Made logs.badge.branch capable of accepting a regular expression Jul 20, 2021
@Ocramius
Copy link
Sponsor Contributor Author

@maks-rafalko I've reworked this to hide the fact that a regex or exact match happens inside a Branch, of which I do no longer expose the configuration contents.

I'll rework the docs PR.

Small suggestion: smash docs and sources together - easier for atomic diffs ;-)

Ocramius added a commit to Ocramius/site that referenced this pull request Jul 20, 2021
Also removed `logs.badge.matchBranchRegex` docs: the upstream patch in infection/infection#1538
also got rid of it.
@Ocramius
Copy link
Sponsor Contributor Author

Docs PR also updated.

Copy link
Member

@maks-rafalko maks-rafalko left a comment

Choose a reason for hiding this comment

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

👍

resources/schema.json Show resolved Hide resolved
resources/schema.json Show resolved Hide resolved
@Ocramius
Copy link
Sponsor Contributor Author

Applied suggested improvements 👍

Copy link
Member

@theofidry theofidry left a comment

Choose a reason for hiding this comment

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

👍 Left some comments but I don't think they are critical

tests/phpunit/Configuration/Entry/BadgeTest.php Outdated Show resolved Hide resolved
@@ -65,7 +63,8 @@ private function assertLogsStateIs(
$this->assertNull($badge);
} else {
$this->assertNotNull($badge);
$this->assertBadgeStateIs($badge, $expectedBadge->getBranch());
Copy link
Member

Choose a reason for hiding this comment

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

object-to-object equality is always tricky due to the loose comparison, but if anyone is interested there is https://github.com/webmozarts/strict-phpunit which solves that issue and allows to remove a lot of boilertemplate

@Ocramius
Copy link
Sponsor Contributor Author

@theofidry for value objects, object-to-object equality is an acceptable trade-off, so I'll leave that one as-is.

It is true that some edge cases can be troublesome, but they mostly affect floating point arithmetic and deeply nested graphs with recursion, so not really important in here.

@theofidry
Copy link
Member

@Ocramius definitely, not necessary here for this case

Ocramius added a commit to Ocramius/infection that referenced this pull request Jul 21, 2021
…rough a data provider

Previously, we had a single test with multiple assertions.

Ref: infection#1538 (comment)
@Ocramius Ocramius force-pushed the feature/#1536-badge-logger-branch-regex-match-configuration branch from 79823a0 to 8a37265 Compare July 21, 2021 08:22
…n reporting

By configuring `logs.badge.matchBranchRegex`, it is possible to set multiple branches to report
their mutation score to upstream tools:

```json
{
    "source": {
        "directories": ["src/"]
    },
    "logs": {
        "badge": {
            "matchBranchRegex": "/^release-.*$/"
        }
    }
}
```

Note that `logs.badge.matchBranchRegex` is mutually exclusive with `logs.badge.branch`, which
is much more restrictive: the two cannot be used together.

Fixes infection#1536
By configuring `logs.badge.branch` with a `/`-delimited regular expression, we can collect
reports about a number of branches.

```json
{
    "source": {
        "directories": ["src/"]
    },
    "logs": {
        "badge": {
            "branch": "/^release-.*$/"
        }
    }
}
```

Note that `logs.badge.matchBranchRegex`, initially proposed as an alternative, has also been removed.

We can safely assume that a `branch` value starting and ending with `/` is a regular expression, because
git branches starting or ending with `/` are not valid anyway.

Fixes infection#1536
…rough a data provider

Previously, we had a single test with multiple assertions.

Ref: infection#1538 (comment)
@Ocramius Ocramius force-pushed the feature/#1536-badge-logger-branch-regex-match-configuration branch from 8a37265 to 2925fe2 Compare July 21, 2021 08:22
@Ocramius
Copy link
Sponsor Contributor Author

Rebased and applied @maks-rafalko and @theofidry's suggestions.

Also looking forward to have this merged, so I don't have to wait for upstream approval for CI 🤷 (thanks crypto-bros, for ruining github)

@theofidry theofidry enabled auto-merge (squash) July 21, 2021 08:37
@theofidry theofidry merged commit 0dde91a into infection:master Jul 21, 2021
@Ocramius Ocramius deleted the feature/#1536-badge-logger-branch-regex-match-configuration branch July 21, 2021 08:45
@Ocramius
Copy link
Sponsor Contributor Author

Thanks for the merge!

@theofidry FWIW, avoid squashing - I put some effort in commit messages, and 0dde91a is really butchered :-\

@theofidry
Copy link
Member

FWIW, avoid squashing

We squash the commits in general: the git history of a PR is rarely tidy and it too often provides close to no value for the amount of efforts it requires to keep it tidy (and even more to try to enforce it) when IMO a link to GitHub/GitLab provides a lot more information.

That said I'll be aware to avoid to do that on yours in the future, I did not took notice of it here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow sending stryker-mutator.io reports for multiple branches Upload MSI for all/multiple branches
4 participants