@@ -90,7 +90,7 @@ function run() {
9090 const allLabels = new Set(preexistingLabels);
9191 for (const [label, globs] of labelGlobs.entries()) {
9292 core.debug(`processing ${label}`);
93- if (checkGlobs(changedFiles, globs, dot)) {
93+ if (checkGlobs(pullRequest.title, pullRequest.body, changedFiles, globs, dot)) {
9494 allLabels.add(label);
9595 }
9696 else if (syncLabels) {
@@ -233,17 +233,41 @@ function toMatchConfig(config) {
233233function printPattern(matcher) {
234234 return (matcher.negate ? '!' : '') + matcher.pattern;
235235}
236- function checkGlobs(changedFiles, globs, dot) {
236+ function checkGlobs(prTitle, prBody, changedFiles, globs, dot) {
237237 for (const glob of globs) {
238238 core.debug(` checking pattern ${JSON.stringify(glob)}`);
239239 const matchConfig = toMatchConfig(glob);
240- if (checkMatch(changedFiles, matchConfig, dot)) {
240+ if (checkMatch(prTitle, prBody, changedFiles, matchConfig, dot)) {
241241 return true;
242242 }
243243 }
244244 return false;
245245}
246246exports.checkGlobs = checkGlobs;
247+ function isMatchTitle(prTitle, titleMatchers) {
248+ core.debug(` matching patterns against title ${prTitle}`);
249+ for (const titleMatcher of titleMatchers) {
250+ core.debug(` - pattern ${titleMatcher}`);
251+ if (!prTitle.includes(titleMatcher)) {
252+ core.debug(` pattern ${titleMatcher} did not match`);
253+ return false;
254+ }
255+ }
256+ core.debug(` all patterns matched title`);
257+ return true;
258+ }
259+ function isMatchBody(prBody, bodyMatchers) {
260+ core.debug(` matching patterns against body ${prBody}`);
261+ for (const bodyMatcher of bodyMatchers) {
262+ core.debug(` - pattern ${bodyMatcher}`);
263+ if (!prBody.includes(bodyMatcher)) {
264+ core.debug(` pattern ${bodyMatcher} did not match`);
265+ return false;
266+ }
267+ }
268+ core.debug(` all patterns matched body`);
269+ return true;
270+ }
247271function isMatch(changedFile, matchers) {
248272 core.debug(` matching patterns against file ${changedFile}`);
249273 for (const matcher of matchers) {
@@ -257,39 +281,72 @@ function isMatch(changedFile, matchers) {
257281 return true;
258282}
259283// equivalent to "Array.some()" but expanded for debugging and clarity
260- function checkAny(changedFiles, globs, dot) {
261- const matchers = globs.map(g => new minimatch_1.Minimatch(g, { dot }));
262- core.debug(` checking "any" patterns`);
263- for (const changedFile of changedFiles) {
264- if (isMatch(changedFile, matchers)) {
265- core.debug(` "any" patterns matched against ${changedFile}`);
266- return true;
284+ function checkAny(prTitle, prBody, changedFiles, globs, dot) {
285+ const matchers = groupMatchers(globs, dot);
286+ core.debug(` checking "any" patterns`);
287+ if (matchers.byTitle.length > 0 && isMatchTitle(prTitle, matchers.byTitle)) {
288+ core.debug(` "any" patterns matched against pr title ${prTitle}`);
289+ return true;
290+ }
291+ if (matchers.byBody.length > 0 && isMatchBody(prBody, matchers.byBody)) {
292+ core.debug(` "any" patterns matched against pr body ${prBody}`);
293+ return true;
294+ }
295+ if (matchers.byFile.length > 0) {
296+ for (const changedFile of changedFiles) {
297+ if (isMatch(changedFile, matchers.byFile)) {
298+ core.debug(` "any" patterns matched against ${changedFile}`);
299+ return true;
300+ }
267301 }
268302 }
269303 core.debug(` "any" patterns did not match any files`);
270304 return false;
271305}
306+ function groupMatchers(globs, dot) {
307+ const grouped = { byBody: [], byTitle: [], byFile: [] };
308+ return globs.reduce((g, glob) => {
309+ if (glob.startsWith('title:')) {
310+ g.byTitle.push(glob.substring(6));
311+ }
312+ else if (glob.startsWith('body:')) {
313+ g.byBody.push(glob.substring(5));
314+ }
315+ else {
316+ g.byFile.push(new minimatch_1.Minimatch(glob, { dot }));
317+ }
318+ return g;
319+ }, grouped);
320+ }
272321// equivalent to "Array.every()" but expanded for debugging and clarity
273- function checkAll(changedFiles, globs, dot) {
274- const matchers = globs.map(g => new minimatch_1.Minimatch(g, { dot }) );
322+ function checkAll(prTitle, prBody, changedFiles, globs, dot) {
323+ const matchers = groupMatchers(globs, dot);
275324 core.debug(` checking "all" patterns`);
325+ if (!isMatchTitle(prTitle, matchers.byTitle)) {
326+ core.debug(` "all" patterns dit not match against pr title ${prTitle}`);
327+ return false;
328+ }
329+ if (!isMatchBody(prBody, matchers.byBody)) {
330+ core.debug(` "all" patterns dit not match against pr body ${prBody}`);
331+ return false;
332+ }
276333 for (const changedFile of changedFiles) {
277- if (!isMatch(changedFile, matchers)) {
334+ if (!isMatch(changedFile, matchers.byFile )) {
278335 core.debug(` "all" patterns did not match against ${changedFile}`);
279336 return false;
280337 }
281338 }
282339 core.debug(` "all" patterns matched all files`);
283340 return true;
284341}
285- function checkMatch(changedFiles, matchConfig, dot) {
342+ function checkMatch(prTitle, prBody, changedFiles, matchConfig, dot) {
286343 if (matchConfig.all !== undefined) {
287- if (!checkAll(changedFiles, matchConfig.all, dot)) {
344+ if (!checkAll(prTitle, prBody, changedFiles, matchConfig.all, dot)) {
288345 return false;
289346 }
290347 }
291348 if (matchConfig.any !== undefined) {
292- if (!checkAny(changedFiles, matchConfig.any, dot)) {
349+ if (!checkAny(prTitle, prBody, changedFiles, matchConfig.any, dot)) {
293350 return false;
294351 }
295352 }
0 commit comments