Skip to content

Move common code + class definition updates #36120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"name": "@azure-tools/specs-shared",
"private": "true",
Expand All @@ -20,7 +20,8 @@
"./swagger": "./src/swagger.js",
"./tag": "./src/tag.js",
"./simple-git": "./src/simple-git.js",
"./test/examples": "./test/examples.js"
"./test/examples": "./test/examples.js",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did notice this looks odd. Was this intentional? If so I'll continue leaving this alone.

"./branch": "./src/branch.js"
},
"bin": {
"spec-model": "./cmd/spec-model.js"
Expand Down
9 changes: 9 additions & 0 deletions .github/shared/src/branch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't really see a good place to put something branch related like this. I DID consider sdk-types.js, but that seemed like it was type related specifically so I didn't put it there.

* Checks an input branch name and determines if it should be considered a release branch.
* @param {string} branchName
* @returns {boolean}
*/
export function isReleaseBranch(branchName) {
const branchRegex = [/main/, /RPSaaSMaster/, /release*/, /ARMCoreRPDev/];
return branchRegex.some((b) => b.test(branchName));
}
36 changes: 36 additions & 0 deletions .github/shared/test/branch.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { describe, test, expect } from "vitest";
import { isReleaseBranch } from "../src/branch.js";

describe("isReleaseBranch", () => {
test("returns true for main branch", () => {
expect(isReleaseBranch("main")).toBe(true);
});

test("returns true for RPSaaSMaster branch", () => {
expect(isReleaseBranch("RPSaaSMaster")).toBe(true);
});

test("returns true for release branches", () => {
expect(isReleaseBranch("release")).toBe(true);
expect(isReleaseBranch("release-v1.0")).toBe(true);
expect(isReleaseBranch("release/feature")).toBe(true);
expect(isReleaseBranch("releasebranch")).toBe(true);
});

test("returns true for ARMCoreRPDev branch", () => {
expect(isReleaseBranch("ARMCoreRPDev")).toBe(true);
});

test("returns false for feature branches", () => {
expect(isReleaseBranch("feature/new-feature")).toBe(false);
expect(isReleaseBranch("bugfix/fix-issue")).toBe(false);
expect(isReleaseBranch("develop")).toBe(false);
expect(isReleaseBranch("code-cleanup-classes")).toBe(false);
});

test("returns false for empty or invalid branch names", () => {
expect(isReleaseBranch("")).toBe(false);
expect(isReleaseBranch(" ")).toBe(false);
expect(isReleaseBranch("test-branch")).toBe(false);
});
});
71 changes: 25 additions & 46 deletions .github/workflows/src/summarize-checks/labelling.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
This file covers two areas of enforcement:
1. It calculates what set of label rules has been violated by the current PR, for the purposes of updating next steps to merge.
Expand All @@ -12,6 +12,8 @@
wrapInArmReviewMessage,
} from "./tsgs.js";

import { isReleaseBranch } from "../../../shared/src/branch.js";

// #region typedefs
/**
* The LabelContext is used by the updateLabels() to determine which labels to add or remove to the PR.
Expand Down Expand Up @@ -190,31 +192,36 @@
*
* See also: https://aka.ms/SpecPRReviewARMInvariants
*/
// todo: inject `core` for access to logging
export class Label {
/**
* The name of the label.
* @type {string}
*/
name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name;
#name;


/**
* Is the label currently present on the pull request?
* @type {boolean}
*/
present;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
present;
#present;


/**
* Should this label be present on the pull request?
* Must be defined before applyStateChange is called.
* Not set at the construction time to facilitate determining desired presence
* of multiple labels in single code block, without intermixing it with
* label construction logic.
* @type {boolean | undefined}
*/
shouldBePresent;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
shouldBePresent;
#shouldBePresent;


/**
* @param {string} name
* @param {Set<string>} [presentLabels]
*/
constructor(name, presentLabels) {
/** @type {string} */
this.name = name;

/**
* Is the label currently present on the pull request?
* This is determined at the time of construction of this object.
* @type {boolean | undefined}
*/
this.present = presentLabels?.has(this.name) ?? undefined;

/**
* Should this label be present on the pull request?
* Must be defined before applyStateChange is called.
* Not set at the construction time to facilitate determining desired presence
* of multiple labels in single code block, without intermixing it with
* label construction logic.
* @type {boolean | undefined}
*/
this.present = presentLabels?.has(this.name) ?? false;
this.shouldBePresent = undefined;
}

Expand Down Expand Up @@ -273,25 +280,6 @@
);
}
}

/**
* @param {string} label
* @returns {boolean}
*/
isEqualToOrPrefixOf(label) {
return this.name.endsWith("*") ? label.startsWith(this.name.slice(0, -1)) : this.name === label;
}

/**
* @returns {string}
*/
logString() {
return (
`Label: name: ${this.name}, ` +
`present: ${this.present}, ` +
`shouldBePresent: ${this.shouldBePresent}. `
);
}
}

// #endregion typedefs
Expand Down Expand Up @@ -567,15 +555,6 @@
return { armReviewLabelShouldBePresent: armReviewLabel.shouldBePresent };
}

/**
* @param {string} branchName
* @returns {boolean}
*/
function isReleaseBranch(branchName) {
const branchRegex = [/main/, /RPSaaSMaster/, /release*/, /ARMCoreRPDev/];
return branchRegex.some((b) => b.test(branchName));
}

/**
CODESYNC:
- requiredLabelsRules.ts / requiredLabelsRules
Expand Down
66 changes: 56 additions & 10 deletions eng/tools/summarize-impact/src/PRContext.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { join, dirname } from "path";
import * as fs from "fs";

Expand Down Expand Up @@ -36,22 +36,75 @@
isDraft: boolean;
};

/**
* Represents the context of a Pull Request (PR) in a repository.
* It contains information about the source and target directories, branches, SHA, and other relevant details while
* providing methods to abstract the differences between the source and target states.
*/
export class PRContext {
// we are starting with checking out before and after to different directories
// sourceDirectory corresponds to "after". EG the PR context is the "after" state of the PR.
// The "before" state is the git root directory without the changes aka targetDirectory
/**
* Path to the source directory representing the code actually being changed.
*
* This directory contains all the files as they exist on the PR branch and is
* compared against `targetDirectory` to compute additions, deletions, and modifications.
*/
sourceDirectory: string;
/**
* Path to the source directory representing the code before the changes in the PR.
*
* This directory contains all the files as they exist on the target branch and is
* compared against `sourceDirectory` to compute additions, deletions, and modifications.
*/
targetDirectory: string;
/**
* The spec model for the source directory.
*
* This is used to analyze the TypeSpec files in the source directory.
*/
sourceSpecModel?: SpecModel;
/**
* The spec model for the target directory.
*
* This is used to analyze the TypeSpec files in the target directory.
*/
targetSpecModel?: SpecModel;
/**
* The information generated about the PR from getChangedFileStatuses() call.
*/
fileList?: FileListInfo;
/**
* The branch from which the PR is created.
*/
sourceBranch: string;
/**
* The branch into which the PR is merged.
*/
targetBranch: string;
/**
* The SHA of the commit that is being merged in the PR. Originates from sourceBranch.
*/
sha: string;
/**
* The repository where the PR is created.
*/
repo: string;
/**
* The owner of the repository where the PR is created.
*/
owner: string;
/**
* The pull request number.
*/
prNumber: string;
/**
* Is the PR a draft PR?
*/
isDraft: boolean;

/**
* The context for labels applied to the PR. This context is passed throughout the labeling actions, and
* is used to determine which labels should be added or removed at the end of the labeling process.
*/
labelContext: LabelContext;

constructor(
Expand Down Expand Up @@ -87,7 +140,6 @@
return changedFiles;
}

// todo get rid of async here not necessary
// todo store the results
getTypeSpecDiffs(): DiffResult<string> {
if (!this.fileList) {
Expand Down Expand Up @@ -272,12 +324,6 @@
// this function is based upon LocalDirContext.getReadmeDiffs() and CommonPRContext.getReadmeDiffs() which are
// very different from each other (because why not). This implementation is based MOSTLY on CommonPRContext
async getReadmeDiffs(): Promise<DiffResult<ReadmeTag>> {
// this gets all of the readme diffs
// const readmeAdditions = this.fileList?.additions.filter(file => readme(file)) || [];
// const readmeChanges = this.fileList?.modifications.filter(file => readme(file))
// const readmeDeletions = this.fileList?.deletions.filter(file => readme(file));
//const changedFiles: DiffFileResult | undefined = await this.localPRContext?.getChangingFiles();

const changedFiles = await this.fileList;
const tagDiffs = (await this.getChangingTags()) || [];

Expand Down
6 changes: 4 additions & 2 deletions eng/tools/summarize-impact/src/impact.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env node

import * as fs from "fs";
Expand All @@ -10,6 +10,8 @@

import { breakingChangesCheckType } from "@azure-tools/specs-shared/breaking-change";

import { dataPlane, resourceManager } from "@azure-tools/specs-shared/changed-files";

import {
DiffResult,
ReadmeTag,
Expand Down Expand Up @@ -169,11 +171,11 @@
}

export function isManagementPR(filePaths: string[]): boolean {
return filePaths.some((it) => it.includes("resource-manager"));
return filePaths.some((it) => resourceManager(it));
}

export function isDataPlanePR(filePaths: string[]): boolean {
return filePaths.some((it) => it.includes("data-plane"));
return filePaths.some((it) => dataPlane(it));
}

export function getAllApiVersionFromRPFolder(rpFolder: string): string[] {
Expand Down
Loading