-
Notifications
You must be signed in to change notification settings - Fork 4
feat: added stale comment for stale features in generate types #452
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
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "version": "5.20.2", | ||
| "version": "5.20.3", | ||
| "commands": { | ||
| "authCommand": { | ||
| "id": "authCommand", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,10 @@ import { OrganizationMember, fetchOrganizationMembers } from '../../api/members' | |
| import { upperCase } from 'lodash' | ||
| import { createHash } from 'crypto' | ||
| import path from 'path' | ||
| import { fetchAllCompletedOrArchivedFeatures } from '../../api/features' | ||
| import { | ||
| fetchAllCompletedOrArchivedFeatures, | ||
| fetchFeatures, | ||
| } from '../../api/features' | ||
| import { fetchCustomProperties } from '../../api/customProperties' | ||
|
|
||
| const reactImports = (oldRepos: boolean, strictCustomData: boolean) => { | ||
|
|
@@ -176,10 +179,23 @@ export default class GenerateTypes extends Base { | |
| ) | ||
| } | ||
|
|
||
| this.features = await fetchAllCompletedOrArchivedFeatures( | ||
| this.authToken, | ||
| this.projectKey, | ||
| ) | ||
| if (this.project.settings?.staleness?.enabled) { | ||
| const [completedFeatures, staleFeatures] = await Promise.all([ | ||
| fetchAllCompletedOrArchivedFeatures( | ||
| this.authToken, | ||
| this.projectKey, | ||
| ), | ||
| fetchFeatures(this.authToken, this.projectKey, { | ||
| staleness: 'all', | ||
| }), | ||
| ]) | ||
| this.features = [...completedFeatures, ...staleFeatures] | ||
| } else { | ||
| this.features = await fetchAllCompletedOrArchivedFeatures( | ||
| this.authToken, | ||
| this.projectKey, | ||
| ) | ||
| } | ||
|
|
||
| const variables = await fetchAllVariables( | ||
| this.authToken, | ||
|
|
@@ -294,19 +310,33 @@ export default class GenerateTypes extends Base { | |
| const createdDate = variable.createdAt.split('T')[0] | ||
|
|
||
| const deprecationInfo = isVariableDeprecated(variable, this.features) | ||
|
|
||
| const isDeprecated = | ||
| this.includeDeprecationWarnings && deprecationInfo.deprecated | ||
| const deprecationWarning = isDeprecated | ||
| ? `@deprecated This variable is part of ${deprecationInfo.feature?.status} feature "${deprecationInfo.feature?.name}" and should be cleaned up.\n` | ||
| : '' | ||
|
|
||
| let staleWarning = '' | ||
| if (this.project.settings?.staleness?.enabled) { | ||
| const staleInfo = isVariableStale(variable, this.features) | ||
| const recommendedValue = getRecommendedValueForStale( | ||
| variable, | ||
| staleInfo.feature as Feature, | ||
| ) | ||
| staleWarning = staleInfo.stale | ||
| ? `@stale This variable is part of "${staleInfo.feature?.name}" feature with stale reason: ${staleInfo.feature?.staleness?.reason}. ${recommendedValue ? `Recommended value to set it to: ${recommendedValue}` : ''}\n` | ||
| : '' | ||
| } | ||
|
|
||
| return blockComment( | ||
| descriptionText, | ||
| creator, | ||
| createdDate, | ||
| indent, | ||
| !this.obfuscate ? variable.key : undefined, | ||
| deprecationWarning, | ||
| staleWarning, | ||
| ) | ||
| } | ||
|
|
||
|
|
@@ -385,6 +415,7 @@ export const blockComment = ( | |
| indent: boolean, | ||
| key?: string, | ||
| deprecationWarning?: string, | ||
| staleWarning?: string, | ||
| ) => { | ||
| const indentString = indent ? ' ' : '' | ||
| return ( | ||
|
|
@@ -399,6 +430,7 @@ export const blockComment = ( | |
| (deprecationWarning | ||
| ? `${indentString} * ${deprecationWarning}\n` | ||
| : '') + | ||
| (staleWarning ? `${indentString} * ${staleWarning}\n` : '') + | ||
| indentString + | ||
| '*/' | ||
| ) | ||
|
|
@@ -430,6 +462,39 @@ function isVariableDeprecated(variable: Variable, features: Feature[]) { | |
| return { deprecated: feature && feature.status !== 'active', feature } | ||
| } | ||
|
|
||
| function isVariableStale(variable: Variable, features: Feature[]) { | ||
| if (!variable._feature || variable.persistent) return { stale: false } | ||
| const feature = features.find((f) => f._id === variable._feature) | ||
| return { stale: feature && feature.staleness, feature } | ||
| } | ||
|
|
||
| function getRecommendedValueForStale(variable: Variable, feature: Feature) { | ||
| if (!feature) { | ||
| return variable.defaultValue | ||
| } | ||
| const reason = feature.staleness?.reason | ||
| if (reason === 'unused') { | ||
| return variable.defaultValue | ||
| } else if (reason === 'released') { | ||
| if (feature.staleness?.metaData?.releaseVariation) { | ||
|
Member
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. if there is no released variation, maybe select the one with the highest distribution % or number of evaluations if we can fetch that?
Contributor
Author
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. would maybe like to add that as metadata from the backend instead of figuring out here in the cli |
||
| const stalenessMetaData = feature.staleness?.metaData | ||
| ?.releaseVariation as { | ||
| _variation: string | ||
| variationKey: string | ||
| variationName: string | ||
| } | ||
| const releaseVariation = feature.variations?.find( | ||
| (v) => v._id === stalenessMetaData._variation, | ||
| ) | ||
| return ( | ||
| releaseVariation?.variables?.[variable.key] || | ||
| variable.defaultValue | ||
| ) | ||
| } | ||
| } | ||
| return variable.defaultValue | ||
| } | ||
|
|
||
| const generateCustomDataType = ( | ||
| customProperties: CustomProperty[], | ||
| strict: boolean, | ||
|
|
||
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.
we really shouldn't manually update this
zodClient.tsfile as it's generated fromscripts/generate-zodios-client.sh. I have a background agent working on updating that script and fixing all the new type errors, but it will be a larger PR.