-
Notifications
You must be signed in to change notification settings - Fork 2
Add check for proper feature flag task comment for all PR's #21
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
Merged
+377
−0
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8a7154c
Add check for proper feature flag task comment for all PR's
dus7 5053ec7
Do not count braces in removed lines
dus7 bcbf58a
Test dummy
dus7 e8a9af9
Fix diff parsing
dus7 bed32f2
Allow parameters in asana links
dus7 96bc9b1
Collect all invalid entries in summary
dus7 8ce1323
Improve instructions
dus7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,254 @@ | ||
| jest.mock("danger", () => jest.fn()) | ||
| import danger from 'danger' | ||
| const dm = danger as any; | ||
|
|
||
| import { featureFlagAsanaLink } from '../org/allPRs' | ||
|
|
||
| beforeEach(() => { | ||
| dm.diffContent = "" | ||
| dm.warn = jest.fn().mockReturnValue(true); | ||
|
|
||
| dm.danger = { | ||
| git: { | ||
| diffForFile: async (_filename) => { | ||
| return { added: dm.diffContent, diff: dm.diffContent } | ||
| }, | ||
| modified_files: [ | ||
| "iOS/Core/FeatureFlag.swift" | ||
| ], | ||
| created_files: [] | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| describe("Feature flag Asana link checks", () => { | ||
| it("does not fail when no feature flag files are changed", async () => { | ||
| dm.danger.git.modified_files = ["SomeOtherFile.swift"] | ||
|
|
||
| await featureFlagAsanaLink() | ||
| expect(dm.warn).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("does not fail when diff has no added case lines", async () => { | ||
| dm.diffContent = `@@ -10,6 +10,8 @@ enum FeatureFlag { | ||
| + var rawValue: String | ||
| + var source: FeatureFlagSource | ||
| ` | ||
|
|
||
| await featureFlagAsanaLink() | ||
| expect(dm.warn).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("does not fail when added case has valid Asana link above it", async () => { | ||
| dm.diffContent = `@@ -10,6 +10,8 @@ enum FeatureFlag { | ||
| + /// https://app.asana.com/1/137249556945/project/1211834678943996/task/123456789 | ||
| + case myNewFeature | ||
| ` | ||
|
|
||
| await featureFlagAsanaLink() | ||
| expect(dm.warn).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("does not fail when added case with assignment has valid Asana link above it", async () => { | ||
| dm.diffContent = `@@ -10,6 +10,8 @@ enum FeatureFlag { | ||
| + /// https://app.asana.com/1/137249556945/project/1211834678943996/task/999888777 | ||
| + case anotherFeature = "anotherFeature" | ||
| ` | ||
|
|
||
| await featureFlagAsanaLink() | ||
| expect(dm.warn).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("fails when added case has no comment above it", async () => { | ||
| dm.diffContent = `@@ -10,6 +10,7 @@ enum FeatureFlag { | ||
| + case myNewFeature | ||
| ` | ||
|
|
||
| await featureFlagAsanaLink() | ||
| expect(dm.warn).toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("fails when added case has a non-Asana comment above it", async () => { | ||
| dm.diffContent = `@@ -10,6 +10,8 @@ enum FeatureFlag { | ||
| + /// Some description of the feature | ||
| + case myNewFeature | ||
| ` | ||
|
|
||
| await featureFlagAsanaLink() | ||
| expect(dm.warn).toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("fails when added case has an Asana link with wrong project ID", async () => { | ||
| dm.diffContent = `@@ -10,6 +10,8 @@ enum FeatureFlag { | ||
| + /// https://app.asana.com/1/137249556945/project/9999999999999999/task/123456789 | ||
| + case myNewFeature | ||
| ` | ||
|
|
||
| await featureFlagAsanaLink() | ||
| expect(dm.warn).toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("fails when comment above is a context line (not added)", async () => { | ||
| dm.diffContent = `@@ -10,6 +10,7 @@ enum FeatureFlag { | ||
| /// https://app.asana.com/1/137249556945/project/1211834678943996/task/123456789 | ||
| + case myNewFeature | ||
| ` | ||
|
|
||
| await featureFlagAsanaLink() | ||
| expect(dm.warn).toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("works with macOS feature flag file", async () => { | ||
| dm.danger.git.modified_files = [ | ||
| "macOS/LocalPackages/FeatureFlags/Sources/FeatureFlags/FeatureFlag.swift" | ||
| ] | ||
| dm.diffContent = `@@ -10,6 +10,8 @@ enum FeatureFlag { | ||
| + /// https://app.asana.com/1/137249556945/project/1211834678943996/task/123456789 | ||
| + case macOSFeature | ||
| ` | ||
|
|
||
| await featureFlagAsanaLink() | ||
| expect(dm.warn).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("fails for macOS feature flag file with missing link", async () => { | ||
| dm.danger.git.modified_files = [ | ||
| "macOS/LocalPackages/FeatureFlags/Sources/FeatureFlags/FeatureFlag.swift" | ||
| ] | ||
| dm.diffContent = `@@ -10,6 +10,7 @@ enum FeatureFlag { | ||
| + case macOSFeature | ||
| ` | ||
|
|
||
| await featureFlagAsanaLink() | ||
| expect(dm.warn).toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("does not fail when diff is empty", async () => { | ||
| dm.danger.git.diffForFile = async (_filename) => { return null } | ||
|
|
||
| await featureFlagAsanaLink() | ||
| expect(dm.warn).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("does not fail for removed case lines", async () => { | ||
| dm.diffContent = `@@ -10,6 +10,5 @@ enum FeatureFlag { | ||
| - case removedFeature | ||
| ` | ||
|
|
||
| await featureFlagAsanaLink() | ||
| expect(dm.warn).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("does not fail for case added in a different enum", async () => { | ||
| dm.diffContent = `@@ -50,6 +50,7 @@ enum SomeOtherEnum { | ||
| + case otherEnumCase | ||
| ` | ||
|
|
||
| await featureFlagAsanaLink() | ||
| expect(dm.warn).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("fails for case in FeatureFlag enum but not in other enum in same diff", async () => { | ||
| dm.diffContent = `@@ -10,6 +10,7 @@ enum SomeOtherEnum { | ||
| + case otherEnumCase | ||
| @@ -50,6 +50,7 @@ enum FeatureFlag { | ||
| + case featureFlagCase | ||
| ` | ||
|
|
||
| await featureFlagAsanaLink() | ||
| expect(dm.warn).toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("does not fail for case in other enum when FeatureFlag cases are valid", async () => { | ||
| dm.diffContent = `@@ -10,6 +10,7 @@ enum SomeOtherEnum { | ||
| + case otherEnumCase | ||
| @@ -50,6 +50,8 @@ enum FeatureFlag { | ||
| + /// https://app.asana.com/1/137249556945/project/1211834678943996/task/123456789 | ||
| + case featureFlagCase | ||
| ` | ||
|
|
||
| await featureFlagAsanaLink() | ||
| expect(dm.warn).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("tracks FeatureFlag enum declared in the diff itself", async () => { | ||
| dm.diffContent = `@@ -10,6 +10,10 @@ | ||
| +enum FeatureFlag: String { | ||
| + case myNewFeature | ||
| +} | ||
| ` | ||
|
|
||
| await featureFlagAsanaLink() | ||
| expect(dm.warn).toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("does not fail when Asana link is above other comment lines", async () => { | ||
| dm.diffContent = `@@ -10,6 +10,10 @@ enum FeatureFlag { | ||
| + /// https://app.asana.com/1/137249556945/project/1211834678943996/task/123456789 | ||
| + /// Some description of the feature | ||
| + case myNewFeature | ||
| ` | ||
|
|
||
| await featureFlagAsanaLink() | ||
| expect(dm.warn).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("does not fail when Asana link is several comment lines above case", async () => { | ||
| dm.diffContent = `@@ -10,6 +10,11 @@ enum FeatureFlag { | ||
| + /// https://app.asana.com/1/137249556945/project/1211834678943996/task/123456789 | ||
| + /// First line of description | ||
| + /// Second line of description | ||
| + case myNewFeature | ||
| ` | ||
|
|
||
| await featureFlagAsanaLink() | ||
| expect(dm.warn).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("fails when comment block has no Asana link at all", async () => { | ||
| dm.diffContent = `@@ -10,6 +10,10 @@ enum FeatureFlag { | ||
| + /// First line of description | ||
| + /// Second line of description | ||
| + case myNewFeature | ||
| ` | ||
|
|
||
| await featureFlagAsanaLink() | ||
| expect(dm.warn).toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("does not check cases after FeatureFlag enum closing brace", async () => { | ||
| dm.diffContent = `@@ -10,6 +10,12 @@ | ||
| +enum FeatureFlag: String { | ||
| + /// https://app.asana.com/1/137249556945/project/1211834678943996/task/123456789 | ||
| + case validFeature | ||
| +} | ||
| +enum AnotherEnum { | ||
| + case nolinkNeeded | ||
| +} | ||
| ` | ||
|
|
||
| await featureFlagAsanaLink() | ||
| expect(dm.warn).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("ignores braces from removed lines when tracking FeatureFlag enum scope", async () => { | ||
| dm.diffContent = `@@ -10,6 +10,8 @@ enum FeatureFlag { | ||
| - } | ||
| + /// https://app.asana.com/1/137249556945/project/1211834678943996/task/123456789 | ||
| + case myNewFeature | ||
| ` | ||
|
|
||
| await featureFlagAsanaLink() | ||
| expect(dm.warn).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("warns when removed braces would have hidden a missing link", async () => { | ||
| dm.diffContent = `@@ -10,6 +10,8 @@ enum FeatureFlag { | ||
| - } | ||
| + case myNewFeature | ||
| ` | ||
|
|
||
| await featureFlagAsanaLink() | ||
| expect(dm.warn).toHaveBeenCalled() | ||
| }) | ||
| }) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.