Skip to content

Different behavior in status check pattern matching with ** #35473

@LordBaryhobal

Description

@LordBaryhobal

Description

Context

When configuring banch protection, you can enable status checks. You are prompted to enter some patterns to match required status checks. The patterns are first matched against recent status checks using the minimatch JS package. But when they are enforced, on the backend, they are matched using the gobwas/glob Go package. This leads to some differences in behaviors (as seen in #33121

Issue

The main issue I am facing right now is the difference in the meaning of "**". It seems like the Go package implements it as a "match any character, any number of times", while the minimatch implements it in a more path-related way, matching "multiple folder names".

Here is a minimal working example in Go, which correctly matches the status check context.

package main

import (
    "fmt"
    "github.com/gobwas/glob"
)

func main() {
    pattern, _ := glob.Compile("Check**")
    if pattern.Match("Check / check (pull_request)") {
        fmt.Println("Matches")
    } else {
        fmt.Println("Doesn't match")
    }
    // -> Matches
}

And here is the same example using the minimatch JS package, which doesn't work because of the "/" in the status check context:

const {minimatch} = require("minimatch")
const matches = minimatch("Check / check (pull_request)", "Check**", {noext: true})
if (matches) {
    console.log("Matches")
} else {
    console.log("Doesn't match")
}
// -> Doesn't match

Possible solution

I don't know how to make minimatch work the same as gobwas/glob or if it is even possible. However, if the patterns were to be RegExps, I think it would be easier to have matching libraries both in Go and JS. Is there a particular reason to use globs instead of regular expressions ?

Demo repo: https://demo.gitea.com/LordBaryhobal/test-status-check

Gitea Version

1.24.4

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

Branch protection rule, status check is not marked as "Matched"

Image

Pull request, check is marked as required

Image

Git Version

No response

Operating System

No response

How are you running Gitea?

Docker image

Database

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions