// https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
const CLOSING_SYNTAX_REGEX = /(?:close|fixe?|resolve)[sd]?\s+#(\d+)/i;
const HAS_CLOSING_PR_LABEL = 'has-closing-pr';

module.exports = async ({ context, github }) => {
  const { body } = context.payload.pull_request;
  // Find a closing syntax after removing comments
  const match = body.replace(/<!--(.+?)-->/gs, '').match(CLOSING_SYNTAX_REGEX);
  if (match) {
    const issue_number = match[1];
    const { owner, repo } = context.repo;
    await github.issues.addLabels({
      owner,
      repo,
      issue_number,
      labels: [HAS_CLOSING_PR_LABEL],
    });
  }
};

@@ -1,8 +1,74 @@
+// Regular expressions to capture a closing syntax in the PR body%0A
 // https
@@ -187,15 +187,22 @@
 TAX_
-REGEX =
+PATTERNS = %5B%0A 
  /(?
@@ -234,16 +234,132 @@
 ?%5Cs+
-#(%5Cd+)/i
+(?:mlflow%5C/mlflow)?#(%5Cd+)/i,%0A  /(?:close%7Cfixe?%7Cresolve)%5Bsd%5D?%5Cs+(?:https?:%5C/%5C/github.com%5C/mlflow%5C/mlflow%5C/issues%5C/)(%5Cd+)/i,%0A%5D
 ;%0Aco
@@ -562,21 +562,32 @@
   const 
-match
+commentsExcluded
  = body.
@@ -619,15 +619,26 @@
  '')
-.
+;%0A  const 
 match
-(
+ = 
 CLOS
@@ -652,13 +652,97 @@
 TAX_
-REGEX
+PATTERNS.map((pattern) =%3E commentsExcluded.match(pattern)).find(%0A    (match) =%3E match,%0A  
 );%0A 

Fix regular expression to capture closing-issue sytanx (#6199)