Skip to content
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

SALTO-7399: advanced fields references #7209

Merged
merged 7 commits into from
Mar 2, 2025

Conversation

IdoZakk
Copy link
Contributor

@IdoZakk IdoZakk commented Feb 5, 2025

Added support for advanced fields reference

Required some refactoring, made that in a different commit.
I also fixed a problem (missing functionality) in ScriptRunner where there were no missing references
(also a small bug in the E2E)
Noise reduction (also for scriptRunner)


Release Notes:
Jira Adapter:

  • Added support to references in advanced fields in automations
  • Added support for missing references in ScriptRunner scripts

User Notifications:
Jira Adapter:

  • customfields IDs in advacedFields (in automation type) will become references.
  • ScriptRunner scripts that uses missing custom fields will be replaced with missing references

@IdoZakk IdoZakk force-pushed the 7399advancedFields branch 2 times, most recently from 35ba037 to 76b7fe0 Compare February 5, 2025 14:20
@coveralls
Copy link

coveralls commented Feb 5, 2025

Coverage Status

coverage: 94.293% (-0.01%) from 94.303%
when pulling 78722bc on IdoZakk:7399advancedFields
into 031e7e8 on salto-io:main.

@IdoZakk IdoZakk force-pushed the 7399advancedFields branch 3 times, most recently from 44a622f to 4eb7e8d Compare February 6, 2025 10:22
@IdoZakk IdoZakk marked this pull request as draft February 23, 2025 13:16
@IdoZakk IdoZakk marked this pull request as ready for review February 26, 2025 11:32
Copy link
Contributor

@shayc331 shayc331 left a comment

Choose a reason for hiding this comment

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

looking good! had some comments


const CUSTOM_FIELD_PATTERN = /(customfield_\d+)/

const referenceCustomFields = (
text: string,
fieldInstancesById: Map<string, InstanceElement>,
enableMissingReferences: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO it is worth using named parameters

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For three distinct types I tend to keep as parameters, but will do

import { InstanceElement, Value } from '@salto-io/adapter-api'
import { AutomationInstance, isAutomationInstance } from './smart_values/smart_value_reference_filter'

const FIELDS_TO_WALK_ON = (): string[] => ['trigger', 'components']
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO it should be a constant and not a function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is something I learned from Seggev, they use it in Netsuite.
As a constant array can be changed (it is not really a constant) when creating a constant array if you use a function the original array cannot be changed

Copy link
Contributor

Choose a reason for hiding this comment

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

nice!


/**
* Convert field values into references, based on predefined rules.
*/

const noReferencesTypes = [PROJECT_COMPONENT_TYPE, FIELD_CONFIGURATION_TYPE_NAME]
const NO_REFERENCES_TYPES = (): string[] => [PROJECT_COMPONENT_TYPE, FIELD_CONFIGURATION_TYPE_NAME]
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need it as a function?
I agree that it should be a constant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as I answered in the previous comment

const instances = elements.filter(isInstanceElement)
const fieldInstances = instances.filter(instance => instance.elemID.typeName === FIELD_TYPE_NAME)
const fieldInstancesById = new Map(
fieldInstances.map(instance => [instance.value.id, instance] as [string, InstanceElement]),
Copy link
Contributor

Choose a reason for hiding this comment

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

we can filter by _.isString(instance.value.id) to make sure it is legit
and why not use Record as we usually do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was already a map, did not want to refactor (I had a long debate once with Alon about Record vs Map...)

`Failed to clean older e2e changes: ${allRemovalErrors.map(e => safeJsonStringify(e)).join(', ')}`,
)
}
const allRemovalErrors = await deployChanges([allOssCreatedElements], () => true) // do not fail on errors
Copy link
Contributor

Choose a reason for hiding this comment

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

can you explain this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a part of the E2E where we clean old instances that were not deleted due to aborted E2E. We had problems with DC so we omitted it, but there is no reason as we do not fail the E2E if this stage fails

@@ -67,6 +66,9 @@ const excludedTypes = [
const nullProgressReporter: ProgressReporter = {
reportProgress: () => {},
}

const deleteElementsAtTheEnd = true // use for debugging
Copy link
Contributor

Choose a reason for hiding this comment

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

is it a leftover?
I dont understand its purpose because it is always truth

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I changed the comment to make it clearer

@IdoZakk IdoZakk requested a review from shayc331 February 27, 2025 12:19
Copy link
Contributor

@shayc331 shayc331 left a comment

Choose a reason for hiding this comment

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

💯
much nicer without the promise.all
had some nits inside

const fieldInstances = instances.filter(instance => instance.elemID.typeName === FIELD_TYPE_NAME)
const fieldInstancesById = new Map(
fieldInstances.map(instance => [instance.value.id, instance] as [string, InstanceElement]),
fieldInstances
.filter(instance => typeof instance.value.id === 'string')
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:
I guess you prefer is that way, but IMO _.isString is cleaner

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tend to go with a natural solution over a package one

@@ -42,7 +43,7 @@ const addWalkOnReferences = (elements: Element[], config: JiraConfig): void => {
const filter: FilterCreator = ({ config }) => ({
name: 'fieldReferencesFilter',
onFetch: async elements => {
addWalkOnReferences(elements, config)
addWalkOnReferences(elements.filter(isInstanceElement), config)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:
you can save the instances in a variable before, because you filter by isInstanceElement again in line 53

@IdoZakk IdoZakk enabled auto-merge (squash) February 27, 2025 20:36
@IdoZakk IdoZakk disabled auto-merge February 27, 2025 20:40
@IdoZakk IdoZakk merged commit f0d3b05 into salto-io:main Mar 2, 2025
55 checks passed
@IdoZakk IdoZakk deleted the 7399advancedFields branch March 2, 2025 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants