From 7186ce468df74a7ef21b202287a4fed6a2c1e9f2 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Fri, 9 Aug 2024 11:12:01 -0700 Subject: [PATCH] Move label automation back to includeModifiedFiles now it support glob (#4048) Policy bot just added this functionality which allows to use glob pattern https://github.com/GitOps-microsoft/GitOps.PullRequestIssueManagement/pull/255 EDIT: seems like this needs to be deployed, will try again in a little bit --- .github/policies/prs.triage.generated.yml | 110 +++++++++++------- eng/common/scripts/labels/automation.ts | 26 ++--- eng/common/scripts/labels/policy.ts | 4 +- eng/common/scripts/utils/find-area-changed.ts | 2 +- 4 files changed, 84 insertions(+), 58 deletions(-) diff --git a/.github/policies/prs.triage.generated.yml b/.github/policies/prs.triage.generated.yml index e4276229dc..e577f394d2 100644 --- a/.github/policies/prs.triage.generated.yml +++ b/.github/policies/prs.triage.generated.yml @@ -11,122 +11,148 @@ configuration: - payloadType: Pull_Request then: - if: - - filesMatchPattern: - pattern: packages/compiler/.* + - includesModifiedFiles: + files: + - packages/compiler/**/* then: - addLabel: label: compiler:core - if: - - filesMatchPattern: - pattern: packages/typespec-vscode/.* + - includesModifiedFiles: + files: [] then: - addLabel: - label: ide + label: compiler:emitter-framework - if: - - filesMatchPattern: - pattern: packages/typespec-vs/.* + - includesModifiedFiles: + files: + - packages/typespec-vscode/**/* + - packages/typespec-vs/**/* then: - addLabel: label: ide - if: - - filesMatchPattern: - pattern: packages/http/.* + - includesModifiedFiles: + files: + - packages/http/**/* then: - addLabel: label: lib:http - if: - - filesMatchPattern: - pattern: packages/openapi/.* + - includesModifiedFiles: + files: + - packages/openapi/**/* then: - addLabel: label: lib:openapi - if: - - filesMatchPattern: - pattern: packages/rest/.* + - includesModifiedFiles: + files: + - packages/rest/**/* then: - addLabel: label: lib:rest - if: - - filesMatchPattern: - pattern: packages/versioning/.* + - includesModifiedFiles: + files: + - packages/versioning/**/* then: - addLabel: label: lib:versioning - if: - - filesMatchPattern: - pattern: blog/.* + - includesModifiedFiles: + files: + - blog/**/* then: - addLabel: label: meta:blog - if: - - filesMatchPattern: - pattern: website/.* + - includesModifiedFiles: + files: + - website/**/* then: - addLabel: label: meta:website - if: - - filesMatchPattern: - pattern: packages/tspd/.* + - includesModifiedFiles: + files: + - packages/tspd/**/* then: - addLabel: label: tspd - if: - - filesMatchPattern: - pattern: packages/http-client-csharp/.* + - includesModifiedFiles: + files: + - packages/http-client-csharp/**/* then: - addLabel: label: emitter:client:csharp - if: - - filesMatchPattern: - pattern: packages/http-client-java/.* + - includesModifiedFiles: + files: + - packages/http-client-java/**/* then: - addLabel: label: emitter:client:java - if: - - filesMatchPattern: - pattern: packages/json-schema/.* + - includesModifiedFiles: + files: + - packages/json-schema/**/* then: - addLabel: label: emitter:json-schema - if: - - filesMatchPattern: - pattern: packages/protobuf/.* + - includesModifiedFiles: + files: + - packages/protobuf/**/* then: - addLabel: label: emitter:protobuf - if: - - filesMatchPattern: - pattern: packages/openapi3/.* + - includesModifiedFiles: + files: + - packages/openapi3/**/* then: - addLabel: label: emitter:openapi3 - if: - - filesMatchPattern: - pattern: packages/openapi3/src/cli/actions/convert/.* + - includesModifiedFiles: + files: + - packages/openapi3/src/cli/actions/convert/**/* then: - addLabel: label: openapi3:converter - if: - - filesMatchPattern: - pattern: eng/.* + - includesModifiedFiles: + files: [] then: - addLabel: - label: eng + label: emitter:service:csharp + - if: + - includesModifiedFiles: + files: [] + then: + - addLabel: + label: emitter:service:js - if: - - filesMatchPattern: - pattern: .github/.* + - includesModifiedFiles: + files: + - eng/**/* + - .github/**/* then: - addLabel: label: eng - if: - - filesMatchPattern: - pattern: packages/playground/.* + - includesModifiedFiles: + files: + - packages/playground/**/* then: - addLabel: label: ui:playground - if: - - filesMatchPattern: - pattern: packages/html-program-viewer/.* + - includesModifiedFiles: + files: + - packages/html-program-viewer/**/* then: - addLabel: label: ui:type-graph-viewer diff --git a/eng/common/scripts/labels/automation.ts b/eng/common/scripts/labels/automation.ts index c843ef45ed..f3b110cc2e 100644 --- a/eng/common/scripts/labels/automation.ts +++ b/eng/common/scripts/labels/automation.ts @@ -1,12 +1,13 @@ import { resolve } from "path"; import { stringify } from "yaml"; import { CheckOptions, syncFile } from "../utils/common.js"; +import { expandFolder } from "../utils/find-area-changed.js"; import { PolicyServiceConfig, and, eventResponderTask, - filesMatchPattern, hasLabel, + includesModifiedFiles, isAction, labelAdded, labelRemoved, @@ -109,19 +110,18 @@ function createPrTriageConfig(config: RepoConfig): PolicyServiceConfig { eventResponderTasks: [ eventResponderTask({ if: [payloadType("Pull_Request")], - then: Object.entries(config.areaPaths).flatMap(([label, files]) => { - return files.map((file) => { - return { - if: [filesMatchPattern(`${file}.*`)], - then: [ - { - addLabel: { - label, - }, + then: Object.entries(config.areaPaths).map(([label, files]) => { + const globs = files.map(expandFolder); + return { + if: [includesModifiedFiles(globs)], + then: [ + { + addLabel: { + label, }, - ], - }; - }); + }, + ], + }; }), }), ], diff --git a/eng/common/scripts/labels/policy.ts b/eng/common/scripts/labels/policy.ts index 68c3db6eb7..b41593569b 100644 --- a/eng/common/scripts/labels/policy.ts +++ b/eng/common/scripts/labels/policy.ts @@ -67,7 +67,7 @@ export type IncludesModifiedFiles = { includesModifiedFiles: { files: string[] }; }; export type FilesMatchPattern = { - filesMatchPattern: { pattern: string }; + filesMatchPattern: { pattern: string; matchAny: boolean }; }; export type Condition = @@ -124,7 +124,7 @@ export function includesModifiedFiles(files: string[]): IncludesModifiedFiles { */ export function filesMatchPattern(pattern: string): FilesMatchPattern { return { - filesMatchPattern: { pattern }, + filesMatchPattern: { pattern, matchAny: true }, }; } diff --git a/eng/common/scripts/utils/find-area-changed.ts b/eng/common/scripts/utils/find-area-changed.ts index e56fa4479b..ad950f4f29 100644 --- a/eng/common/scripts/utils/find-area-changed.ts +++ b/eng/common/scripts/utils/find-area-changed.ts @@ -20,7 +20,7 @@ export function findAreasChanged(files: string[]): (keyof typeof CIRules)[] { return result; } -function expandFolder(maybeFolder: string) { +export function expandFolder(maybeFolder: string) { if (maybeFolder.endsWith("/")) { return `${maybeFolder}**/*`; }