Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeguerin committed May 22, 2024
1 parent 9dbfaca commit bc49070
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 38 deletions.
61 changes: 30 additions & 31 deletions eng/common/scripts/labels/automation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve } from "path";
import { stringify } from "yaml";
import { CheckOptions, repoRoot, syncFile } from "../common.js";
import { CheckOptions, syncFile } from "../common.js";
import {
PolicyServiceConfig,
and,
Expand Down Expand Up @@ -95,37 +95,36 @@ function createIssueTriageConfig(config: RepoConfig): PolicyServiceConfig {
},
},
};
};
}
function createPrTriageConfig(config: RepoConfig): PolicyServiceConfig {

return {
id: "prs.triage",
name: "Assign area labels to PRs",
description: "Assign area labels to PR depending on path modified.",
resource: "repository",
disabled: false,
configuration: {
resourceManagementConfiguration: {
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,
return {
id: "prs.triage",
name: "Assign area labels to PRs",
description: "Assign area labels to PR depending on path modified.",
resource: "repository",
disabled: false,
configuration: {
resourceManagementConfiguration: {
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,
},
},
},
],
};
});
],
};
});
}),
}),
}),
],
],
},
},
},
};
};
};
}
9 changes: 4 additions & 5 deletions eng/common/scripts/labels/sync-labels.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { resolve } from "path";
import { parseArgs } from "util";
import { syncLabelAutomation } from "./automation.js";
import { syncLabelsDefinitions } from "./definitions.js";
import { resolve } from "path";
import { RepoConfig } from "./types.js";

const options = parseArgs({
args: process.argv.slice(2),
options: {
"config": {
config: {
type: "string",
description: "The directory where the labels configuration is stored.",
},
Expand All @@ -23,7 +23,7 @@ const options = parseArgs({
},
});

if(!options.values["config"]) {
if (!options.values["config"]) {
throw new Error("--config is required");
}

Expand All @@ -39,8 +39,7 @@ await syncLabelAutomation(config, {
check: options.values["check"],
});


async function loadConfig(configFile: string): Promise<RepoConfig> {
const module = await import(resolve(process.cwd(), configFile));
const module = await import(resolve(process.cwd(), configFile));
return module.default;
}
4 changes: 2 additions & 2 deletions eng/common/scripts/labels/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ export interface RepoConfig {
repo: {
owner: string;
repo: string;
},
};
labels: LabelsConfig;
areaPaths: Record<string, string[]>;
}

export interface LabelsConfig {
area: LabelCategory;
[key: string]: LabelCategory
[key: string]: LabelCategory;
}

export interface LabelCategory {
Expand Down

0 comments on commit bc49070

Please sign in to comment.