const { getRefDate, releaseYargsBuilder } = require('./release-utils');

const pullsBaseURL = new URL(
  'https://github.com/mdn/browser-compat-data/pulls',
);
const releaseNotesLabel = 'label:"needs-release-note :newspaper:"';

const { argv } = require('yargs').command(
  '$0 [start-version-tag [end-version-tag]]',
  'Get a link to PRs that need release notes between two tags (or other commits)',
  releaseYargsBuilder,
);

function needsReleaseNotePulls(startRef, endRef) {
  const searchUrl = new URL(pullsBaseURL);

  let merged;
  if (endRef !== 'HEAD') {
    merged = `merged:${getRefDate(startRef, true)}..${getRefDate(
      endRef,
      true,
    )}`;
  } else {
    merged = `merged:>=${getRefDate(startRef, true)}`;
  }
  searchUrl.search = `q=is:pr ${merged} ${releaseNotesLabel}`;

  return `${searchUrl.href}`;
}

function main() {
  const { startVersionTag: start, endVersionTag: end } = argv;

  console.log(
    `From ${start} (${getRefDate(start)}) to ${end} (${getRefDate(end)}):`,
  );
  console.log();
  console.log(needsReleaseNotePulls(start, end));
}

main();

@@ -336,31 +336,16 @@
 PRs 
-that need release notes
+included
  bet
@@ -379,16 +379,31 @@
 mits)',%0A
+  yargs =%3E %7B%0A  
   releas
@@ -419,146 +419,749 @@
 lder
-,%0A);%0A%0Afunction
+(yargs);%0A    yargs.option('q', %7B%0A      alias: 'quiet',%0A      describe: 'Print the URL only',%0A      type: 'boolean',%0A    %7D);%0A    yargs.option('labeled', %7B%0A      describe: 'Filter to
  needs
-R
+-r
 elease
-NotePulls(startRef, endRef) %7B%0A  const searchUrl = new URL(pullsBaseURL);%0A%0A  let merged;%0A  if (endRef !== 'HEAD'
+-note labeled PRs only',%0A      type: 'boolean',%0A    %7D);%0A    yargs.option('query-only', %7B%0A      describe: 'Print the query only (such as for piping to %60gh%60)',%0A      type: 'boolean',%0A    %7D);%0A    yargs.example(%0A      '$0 --quiet --labeled --query-only',%0A      'Get the query for piping to %60gh%60',%0A    );%0A  %7D,%0A);%0A%0Afunction queryToURL(query) %7B%0A  const searchUrl = new URL(pullsBaseURL);%0A  searchUrl.search = %60q=$%7Bquery%7D%60;%0A  return searchUrl.href;%0A%7D%0A%0Afunction buildQuery(endRef, startRef, urlSafe) %7B%0A  let merged;%0A  if (!%5B'HEAD', 'main'%5D.includes(endRef)
 ) %7B%0A
@@ -1204,19 +1204,22 @@
 artRef, 
-tru
+urlSaf
 e)%7D..$%7Bg
@@ -1321,19 +1321,22 @@
 artRef, 
-tru
+urlSaf
 e)%7D%60;%0A  
@@ -1341,98 +1341,108 @@
   %7D%0A
+%0A
   
-searchUrl.search = %60q=is:pr $%7Bmerged%7D $%7BreleaseNotesLabel%7D%60;%0A%0A  return %60$%7BsearchUrl.href
+return %60is:pr $%7Bmerged%7D%60;%0A%7D%0A%0Afunction appendLabel(query) %7B%0A  return %60$%7Bquery%7D $%7BreleaseNotesLabel
 %7D%60;%0A
@@ -1471,16 +1471,20 @@
  const %7B
+%0A   
  startVe
@@ -1495,24 +1495,28 @@
 nTag: start,
+%0A   
  endVersionT
@@ -1526,20 +1526,184 @@
  end
- %7D = argv;%0A%0A
+,%0A    quiet,%0A    labeled,%0A    queryOnly,%0A  %7D = argv;%0A%0A  let query = buildQuery(end, start, !queryOnly);%0A  if (labeled) %7B%0A    query = appendLabel(query);%0A  %7D%0A%0A  if (!quiet) %7B%0A  
   co
@@ -1713,16 +1713,18 @@
 le.log(%0A
+  
     %60Fro
@@ -1791,21 +1791,25 @@
 d)%7D):%60,%0A
+  
   );%0A
+  
   consol
@@ -1823,55 +1823,104 @@
 ;%0A  
-console.log(needsReleaseNotePulls(start, end));
+%7D%0A%0A  if (queryOnly) %7B%0A    console.log(query);%0A  %7D else %7B%0A    console.log(queryToURL(query));%0A  %7D
 %0A%7D%0A%0A

Make it easier to pipe release-pulls to other tools (#13905)