Repository: storybookjs/storybook
File: scripts/dangerfile.js (JavaScript)

Code before:
/** @param {string} title */
const checkPrTitle = (title) => {
  const match = title.match(/^[A-Z].+:\s[A-Z].+$/);
  if (!match) {
    fail(
      `PR title must be in the format of "Area: Summary", With both Area and Summary starting with a capital letter
Good examples:
- "Docs: Describe Canvas Doc Block"
- "Svelte: Support Svelte v4"
Bad examples:
- "add new api docs"
- "fix: Svelte 4 support"
- "Vue: improve docs"`
    );
  }
};

/** @param {string} body */
const checkManualTestingSection = (body) => {
  // Check if author is a core team member or maintainer
  const author = danger.github.pr.user;
  const authorAssociation = danger.github.pr.author_association;

  // Bypass check for OWNER, MEMBER roles (but never for bots e.g. Copilot)
  if (['OWNER', 'MEMBER'].includes(authorAssociation) && author.type !== 'Bot') {
    // return; // TODO: re-enable after debug
  }

  // Check if manual testing section exists
  const manualTestingMatch = body.match(/####\s*Manual testing/i);
  if (!manualTestingMatch || manualTestingMatch.index === undefined) {
    fail(
      'PR description is missing the mandatory "#### Manual testing" section. Please add it so that reviewers know how to manually test your changes.'
    );
    return;
  }

  // Extract content after the manual testing section
  const manualTestingSectionStart = manualTestingMatch.index + manualTestingMatch[0].length;
  const restOfBody = body.substring(manualTestingSectionStart);

  // Find the next section
  const nextSectionMatch = restOfBody.match(/\n#+[^#]/);
  const manualTestingContent = nextSectionMatch
    ? restOfBody.substring(0, nextSectionMatch.index)
    : restOfBody;

  // Remove the caution block and check if there's any meaningful content left
  const contentWithoutCaution = manualTestingContent
    .replace(/>\s*\[!CAUTION\][^]*?This section is mandatory[^]*?Thanks!/i, '')
    .trim();

Review comment (bug):
```suggestion
    return;
```

* [x] re-enable bypass after debugging the CI job

Code after:
/** @param {string} title */
const checkPrTitle = (title) => {
  const match = title.match(/^[A-Z].+:\s[A-Z].+$/);
  if (!match) {
    fail(
      `PR title must be in the format of "Area: Summary", With both Area and Summary starting with a capital letter
Good examples:
- "Docs: Describe Canvas Doc Block"
- "Svelte: Support Svelte v4"
Bad examples:
- "add new api docs"
- "fix: Svelte 4 support"
- "Vue: improve docs"`
    );
  }
};

/** @param {string} body */
const checkManualTestingSection = (body) => {
  // Check if author is a core team member or maintainer
  const author = danger.github.pr.user;
  const authorAssociation = danger.github.pr.author_association;

  // Bypass check for OWNER, MEMBER roles (but never for bots e.g. Copilot)
  if (['OWNER', 'MEMBER'].includes(authorAssociation) && author.type !== 'Bot') {
    return;
  }

  // Check if manual testing section exists
  const manualTestingMatch = body.match(/####\s*Manual testing/i);
  if (!manualTestingMatch || manualTestingMatch.index === undefined) {
    fail(
      'PR description is missing the mandatory "#### Manual testing" section. Please add it so that reviewers know how to manually test your changes.'
    );
    return;
  }

  // Extract content after the manual testing section
  const manualTestingSectionStart = manualTestingMatch.index + manualTestingMatch[0].length;
  const restOfBody = body.substring(manualTestingSectionStart);

  // Find the next section
  const nextSectionMatch = restOfBody.match(/\n#+[^#]/);
  const manualTestingContent = nextSectionMatch
    ? restOfBody.substring(0, nextSectionMatch.index)
    : restOfBody;

  // Remove the initial message and check if there's any meaningful content left
  const contentWithoutInitialMessage = manualTestingContent
    .replace(/>\s*\[!CAUTION\][^]*?This section is mandatory[^]*?Thanks!/i, '')
    .trim();