-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't really see a good place to put something |
||
* 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)); | ||
} |
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); | ||
}); | ||
}); |
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. | ||||||
|
@@ -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. | ||||||
|
@@ -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; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
/** | ||||||
* Is the label currently present on the pull request? | ||||||
* @type {boolean} | ||||||
*/ | ||||||
present; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
/** | ||||||
* 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; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
/** | ||||||
* @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; | ||||||
} | ||||||
|
||||||
|
@@ -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 | ||||||
|
@@ -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 | ||||||
|
There was a problem hiding this comment.
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.